diff --git a/Foundation.hs b/Foundation.hs index 7d9f153..752cc76 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -3,8 +3,7 @@ module Foundation where import Database.Persist.Sql (ConnectionPool, runSqlPool) import Import.NoFoundation import Text.Hamlet (hamletFile) -import Yesod.Auth.BrowserId (authBrowserId) -import Yesod.Auth.HashDB (HashDBUser(..),authHashDB) +import Yesod.Auth.HashDB (HashDBUser(..),authHashDB,authHashDBWithForm) import Yesod.Auth.Message (AuthMessage (InvalidLogin)) import qualified Yesod.Core.Unsafe as Unsafe import Yesod.Core.Types (Logger) @@ -200,11 +199,19 @@ instance YesodAuth App where } -- You can add other plugins like BrowserID, email or OAuth here - authPlugins _ = [authBrowserId def, - authHashDB (Just . UniqueUser)] + authPlugins master = [authHashDBWithForm (myLoginForm master) (Just . UniqueUser)] authHttpManager = getHttpManager +contactEmailLabel :: App -> Text +contactEmailLabel site = + case maybeContactMail of + Just contactMail -> " (" ++ contactMail ++ ")" + Nothing -> "" + where maybeContactMail = appContactEmail $ appSettings site + +myLoginForm site action = $(whamletFile "templates/auth.hamlet") + instance YesodAuthPersist App -- This instance is required to use forms. You can modify renderMessage to diff --git a/Handler/Home.hs b/Handler/Home.hs index c1ac281..9c30f42 100644 --- a/Handler/Home.hs +++ b/Handler/Home.hs @@ -14,6 +14,7 @@ import Handler.Shared getHomeR :: Handler Html getHomeR = do maybeUser <- maybeAuth + master <- getYesod let maybeLocalId = case maybeUser of Just user -> userLocalId $ entityVal user Nothing -> Nothing diff --git a/Settings.hs b/Settings.hs index 853ea14..3fd079d 100644 --- a/Settings.hs +++ b/Settings.hs @@ -54,6 +54,8 @@ data AppSettings = AppSettings , appAnalytics :: Maybe Text -- ^ Google Analytics code , appVarDir :: String + -- ^ Contact (admin) e-mail + , appContactEmail :: Maybe Text } instance FromJSON AppSettings where @@ -80,6 +82,7 @@ instance FromJSON AppSettings where appCopyright <- o .: "copyright" appAnalytics <- o .:? "analytics" appVarDir <- o .: "var-dir" + appContactEmail <- o .:? "contact-email" return AppSettings {..} diff --git a/config/settings.yml b/config/settings.yml index 9708c22..7d9f217 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -7,6 +7,7 @@ port: "_env:PORT:3000" approot: "_env:APPROOT:http://localhost:3000" ip-from-header: "_env:IP_FROM_HEADER:false" var-dir: "_env:VAR_DIR:." +contact-email: "_env:CONTACT_EMAIL:filipg@amu.edu.pl" # Optional values with the following production defaults. # In development, they default to the inverse. diff --git a/templates/auth.hamlet b/templates/auth.hamlet new file mode 100644 index 0000000..f577019 --- /dev/null +++ b/templates/auth.hamlet @@ -0,0 +1,10 @@ +