From b4a4d6fd8f7ab22e085249699ea56a0b7476f4e2 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 15 Aug 2014 15:41:25 +0200 Subject: [PATCH] now getting username from his id in cookie --- Foundation.hs | 8 ++++++++ Helper.hs | 11 +++++------ templates/default-layout.hamlet | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Foundation.hs b/Foundation.hs index 83ff501..684f8b8 100644 --- a/Foundation.hs +++ b/Foundation.hs @@ -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 diff --git a/Helper.hs b/Helper.hs index 3582be4..73fbe47 100644 --- a/Helper.hs +++ b/Helper.hs @@ -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 diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index 2d11200..7f7f940 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -2,7 +2,7 @@