Commit 2c11ea64 authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

login logout.

parent 8525a8c2
......@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: f0531eee1458086fe8489757aa53ee4e4990405053ccaac6e1d42cee760424a1
-- hash: d861629c79fdb1cf06fd75ce62386af16a3660c0912ab0ae3a6ec30a93346e12
name: Cirkeltrek
version: 0.0.0
......@@ -16,6 +16,7 @@ library
Home
Model
Model.Grouping
Profile
Settings
other-modules:
Paths_Cirkeltrek
......
......@@ -20,12 +20,14 @@ import Network.Wai (Middleware)
import Network.Wai.Handler.Warp
import Network.Wai.Middleware.RequestLogger
import System.Log.FastLogger
import Yesod.Auth
import Yesod.Core
import Yesod.Core.Types (loggerSet)
import Yesod.Default.Config2
import Yesod.Static
import Home
import Profile
import Model
import Settings (ApplicationSettings (..),
configSettingsYmlValue)
......
......@@ -8,7 +8,6 @@
module Foundation where
import ClassyPrelude
import ClassyPrelude.Yesod
import Database.Persist.Sql
......@@ -36,7 +35,9 @@ data App = App
mkYesodData
"App"
[parseRoutes|
/ HomeR GET
/ HomeR GET
/auth SigninR Auth getAuth
/profile ProfileR GET
|]
type Form a = Html -> MForm (HandlerFor App) (FormResult a, Widget)
......@@ -52,17 +53,28 @@ instance Yesod App where
yesodMiddleware = defaultYesodMiddleware
defaultLayout widget = do
master <- getYesod
maut <- maybeAuth
mmessage <- getMessage
mcurrentroute <- getCurrentRoute
pagecontent <- widgetToPageContent $ do
[whamlet|
$maybe route <- mcurrentroute
<p> You're at #{show route}.
$maybe aut <- maut
<a [email protected]{SigninR LogoutR}> Logout
$nothing
<p> Apparently you're lost.
<a [email protected]{SigninR LoginR}> Login
^{widget}
|]
withUrlRenderer $(hamletFile "templates/wrapper.hamlet")
authRoute _ = Just $ SigninR LoginR
isAuthorized (SigninR _) _ = return Authorized
isAuthorized HomeR _ = return Authorized
isAuthorized ProfileR _ = isLoggedIn
isLoggedIn :: Handler AuthResult
isLoggedIn = do
maut <- maybeAuth
case maut of
Nothing -> return $ Unauthorized "login please"
Just _ -> return Authorized
instance YesodPersist App where
type YesodPersistBackend App = SqlBackend
......
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Profile where
import Foundation
import Database.Persist.Sql
import Yesod.Auth
import Yesod.Core
import Model
getProfileR :: Handler Html
getProfileR = do
(Just (Entity userid user)) <- maybeAuth
defaultLayout $ do
setTitle "Nice"
[whamlet|
<p> You are: #{usersUsername user}
<p> Userid: #{fromSqlKey userid}
<p> Your email: #{usersEmail user}
|]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment