yesod-auth: user defined layout
This commit is contained in:
parent
12480b2d2a
commit
d817d37c9c
@ -91,6 +91,10 @@ data Creds master = Creds
|
|||||||
class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage) => YesodAuth master where
|
class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage) => YesodAuth master where
|
||||||
type AuthId master
|
type AuthId master
|
||||||
|
|
||||||
|
-- | specify the layout. Uses defaultLayout by default
|
||||||
|
authLayout :: WidgetT master IO () -> HandlerT master IO Html
|
||||||
|
authLayout = defaultLayout
|
||||||
|
|
||||||
-- | Default destination on successful login, if no other
|
-- | Default destination on successful login, if no other
|
||||||
-- destination exists.
|
-- destination exists.
|
||||||
loginDest :: master -> Route master
|
loginDest :: master -> Route master
|
||||||
@ -109,7 +113,7 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
|
|||||||
loginHandler :: AuthHandler master RepHtml
|
loginHandler :: AuthHandler master RepHtml
|
||||||
loginHandler = do
|
loginHandler = do
|
||||||
tp <- getRouteToParent
|
tp <- getRouteToParent
|
||||||
lift $ defaultLayout $ do
|
lift $ authLayout $ do
|
||||||
setTitleI Msg.LoginTitle
|
setTitleI Msg.LoginTitle
|
||||||
master <- getYesod
|
master <- getYesod
|
||||||
mapM_ (flip apLogin tp) (authPlugins master)
|
mapM_ (flip apLogin tp) (authPlugins master)
|
||||||
@ -273,7 +277,7 @@ setCreds doRedirects creds = do
|
|||||||
Nothing -> do
|
Nothing -> do
|
||||||
sendResponseStatus unauthorized401 =<< (
|
sendResponseStatus unauthorized401 =<< (
|
||||||
selectRep $ do
|
selectRep $ do
|
||||||
provideRep $ defaultLayout $ toWidget [shamlet|<h1>Invalid login|]
|
provideRep $ authLayout $ toWidget [shamlet|<h1>Invalid login|]
|
||||||
provideJsonMessage "Invalid Login"
|
provideJsonMessage "Invalid Login"
|
||||||
)
|
)
|
||||||
Just ar -> loginErrorMessageMasterI ar Msg.InvalidLogin
|
Just ar -> loginErrorMessageMasterI ar Msg.InvalidLogin
|
||||||
@ -288,6 +292,15 @@ setCreds doRedirects creds = do
|
|||||||
provideJsonMessage "Login Successful"
|
provideJsonMessage "Login Successful"
|
||||||
sendResponse res
|
sendResponse res
|
||||||
|
|
||||||
|
-- | same as defaultLayoutJson, but uses authLayout
|
||||||
|
authLayoutJson :: (YesodAuth site, ToJSON j)
|
||||||
|
=> WidgetT site IO () -- ^ HTML
|
||||||
|
-> HandlerT site IO j -- ^ JSON
|
||||||
|
-> HandlerT site IO TypedContent
|
||||||
|
authLayoutJson w json = selectRep $ do
|
||||||
|
provideRep $ authLayout w
|
||||||
|
provideRep $ fmap toJSON json
|
||||||
|
|
||||||
-- | Clears current user credentials for the session.
|
-- | Clears current user credentials for the session.
|
||||||
--
|
--
|
||||||
-- Since 1.1.7
|
-- Since 1.1.7
|
||||||
@ -304,7 +317,7 @@ clearCreds doRedirects = do
|
|||||||
getCheckR :: AuthHandler master TypedContent
|
getCheckR :: AuthHandler master TypedContent
|
||||||
getCheckR = lift $ do
|
getCheckR = lift $ do
|
||||||
creds <- maybeAuthId
|
creds <- maybeAuthId
|
||||||
defaultLayoutJson (do
|
authLayoutJson (do
|
||||||
setTitle "Authentication Status"
|
setTitle "Authentication Status"
|
||||||
toWidget $ html' creds) (return $ jsonCreds creds)
|
toWidget $ html' creds) (return $ jsonCreds creds)
|
||||||
where
|
where
|
||||||
|
|||||||
@ -168,7 +168,7 @@ class (YesodAuth site, PathPiece (AuthEmailId site)) => YesodAuthEmail site wher
|
|||||||
--
|
--
|
||||||
-- Since 1.2.2
|
-- Since 1.2.2
|
||||||
confirmationEmailSentResponse :: Text -> HandlerT site IO Html
|
confirmationEmailSentResponse :: Text -> HandlerT site IO Html
|
||||||
confirmationEmailSentResponse identifier = defaultLayout $ do
|
confirmationEmailSentResponse identifier = authLayout $ do
|
||||||
setTitleI Msg.ConfirmationEmailSentTitle
|
setTitleI Msg.ConfirmationEmailSentTitle
|
||||||
[whamlet|<p>_{Msg.ConfirmationEmailSent identifier}|]
|
[whamlet|<p>_{Msg.ConfirmationEmailSent identifier}|]
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ getRegisterR :: YesodAuthEmail master => HandlerT Auth (HandlerT master IO) Html
|
|||||||
getRegisterR = do
|
getRegisterR = do
|
||||||
email <- newIdent
|
email <- newIdent
|
||||||
tp <- getRouteToParent
|
tp <- getRouteToParent
|
||||||
lift $ defaultLayout $ do
|
lift $ authLayout $ do
|
||||||
setTitleI Msg.RegisterLong
|
setTitleI Msg.RegisterLong
|
||||||
[whamlet|
|
[whamlet|
|
||||||
<p>_{Msg.EnterEmail}
|
<p>_{Msg.EnterEmail}
|
||||||
@ -275,7 +275,7 @@ getForgotPasswordR :: YesodAuthEmail master => HandlerT Auth (HandlerT master IO
|
|||||||
getForgotPasswordR = do
|
getForgotPasswordR = do
|
||||||
tp <- getRouteToParent
|
tp <- getRouteToParent
|
||||||
email <- newIdent
|
email <- newIdent
|
||||||
lift $ defaultLayout $ do
|
lift $ authLayout $ do
|
||||||
setTitleI Msg.PasswordResetTitle
|
setTitleI Msg.PasswordResetTitle
|
||||||
[whamlet|
|
[whamlet|
|
||||||
<p>_{Msg.PasswordResetPrompt}
|
<p>_{Msg.PasswordResetPrompt}
|
||||||
@ -307,7 +307,7 @@ getVerifyR lid key = do
|
|||||||
lift $ setLoginLinkKey uid
|
lift $ setLoginLinkKey uid
|
||||||
redirect setpassR
|
redirect setpassR
|
||||||
_ -> return ()
|
_ -> return ()
|
||||||
lift $ defaultLayout $ do
|
lift $ authLayout $ do
|
||||||
setTitleI Msg.InvalidKey
|
setTitleI Msg.InvalidKey
|
||||||
[whamlet|
|
[whamlet|
|
||||||
$newline never
|
$newline never
|
||||||
@ -358,7 +358,7 @@ getPasswordR = do
|
|||||||
Nothing -> loginErrorMessageI LoginR Msg.BadSetPass
|
Nothing -> loginErrorMessageI LoginR Msg.BadSetPass
|
||||||
tp <- getRouteToParent
|
tp <- getRouteToParent
|
||||||
needOld <- maybe (return True) (lift . needOldPassword) maid
|
needOld <- maybe (return True) (lift . needOldPassword) maid
|
||||||
lift $ defaultLayout $ do
|
lift $ authLayout $ do
|
||||||
setTitleI Msg.SetPassTitle
|
setTitleI Msg.SetPassTitle
|
||||||
[whamlet|
|
[whamlet|
|
||||||
$newline never
|
$newline never
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user