maybeAuth/requireAuth use Entity
This commit is contained in:
parent
6b1ccc0f86
commit
26fe38a9f4
@ -218,26 +218,28 @@ maybeAuthId = do
|
||||
|
||||
maybeAuth :: ( YesodAuth m
|
||||
, b ~ YesodPersistBackend m
|
||||
, b ~ PersistEntityBackend val
|
||||
, Key b val ~ AuthId m
|
||||
, PersistStore b (GHandler s m)
|
||||
, PersistEntity val
|
||||
, YesodPersist m
|
||||
) => GHandler s m (Maybe (Key b val, val))
|
||||
) => GHandler s m (Maybe (Entity val))
|
||||
maybeAuth = runMaybeT $ do
|
||||
aid <- MaybeT $ maybeAuthId
|
||||
a <- MaybeT $ runDB $ get aid
|
||||
return (aid, a)
|
||||
return $ Entity aid a
|
||||
|
||||
requireAuthId :: YesodAuth m => GHandler s m (AuthId m)
|
||||
requireAuthId = maybeAuthId >>= maybe redirectLogin return
|
||||
|
||||
requireAuth :: ( YesodAuth m
|
||||
, b ~ YesodPersistBackend m
|
||||
, b ~ PersistEntityBackend val
|
||||
, Key b val ~ AuthId m
|
||||
, PersistStore b (GHandler s m)
|
||||
, PersistEntity val
|
||||
, YesodPersist m
|
||||
) => GHandler s m (Key b val, val)
|
||||
) => GHandler s m (Entity val)
|
||||
requireAuth = maybeAuth >>= maybe redirectLogin return
|
||||
|
||||
redirectLogin :: Yesod m => GHandler s m a
|
||||
|
||||
@ -198,10 +198,10 @@ getAuthIdHashDB :: ( YesodAuth master, YesodPersist master
|
||||
-> Creds master -- ^ the creds argument
|
||||
-> GHandler sub master (Maybe (AuthId master))
|
||||
getAuthIdHashDB authR uniq creds = do
|
||||
muid <- maybeAuth
|
||||
muid <- maybeAuthId
|
||||
case muid of
|
||||
-- user already authenticated
|
||||
Just (uid, _) -> return $ Just uid
|
||||
Just uid -> return $ Just uid
|
||||
Nothing -> do
|
||||
x <- case uniq (credsIdent creds) of
|
||||
Nothing -> return Nothing
|
||||
|
||||
Loading…
Reference in New Issue
Block a user