expand 's' to 'sub'

This commit is contained in:
Greg Weber 2013-01-14 07:36:34 -08:00
parent 0cb1752067
commit 613adc8a3d

View File

@ -62,7 +62,7 @@ type Piece = Text
data AuthPlugin master = AuthPlugin data AuthPlugin master = AuthPlugin
{ apName :: Text { apName :: Text
, apDispatch :: Method -> [Piece] -> GHandler Auth master () , apDispatch :: Method -> [Piece] -> GHandler Auth master ()
, apLogin :: forall s. (Route Auth -> Route master) -> GWidget s master () , apLogin :: forall sub. (Route Auth -> Route master) -> GWidget sub master ()
} }
getAuth :: a -> Auth getAuth :: a -> Auth
@ -87,7 +87,7 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
logoutDest :: master -> Route master logoutDest :: master -> Route master
-- | Determine the ID associated with the set of credentials. -- | Determine the ID associated with the set of credentials.
getAuthId :: Creds master -> GHandler s master (Maybe (AuthId master)) getAuthId :: Creds master -> GHandler sub master (Maybe (AuthId master))
-- | Which authentication backends to use. -- | Which authentication backends to use.
authPlugins :: master -> [AuthPlugin master] authPlugins :: master -> [AuthPlugin master]
@ -119,11 +119,11 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
-- | Called on a successful login. By default, calls -- | Called on a successful login. By default, calls
-- @setMessageI NowLoggedIn@. -- @setMessageI NowLoggedIn@.
onLogin :: GHandler s master () onLogin :: GHandler sub master ()
onLogin = setMessageI Msg.NowLoggedIn onLogin = setMessageI Msg.NowLoggedIn
-- | Called on logout. By default, does nothing -- | Called on logout. By default, does nothing
onLogout :: GHandler s master () onLogout :: GHandler sub master ()
onLogout = return () onLogout = return ()
-- | Retrieves user credentials, if user is authenticated. -- | Retrieves user credentials, if user is authenticated.
@ -135,7 +135,7 @@ class (Yesod master, PathPiece (AuthId master), RenderMessage master FormMessage
-- other than a browser. -- other than a browser.
-- --
-- Since 1.1.2 -- Since 1.1.2
maybeAuthId :: GHandler s master (Maybe (AuthId master)) maybeAuthId :: GHandler sub master (Maybe (AuthId master))
maybeAuthId = defaultMaybeAuthId maybeAuthId = defaultMaybeAuthId
credsKey :: Text credsKey :: Text
@ -145,7 +145,7 @@ credsKey = "_ID"
-- --
-- Since 1.1.2 -- Since 1.1.2
defaultMaybeAuthId :: YesodAuth master defaultMaybeAuthId :: YesodAuth master
=> GHandler s master (Maybe (AuthId master)) => GHandler sub master (Maybe (AuthId master))
defaultMaybeAuthId = do defaultMaybeAuthId = do
ms <- lookupSession credsKey ms <- lookupSession credsKey
case ms of case ms of
@ -163,7 +163,7 @@ mkYesodSub "Auth"
/page/#Text/STRINGS PluginR /page/#Text/STRINGS PluginR
|] |]
setCreds :: YesodAuth master => Bool -> Creds master -> GHandler s master () setCreds :: YesodAuth master => Bool -> Creds master -> GHandler sub master ()
setCreds doRedirects creds = do setCreds doRedirects creds = do
y <- getYesod y <- getYesod
maid <- getAuthId creds maid <- getAuthId creds
@ -236,44 +236,44 @@ handlePluginR plugin pieces = do
maybeAuth :: ( YesodAuth master maybeAuth :: ( YesodAuth master
#if MIN_VERSION_persistent(1, 1, 0) #if MIN_VERSION_persistent(1, 1, 0)
, PersistMonadBackend (b (GHandler s master)) ~ PersistEntityBackend val , PersistMonadBackend (b (GHandler sub master)) ~ PersistEntityBackend val
, b ~ YesodPersistBackend master , b ~ YesodPersistBackend master
, Key val ~ AuthId master , Key val ~ AuthId master
, PersistStore (b (GHandler s master)) , PersistStore (b (GHandler sub master))
#else #else
, b ~ YesodPersistBackend master , b ~ YesodPersistBackend master
, b ~ PersistEntityBackend val , b ~ PersistEntityBackend val
, Key b val ~ AuthId master , Key b val ~ AuthId master
, PersistStore b (GHandler s master) , PersistStore b (GHandler sub master)
#endif #endif
, PersistEntity val , PersistEntity val
, YesodPersist master , YesodPersist master
) => GHandler s master (Maybe (Entity val)) ) => GHandler sub master (Maybe (Entity val))
maybeAuth = runMaybeT $ do maybeAuth = runMaybeT $ do
aid <- MaybeT $ maybeAuthId aid <- MaybeT $ maybeAuthId
a <- MaybeT $ runDB $ get aid a <- MaybeT $ runDB $ get aid
return $ Entity aid a return $ Entity aid a
requireAuthId :: YesodAuth master => GHandler s master (AuthId master) requireAuthId :: YesodAuth master => GHandler sub master (AuthId master)
requireAuthId = maybeAuthId >>= maybe redirectLogin return requireAuthId = maybeAuthId >>= maybe redirectLogin return
requireAuth :: ( YesodAuth master requireAuth :: ( YesodAuth master
, b ~ YesodPersistBackend master , b ~ YesodPersistBackend master
#if MIN_VERSION_persistent(1, 1, 0) #if MIN_VERSION_persistent(1, 1, 0)
, PersistMonadBackend (b (GHandler s master)) ~ PersistEntityBackend val , PersistMonadBackend (b (GHandler sub master)) ~ PersistEntityBackend val
, Key val ~ AuthId master , Key val ~ AuthId master
, PersistStore (b (GHandler s master)) , PersistStore (b (GHandler sub master))
#else #else
, b ~ PersistEntityBackend val , b ~ PersistEntityBackend val
, Key b val ~ AuthId master , Key b val ~ AuthId master
, PersistStore b (GHandler s master) , PersistStore b (GHandler sub master)
#endif #endif
, PersistEntity val , PersistEntity val
, YesodPersist master , YesodPersist master
) => GHandler s master (Entity val) ) => GHandler sub master (Entity val)
requireAuth = maybeAuth >>= maybe redirectLogin return requireAuth = maybeAuth >>= maybe redirectLogin return
redirectLogin :: Yesod master => GHandler s master a redirectLogin :: Yesod master => GHandler sub master a
redirectLogin = do redirectLogin = do
y <- getYesod y <- getYesod
setUltDestCurrent setUltDestCurrent