eidolon/Handler/ProfileSettings.hs
2015-01-11 08:57:38 +01:00

50 lines
1.6 KiB
Haskell

module Handler.ProfileSettings where
import Import
import Handler.Commons
getProfileSettingsR :: UserId -> Handler Html
getProfileSettingsR userId = do
checkRes <- profileCheck userId
case checkRes of
Right user -> do
(profileSettingsWidget, enctype) <- generateFormPost $ profileSettingsForm user
formLayout $ do
setTitle "Eidolon :: Profile settings"
$(widgetFile "profileSettings")
Left (errorMsg, route) -> do
setMessage errorMsg
redirect $ route
postProfileSettingsR :: UserId -> Handler Html
postProfileSettingsR userId = do
checkRes <- profileCheck userId
case checkRes of
Right user -> do
((result, _), _) <- runFormPost $ profileSettingsForm user
case result of
FormSuccess temp -> do
runDB $ update userId [
UserName =. (userName temp)
, UserSlug =. (userSlug temp)
, UserEmail =. (userEmail temp)
]
setMessage "Profile settings changed successfully"
redirect $ UserR $ userName user
_ -> do
setMessage "There was an error changing your settings"
redirect $ ProfileSettingsR userId
Left (errorMsg, route) -> do
setMessage errorMsg
redirect $ route
profileSettingsForm :: User -> Form User
profileSettingsForm user = renderDivs $ User
<$> areq textField "Username" (Just $ userName user)
<*> areq textField "Userslug" (Just $ userSlug user)
<*> areq emailField "Email" (Just $ userEmail user)
<*> pure (userSalt user)
<*> pure (userSalted user)
<*> pure (userAlbums user)
<*> pure (userAdmin user)