happstack-auth-0.2.1.1: A Happstack Authentication Suite

Portabilitynon-portable
Stabilityexperimental
Maintainermail@n-sch.de

Happstack.Auth

Contents

Description

Happstack.Auth offers an easy way to implement user authentication for Happstack web applications. It uses Happstack.State as database back-end and SHA512 for password encryption. Session safety is ensured by a HTTP header fingerprint (client ip & user-agent) and a configurable session timeout.

To use this module, add the AuthState to your state dependencies, for example:

 import Happstack.Auth

 instance Component MyState where
     type Dependencies MyState = AuthState :+: End
     initialValue = ...

One of the first things in your response monad should be updateTimeout to make sure session timeouts are updated correctly.

Synopsis

High level functions

User registration

registerSource

Arguments

:: (MonadIO m, FilterMonad Response m, ServerMonad m) 
=> Minutes

Session timeout

-> Username 
-> Password 
-> m a

User exists response

-> m a

Success response

-> m a 

Register a new user

changePasswordSource

Arguments

:: MonadIO m 
=> Username 
-> Password

Old password

-> Password

New password

-> m Bool 

Session management

updateTimeout :: (MonadIO m, FilterMonad Response m, MonadPlus m, ServerMonad m) => Minutes -> m ()Source

Update the session timeout of logged in users. Add this to the top of your application route, for example:

 appRoute :: ServerPart Response
 appRoute = updateTimeout 5 >> msum
     [ {- your routing here -}
     ]

performLoginSource

Arguments

:: (MonadIO m, FilterMonad Response m, ServerMonad m) 
=> Minutes

Session timeout

-> User 
-> m a

Run with modified headers, including the new session cookie

-> m a 

loginHandlerSource

Arguments

:: (MonadIO m, FilterMonad Response m, MonadPlus m, ServerMonad m) 
=> Minutes

Session timeout

-> Maybe String

POST field to look for username (default: "username")

-> Maybe String

POST field to look for password (default: "password")

-> m a

Success response

-> (Maybe Username -> Maybe Password -> m a)

Fail response. Arguments: Post data

-> m a 

Handles data from a login form to log the user in.

logoutHandlerSource

Arguments

:: (ServerMonad m, MonadPlus m, MonadIO m, FilterMonad Response m) 
=> m a

Response after logout

-> m a 

withSessionSource

Arguments

:: MonadIO m 
=> (SessionData -> ServerPartT m a)

Logged in response

-> ServerPartT m a

Not logged in response

-> ServerPartT m a 

Run a ServerPartT with the SessionData of the currently logged in user (if available)

loginGateSource

Arguments

:: MonadIO m 
=> ServerPartT m a

Logged in

-> ServerPartT m a

Not registered

-> ServerPartT m a 

Require a login

getSessionData :: (MonadIO m, MonadPlus m, ServerMonad m) => m (Maybe SessionData)Source

Get the SessionData of the currently logged in user

getSessionKey :: (MonadIO m, MonadPlus m, ServerMonad m) => m (Maybe SessionKey)Source

Get the identifier for the current session

Basic functions

Users

updateUser :: MonadIO m => User -> m ()Source

Update (replace) a user

askUsers :: MonadIO m => m UserDBSource

Warning: This UserDB uses the internal types from Happstack.Auth.Data.Internal

Sessions

getSessions :: MonadIO m => m (Sessions SessionData)Source

Warning: This Sessions uses the internal types from Happstack.Auth.Data.Internal

Data types

These data types collide with the data definitions used internaly in Happstack.Auth.Data.Internal. However, if you need both modules you might want to import the Data module qualified:

 import Happstack.Auth
 import qualified Happstack.Auth.Data.Internal as AuthD

data AuthState Source

Add this to your Dependency-List of your application state