now getting username from his id in cookie

This commit is contained in:
nek0 2014-08-15 15:41:25 +02:00
parent 8e657f148d
commit b4a4d6fd8f
3 changed files with 14 additions and 7 deletions

View file

@ -68,6 +68,14 @@ instance Yesod App where
master <- getYesod
mmsg <- getMessage
msu <- lookupSession "userId"
username <- case msu of
Just a -> do
uId <- return $ getUserIdFromText a
user <- runDB $ getJust uId
return $ userName user
otherwise -> do
return ("" :: Text)
-- We break up the default layout into two components:
-- default-layout is the contents of the body tag, and

View file

@ -1,7 +1,7 @@
module Helper
( getUserIdFromText
, extractKey
-- , getUserName
-- , getUserNameById
)
where
@ -27,10 +27,9 @@ extractKey = extractKey' . unKey
extractKey' (PersistInt64 k) = pack $ show k
extractKey' _ = ""
--getUserName :: Text -> User
--getUserName textId =
--getUserNameById :: UserId -> Text
--getUserNameById userId =
-- let
-- userId = getUserIdFromText textId
-- user = get $ userId
-- user = runDB $ getJust $ userId
-- in
-- show user
-- userName user

View file

@ -2,7 +2,7 @@
<div id="top-nav">
<ul id="user-nav">
$maybe userId <- msu
Logged in as <a href=@{ProfileR $ getUserIdFromText userId}>$user
Logged in as <a href=@{ProfileR $ getUserIdFromText userId}>#{username}
<li>
<a href=@{LogoutR}>Logout
<li>