yesod-auth-0.4.0.2: Authentication for Yesod.

PortabilityPortable
StabilityStable
Maintainerpbrisbin@gmail.com

Yesod.Helpers.Auth.HashDB

Description

A yesod-auth AuthPlugin designed to look users up in Persist where their user id's and a sha1 hash of their password will already be stored.

Example usage:

 -- import the function
 import Helpers.Auth.HashDB

 -- make sure you have an auth route
 mkYesodData "MyApp" [$parseRoutes|
 / RootR GET
 /auth AuthR Auth getAuth
 |]


 -- make your app an instance of YesodAuth using this plugin
 instance YesodAuth MyApp where
    type AuthId MyApp = UserId

    loginDest _  = RootR
    logoutDest _ = RootR
    getAuthId    = getAuthIdHashDB AuthR 
    showAuthId _ = showIntegral
    readAuthId _ = readIntegral
    authPlugins  = [authHashDB]


 -- include the migration function in site startup
 withServer :: (Application -> IO a) -> IO a
 withServer f = withConnectionPool $ \p -> do
     runSqlPool (runMigration migrateUsers) p
     let h = DevSite p

Your app must be an instance of YesodPersist and the username and hashed-passwords must be added manually to the database.

 echo -n 'MyPassword' | sha1sum

can be used to get the hash from the commandline.

Synopsis

Documentation

authHashDB :: (YesodAuth y, YesodPersist y, PersistBackend (YesodDB y (GGHandler Auth y IO))) => AuthPlugin ySource

Prompt for username and password, validate that against a database which holds the username and a hash of the password

getAuthIdHashDBSource

Arguments

:: (Key User ~ AuthId master, PersistBackend (YesodDB master (GGHandler sub master IO)), YesodPersist master, YesodAuth master) 
=> (AuthRoute -> Route master)

your site's Auth Route

-> Creds m

the creds argument

-> GHandler sub master (Maybe UserId) 

A drop in for the getAuthId method of your YesodAuth instance which can be used if authHashDB is the only plugin in use.

type UserId = Key UserSource