get rid of Persona, info on how to get an account

This commit is contained in:
Filip Gralinski 2017-01-28 11:22:56 +01:00
parent 23411e5d61
commit cf5a26a201
6 changed files with 28 additions and 11 deletions

View File

@ -3,8 +3,7 @@ module Foundation where
import Database.Persist.Sql (ConnectionPool, runSqlPool) import Database.Persist.Sql (ConnectionPool, runSqlPool)
import Import.NoFoundation import Import.NoFoundation
import Text.Hamlet (hamletFile) import Text.Hamlet (hamletFile)
import Yesod.Auth.BrowserId (authBrowserId) import Yesod.Auth.HashDB (HashDBUser(..),authHashDB,authHashDBWithForm)
import Yesod.Auth.HashDB (HashDBUser(..),authHashDB)
import Yesod.Auth.Message (AuthMessage (InvalidLogin)) import Yesod.Auth.Message (AuthMessage (InvalidLogin))
import qualified Yesod.Core.Unsafe as Unsafe import qualified Yesod.Core.Unsafe as Unsafe
import Yesod.Core.Types (Logger) import Yesod.Core.Types (Logger)
@ -200,11 +199,19 @@ instance YesodAuth App where
} }
-- You can add other plugins like BrowserID, email or OAuth here -- You can add other plugins like BrowserID, email or OAuth here
authPlugins _ = [authBrowserId def, authPlugins master = [authHashDBWithForm (myLoginForm master) (Just . UniqueUser)]
authHashDB (Just . UniqueUser)]
authHttpManager = getHttpManager 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 instance YesodAuthPersist App
-- This instance is required to use forms. You can modify renderMessage to -- This instance is required to use forms. You can modify renderMessage to

View File

@ -14,6 +14,7 @@ import Handler.Shared
getHomeR :: Handler Html getHomeR :: Handler Html
getHomeR = do getHomeR = do
maybeUser <- maybeAuth maybeUser <- maybeAuth
master <- getYesod
let maybeLocalId = case maybeUser of let maybeLocalId = case maybeUser of
Just user -> userLocalId $ entityVal user Just user -> userLocalId $ entityVal user
Nothing -> Nothing Nothing -> Nothing

View File

@ -54,6 +54,8 @@ data AppSettings = AppSettings
, appAnalytics :: Maybe Text , appAnalytics :: Maybe Text
-- ^ Google Analytics code -- ^ Google Analytics code
, appVarDir :: String , appVarDir :: String
-- ^ Contact (admin) e-mail
, appContactEmail :: Maybe Text
} }
instance FromJSON AppSettings where instance FromJSON AppSettings where
@ -80,6 +82,7 @@ instance FromJSON AppSettings where
appCopyright <- o .: "copyright" appCopyright <- o .: "copyright"
appAnalytics <- o .:? "analytics" appAnalytics <- o .:? "analytics"
appVarDir <- o .: "var-dir" appVarDir <- o .: "var-dir"
appContactEmail <- o .:? "contact-email"
return AppSettings {..} return AppSettings {..}

View File

@ -7,6 +7,7 @@ port: "_env:PORT:3000"
approot: "_env:APPROOT:http://localhost:3000" approot: "_env:APPROOT:http://localhost:3000"
ip-from-header: "_env:IP_FROM_HEADER:false" ip-from-header: "_env:IP_FROM_HEADER:false"
var-dir: "_env:VAR_DIR:." var-dir: "_env:VAR_DIR:."
contact-email: "_env:CONTACT_EMAIL:filipg@amu.edu.pl"
# Optional values with the following production defaults. # Optional values with the following production defaults.
# In development, they default to the inverse. # In development, they default to the inverse.

10
templates/auth.hamlet Normal file
View File

@ -0,0 +1,10 @@
<h2>Login
<div id="login">
<form method="post" action="@{action}">
<table>
<tr><th>Username:</th><td><input id="x" name="username" autofocus="" required></td>
<tr><th>Password:</th><td><input type="password" name="password" required></td>
<tr><td>&nbsp;</td><td><input type="submit" value="Login"></td>
<p>&nbsp;
<div class="alert alert-info" role="alert">
<p>Don't have an account yet? Forgot the password? Please get in touch with the site admin#{contactEmailLabel site}.

View File

@ -14,8 +14,7 @@
$nothing $nothing
<div class="alert alert-info" role="alert"> <div class="alert alert-info" role="alert">
<p> <p>
<strong>Please set up your password at <a href="@{YourAccountR}">your account</a> so that you could log in when <a href="https://developer.mozilla.org/en-US/Persona">Persona</a> authentication system is shut down. <strong>You have an empty password</strong> (probably because you used <a href="https://developer.mozilla.org/en-US/Persona">Persona</a> authentication system before). Get in touch with the site admin to set up the password.
$maybe _ <- maybeLocalId $maybe _ <- maybeLocalId
<p>Go to the <a href="@{ListChallengesR}">challenge list</a> and choose a challenge for you! <p>Go to the <a href="@{ListChallengesR}">challenge list</a> and choose a challenge for you!
$nothing $nothing
@ -27,10 +26,6 @@
<div class="alert alert-info" role="alert"> <div class="alert alert-info" role="alert">
<p> <p>
<strong>How to log in? <strong>How to log in?</strong> If you already have an account, just click <a href="@{AuthR LoginR}">log in</a>. Otherwise, please get in touch with the site admin#{contactEmailLabel master}.
Gonito uses <a href="https://developer.mozilla.org/en-US/Persona">Persona</a> authentication system available in Mozilla Firefox. Other authentication systems are on the way, but for the time being you need to use Firefox.
<p>So, just click <a href="@{AuthR LoginR}">log in</a>, then "Sign in with Persona" button and Firefox will guide you!
<p>Unfortunately, Persona will be shut down soon :( Don't worry, just sign in with Persona and then set up a password, so that you could log in even when Persona is closed.
<p class="text-muted text-right"><sup>*</sup>Disclaimer: Gonito is neither affiliated with nor endorsed by <a href="https://www.kaggle.com">Kaggle</a>. <p class="text-muted text-right"><sup>*</sup>Disclaimer: Gonito is neither affiliated with nor endorsed by <a href="https://www.kaggle.com">Kaggle</a>.