changed auth. now both work and login-timestamp gets updated

This commit is contained in:
Nicole Dresselhaus 2015-06-17 16:22:26 +02:00
parent a59e571ea2
commit d2181e5c45
2 changed files with 23 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import Yesod.Auth.BrowserId (authBrowserId)
import Yesod.Default.Util (addStaticContentExternal)
import Yesod.Core.Types (Logger)
import qualified Yesod.Core.Unsafe as Unsafe
import Yesod.Auth.HashDB (authHashDB, getAuthIdHashDB)
import Yesod.Auth.HashDB (authHashDB)
-- | The foundation datatype for your application. This can be a good place to
-- keep settings and values requiring initialization before your application
@ -122,8 +122,27 @@ instance YesodAuth App where
-- Override the above two destinations when a Referer: header is present
redirectToReferer _ = True
getAuthId creds = getAuthIdHashDB AuthR (Just . UniqueUser) creds --authenticate on own site
--TODO: Authenticate via OAuth2
--authenticate :: Creds master -> HandlerT master IO (AuthenticationResult master)
authenticate creds = do
runDB $ do
x <- getBy $ UniqueUser $ credsIdent creds
now <- liftIO getCurrentTime
case x of
Just (Entity uid _) -> do
update uid [UserLastLogin =. now]
return $ Authenticated uid
Nothing -> Authenticated <$> insert User
{ userIdent = credsIdent creds
, userPassword = Nothing
, userLastLogin = now
}
-- return $ UserError Msg.InvalidLogin
{-getAuthId creds = do
auth <- authenticate creds
return $ case auth of
Authentication auid -> Just auid
_ -> Nothing-}
--getAuthIdHashDB AuthR (Just . UniqueUser) creds --authenticate on own site
{-do
runDB $ do
x <- getBy $ UniqueUser $ credsIdent creds

View File

@ -51,7 +51,7 @@ library
build-depends: base >= 4 && < 5
, yesod >= 1.4.1 && < 1.5
, yesod-core >= 1.4.6 && < 1.5
, yesod-auth >= 1.4.0 && < 1.5
, yesod-auth >= 1.4.4 && < 1.5
, yesod-static >= 1.4.0.3 && < 1.5
, yesod-form >= 1.4.0 && < 1.5
, yesod-auth-hashdb >= 1.4.0 && < 1.5