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 master <- getYesod
mmsg <- getMessage mmsg <- getMessage
msu <- lookupSession "userId" 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: -- We break up the default layout into two components:
-- default-layout is the contents of the body tag, and -- default-layout is the contents of the body tag, and

View file

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

View file

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