forked from filipg/gonito
add "your account" option
This commit is contained in:
parent
3722329152
commit
652e82fa62
@ -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
|
||||
|
@ -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
42
Handler/YourAccount.hs
Normal 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
|
@ -2,6 +2,7 @@ User
|
||||
ident Text
|
||||
password Text Maybe
|
||||
UniqueUser ident
|
||||
name Text Maybe
|
||||
deriving Typeable
|
||||
Email
|
||||
email Text
|
||||
|
@ -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
|
||||
|
@ -30,6 +30,7 @@ library
|
||||
Handler.Shared
|
||||
Handler.ShowChallenge
|
||||
Handler.Extract
|
||||
Handler.YourAccount
|
||||
|
||||
if flag(dev) || flag(library-only)
|
||||
cpp-options: -DDEVELOPMENT
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
|
7
templates/your-account.hamlet
Normal file
7
templates/your-account.hamlet
Normal 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>
|
Loading…
Reference in New Issue
Block a user