Skip to content

Commit

Permalink
Update to latest heist API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mightybyte committed Aug 22, 2013
1 parent ce65c1c commit 4bf44c1
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions src/Snap/Snaplet/Auth/SpliceHelpers.hs
Expand Up @@ -57,9 +57,9 @@ addAuthSplices
-> Initializer b v ()
addAuthSplices h auth = addConfig h $ mempty
{ hcInterpretedSplices = do
"ifLoggedIn" ?! ifLoggedIn auth
"ifLoggedOut" ?! ifLoggedOut auth
"loggedInUser" ?! loggedInUser auth
"ifLoggedIn" ## ifLoggedIn auth
"ifLoggedOut" ## ifLoggedOut auth
"loggedInUser" ## loggedInUser auth
, hcCompiledSplices = compiledAuthSplices auth
}

Expand All @@ -70,50 +70,50 @@ addAuthSplices h auth = addConfig h $ mempty
compiledAuthSplices :: SnapletLens b (AuthManager b)
-> Splices (SnapletCSplice b)
compiledAuthSplices auth = do
"ifLoggedIn" ?! cIfLoggedIn auth
"ifLoggedOut" ?! cIfLoggedOut auth
"loggedInUser" ?! cLoggedInUser auth
"ifLoggedIn" ## cIfLoggedIn auth
"ifLoggedOut" ## cIfLoggedOut auth
"loggedInUser" ## cLoggedInUser auth


------------------------------------------------------------------------------
-- | Function to generate interpreted splices from an AuthUser.
userISplices :: Monad m => AuthUser -> Splices (I.Splice m)
userISplices AuthUser{..} = do
"userId" ?! I.textSplice $ maybe "-" unUid userId
"userLogin" ?! I.textSplice userLogin
"userEmail" ?! I.textSplice $ fromMaybe "-" userEmail
"userActive" ?! I.textSplice $ T.pack $ show $ isNothing userSuspendedAt
"userLoginCount" ?! I.textSplice $ T.pack $ show userLoginCount
"userFailedCount" ?! I.textSplice $ T.pack $ show userFailedLoginCount
"userLoginAt" ?! I.textSplice $ maybe "-" (T.pack . show) userCurrentLoginAt
"userLastLoginAt" ?! I.textSplice $ maybe "-" (T.pack . show) userLastLoginAt
"userSuspendedAt" ?! I.textSplice $ maybe "-" (T.pack . show) userSuspendedAt
"userLoginIP" ?! I.textSplice $ maybe "-" decodeUtf8 userCurrentLoginIp
"userLastLoginIP" ?! I.textSplice $ maybe "-" decodeUtf8 userLastLoginIp
"userIfActive" ?! ifISplice $ isNothing userSuspendedAt
"userIfSuspended" ?! ifISplice $ isJust userSuspendedAt
"userId" ## I.textSplice $ maybe "-" unUid userId
"userLogin" ## I.textSplice userLogin
"userEmail" ## I.textSplice $ fromMaybe "-" userEmail
"userActive" ## I.textSplice $ T.pack $ show $ isNothing userSuspendedAt
"userLoginCount" ## I.textSplice $ T.pack $ show userLoginCount
"userFailedCount" ## I.textSplice $ T.pack $ show userFailedLoginCount
"userLoginAt" ## I.textSplice $ maybe "-" (T.pack . show) userCurrentLoginAt
"userLastLoginAt" ## I.textSplice $ maybe "-" (T.pack . show) userLastLoginAt
"userSuspendedAt" ## I.textSplice $ maybe "-" (T.pack . show) userSuspendedAt
"userLoginIP" ## I.textSplice $ maybe "-" decodeUtf8 userCurrentLoginIp
"userLastLoginIP" ## I.textSplice $ maybe "-" decodeUtf8 userLastLoginIp
"userIfActive" ## ifISplice $ isNothing userSuspendedAt
"userIfSuspended" ## ifISplice $ isJust userSuspendedAt


------------------------------------------------------------------------------
-- | Compiled splices for AuthUser.
userCSplices :: Monad m => Splices (RuntimeSplice m AuthUser -> C.Splice m)
userCSplices = unionWith const fields ifs
userCSplices = fields `mappend` ifs
where
fields = mapS (C.pureSplice . C.textSplice) $ do
"userId" ?! maybe "-" unUid . userId
"userLogin" ?! userLogin
"userEmail" ?! fromMaybe "-" . userEmail
"userActive" ?! T.pack . show . isNothing . userSuspendedAt
"userLoginCount" ?! T.pack . show . userLoginCount
"userFailedCount" ?! T.pack . show . userFailedLoginCount
"userLoginAt" ?! maybe "-" (T.pack . show) . userCurrentLoginAt
"userLastLoginAt" ?! maybe "-" (T.pack . show) . userLastLoginAt
"userSuspendedAt" ?! maybe "-" (T.pack . show) . userSuspendedAt
"userLoginIP" ?! maybe "-" decodeUtf8 . userCurrentLoginIp
"userLastLoginIP" ?! maybe "-" decodeUtf8 . userLastLoginIp
"userId" ## maybe "-" unUid . userId
"userLogin" ## userLogin
"userEmail" ## fromMaybe "-" . userEmail
"userActive" ## T.pack . show . isNothing . userSuspendedAt
"userLoginCount" ## T.pack . show . userLoginCount
"userFailedCount" ## T.pack . show . userFailedLoginCount
"userLoginAt" ## maybe "-" (T.pack . show) . userCurrentLoginAt
"userLastLoginAt" ## maybe "-" (T.pack . show) . userLastLoginAt
"userSuspendedAt" ## maybe "-" (T.pack . show) . userSuspendedAt
"userLoginIP" ## maybe "-" decodeUtf8 . userCurrentLoginIp
"userLastLoginIP" ## maybe "-" decodeUtf8 . userLastLoginIp
ifs = do
"userIfActive" ?! ifCSplice (isNothing . userSuspendedAt)
"userIfSuspended" ?! ifCSplice (isJust . userSuspendedAt)
"userIfActive" ## ifCSplice (isNothing . userSuspendedAt)
"userIfSuspended" ## ifCSplice (isJust . userSuspendedAt)


------------------------------------------------------------------------------
Expand Down

0 comments on commit 4bf44c1

Please sign in to comment.