add "your account" option

This commit is contained in:
Filip Gralinski 2015-09-30 20:15:33 +02:00
parent 3722329152
commit 652e82fa62
9 changed files with 59 additions and 0 deletions

View File

@ -40,6 +40,7 @@ import Handler.CreateChallenge
import Handler.ListChallenges
import Handler.ShowChallenge
import Handler.Shared
import Handler.YourAccount
-- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the

View File

@ -171,6 +171,7 @@ instance YesodAuth App where
insert User
{ userIdent = credsIdent creds
, userPassword = Nothing
, userName = Nothing
}
-- You can add other plugins like BrowserID, email or OAuth here

42
Handler/YourAccount.hs Normal file
View File

@ -0,0 +1,42 @@
module Handler.YourAccount where
import Import
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3,
withSmallInput)
import Handler.Shared
import Handler.Extract
getYourAccountR :: Handler Html
getYourAccountR = do
userId <- requireAuthId
user <- runDB $ get404 userId
(formWidget, formEnctype) <- generateFormPost (yourAccountForm $ userName user)
let submission = Nothing :: Maybe (Import.FileInfo, Text)
handlerName = "getYourAccountR" :: Text
defaultLayout $ do
aDomId <- newIdent
setTitle "Your account"
$(widgetFile "your-account")
postYourAccountR :: Handler Html
postYourAccountR = do
((result, formWidget), formEnctype) <- runFormPost (yourAccountForm Nothing)
let handlerName = "postYourAccountR" :: Text
accountData = case result of
FormSuccess res -> Just res
_ -> Nothing
Just (name, aboutMe) = accountData
userId <- requireAuthId
runDB $ update userId [UserName =. name]
user <- runDB $ get404 userId
defaultLayout $ do
aDomId <- newIdent
setTitle "Your account"
$(widgetFile "your-account")
yourAccountForm :: Maybe Text -> Form (Maybe Text, Maybe Text)
yourAccountForm maybeName = renderBootstrap3 BootstrapBasicForm $ (,)
<$> aopt textField (fieldSettingsLabel MsgAccountName) (Just maybeName)
<*> aopt textField (fieldSettingsLabel MsgAboutMe) Nothing

View File

@ -2,6 +2,7 @@ User
ident Text
password Text Maybe
UniqueUser ident
name Text Maybe
deriving Typeable
Email
email Text

View File

@ -16,3 +16,5 @@
/challenge-submission/#Text ChallengeSubmissionR GET POST
/challenge-my-submissions/#Text ChallengeMySubmissionsR GET
/challenge-all-submissions/#Text ChallengeAllSubmissionsR GET
/account YourAccountR GET POST

View File

@ -30,6 +30,7 @@ library
Handler.Shared
Handler.ShowChallenge
Handler.Extract
Handler.YourAccount
if flag(dev) || flag(library-only)
cpp-options: -DDEVELOPMENT

View File

@ -13,3 +13,6 @@ Submit: Submit
SubmissionUrl: Submission repo URL
SubmissionBranch: Submission repo branch
SubmissionDescription: Submission description
YourAccount: your account
AboutMe: about me
AccountName: name

View File

@ -3,6 +3,7 @@
_{MsgLoggedAs} #{userIdent $ entityVal user}
\ | <a href="@{CreateChallengeR}">_{MsgCreateChallenge}</a>
\ | <a href="@{ListChallengesR}">_{MsgListChallenges}</a>
\ | <a href="@{YourAccountR}">_{MsgYourAccount}</a>
\ | <a href="@{AuthR LogoutR}">_{MsgLogOut}</a>
$nothing
<a href="@{AuthR LoginR}">_{MsgLogIn}</a>

View File

@ -0,0 +1,7 @@
<h2>Your account
<p>
<form method=post action=@{YourAccountR}#form enctype=#{formEnctype}>
^{formWidget}
<button .btn .btn-primary type="submit">
_{MsgSubmit} <span class="glyphicon glyphicon-upload"></span>