From fd57460df143448c11cf4d255b0a1e4f645c2687 Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 14 Aug 2014 00:51:40 +0200 Subject: [PATCH] beautyfied --- Handler/Login.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Handler/Login.hs b/Handler/Login.hs index 15b2384..d2125a9 100644 --- a/Handler/Login.hs +++ b/Handler/Login.hs @@ -25,7 +25,7 @@ postLoginR = do Just user -> do case credentialsPasswd cred == userPassword (entityVal user) of True -> do - setSession "userId" $ pack $ show $ entityKey user + setSession "userId" $ extractKey $ entityKey user setMessage $ [shamlet|
Successfully logged in|]
               redirect $ HomeR
             False -> do
@@ -35,6 +35,12 @@ postLoginR = do
           setMessage $ [shamlet|
User does not exist|]
           redirect $ LoginR
 
+extractKey :: KeyBackend backend entity -> Text
+extractKey = extractKey' . unKey
+  where
+    extractKey' (PersistInt64 k) = pack $ show k
+    extractKey' _ = ""
+
 loginForm :: Form Credentials
 loginForm = renderDivs $ Credentials
   <$> areq textField "Username" Nothing