packages feed

PUH-Project 0.1.0.0 → 0.1.0.1

raw patch · 4 files changed

+21/−25 lines, 4 files

Files

Assignments.hs view
@@ -19,8 +19,7 @@ import Data.List
 import qualified Data.Text as T
 
-root = "."
-
+root = "V:/Univeras/7pusmetis/Haskell/project/PUH_project/"
 confName = "conf"
 
 -- | A user identifier (not DB id) like a username or JMBAG 
@@ -173,6 +172,8 @@ }
 
 
+main :: IO ()
+main = putStrLn "Hello Haskell"
 
 
 
Email.hs view
@@ -11,34 +11,18 @@ import qualified Network.Mail.SMTP as Mail
 import qualified Data.Text.Lazy as L
 import qualified Network.Mail.Mime as Mime
+import User
 import Data.Word
 import Network.Socket.Internal
 import Data.List
+import Role
 
 -- | An alias for the template contents 
 type Template = T.Text
 
--- | A user identifier (not DB id) like a username or JMBAG
-type UserIdentifier = String
 
-data Role = Student Integer -- Academic Year shorthand (2015 for 2015/16)
-    | TA Integer Integer -- AY shorthand range (inclusive)
-    | Professor deriving (Eq, Ord, Show)
 
--- | A user (the definition can be bigger)
-data User = User { identifier :: UserIdentifier
-    , email :: String
-    , pwdHash :: String
-    , role :: Role
-    } deriving (Eq, Show)
 
-user1 = User {identifier = "Vienas", email = "medinismolis@gmx.com", pwdHash = "sgsvht", role = Professor};
-user2 = User {identifier = "Du", email = "medinismolis@gmx.com", pwdHash = "sgsvht", role = Student {}};
-user3 = User {identifier = "Trys", email = "medinismolis@gmx.com", pwdHash = "sgsvht", role = Student {}};
-user4 = User {identifier = "Keturi", email = "medinismolis@gmx.com", pwdHash = "sgsvht", role = TA {}};
-user5 = User {identifier = "Linas", email = "medinismolis@gmx.com", pwdHash = "sgsvht", role = TA {}};
-userList = [user1, user2, user3, user4, user5]
-
 -- | Configuration object
 data Configuration = Configuration { 
     host       :: String,
@@ -81,13 +65,14 @@ -- | Sends an e-mail with given text to list of users 
 -- | using given configuration. Throws appropriate error upon failure. 
 -- | Provide subject of the email as the last argument.
-sendMail :: IO Configuration -> IO T.Text -> [User] -> String -> IO ()
-sendMail iocnfg iotxt list subj = do
+sendMail :: IO Configuration -> IO T.Text -> IO [User] -> String -> IO ()
+sendMail iocnfg iotxt usrlist subj = do
     txt <- iotxt
     cnfg <- iocnfg
+    list <- usrlist
     let mails = map (\x -> (T.pack $ email x, unwrapEither $ compileTemplate txt (createTemplateMap (ident cnfg) x), identifier x)) list
-    mapM_ (\(x,y,z) -> sendSingleMail x y z cnfg subj) mails -- sends all emails
-    --mapM_ (\(x,y,_) -> putStrLn $ (T.unpack x ++ " -> \n" ++ L.unpack y)) mails -- prints all emails
+    --mapM_ (\(x,y,z) -> sendSingleMail x y z cnfg subj) mails -- sends all emails
+    mapM_ (\(x,y,_) -> putStrLn $ (T.unpack x ++ " -> \n" ++ L.unpack y)) mails -- prints all emails
     
 -- | Prepares and sends email
 sendSingleMail :: T.Text -> L.Text -> String -> Configuration -> String -> IO ()
PUH-Project.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                PUH-Project
-version:             0.1.0.0
+version:             0.1.0.1
 synopsis:            This is a package which includes Assignments, Email, User and Reviews modules for Programming in Haskell course.
 -- description:         
 license:             BSD3
User.hs view
@@ -9,12 +9,15 @@ {-# LANGUAGE TypeFamilies               #-}
 
 module User (
+    User(User),
     createUser,
     updateUser,
     deleteUser,
     listUsers,
     listUsersInRole,
     getUser,
+    identifier,
+    email,
     isRoleInYear,
     UserIdentifier) where
 
@@ -42,6 +45,12 @@              ",email = " ++ show (userEmail u) ++
              ",role = " ++ show (userRole u) ++ "}"
              
+identifier :: User -> UserIdentifier
+identifier = userIdentifier
+
+email :: User -> String
+email = userEmail
+
 -- | Takes a user identifier, e-mail, password and role.
 -- | Performs password hashing and stores the user into the
 -- | database, returning a filled User. If creating it fails (e.g.
@@ -108,6 +117,7 @@         case maybeEntity of
             Nothing -> error "User not found"
             Just entity -> return $ entityVal entity
+
 
 -- | Checks whether the user has a role of AT LEAST X in a given academic
 -- | year.