Safe Haskell | None |
---|---|
Language | Haskell2010 |
Adapted from "snaplet-postgresql-simple"'s auth module.
This module allows you to use the auth snaplet with your user database stored
in a Hasql database. When you run your application with this snaplet, a
config file will be copied into the the snaplets/hasql-auth
directory.
This file contains all of the configurable options for the snaplet and allows
you to change them without recompiling your application.
To use this snaplet in your application enable the session, postgres, and auth snaplets as follows:
data App = App { ... -- your own application state here , _sess :: Snaplet SessionManager , _db :: Snaplet (Pool s) , _auth :: Snaplet (AuthManager App) }
Then in your initializer you'll have something like this:
d <- nestSnaplet "db" db $ hasqlInit a <- nestSnaplet "auth" auth $ initHasqlAuth sess d
A database table snap_auth_users
for users is created on initialisation.
- newtype HasqlAuthManager s = HasqlAuthManager {}
- initHasqlAuth :: (CxTx s, Show (CxError s), Show (TxError s), CxAuthUser s) => SnapletLens b SessionManager -> Snaplet (Pool s) -> SnapletInit b (AuthManager b)
- defAuthTable :: Stmt c
- type CxAuthUser c = (CxValue c Text, CxValue c (Maybe Text), CxValue c (Maybe UTCTime), CxValue c Int, CxValue c ByteString, CxValue c (Maybe ByteString), CxValue c Value)
- userFromTuple :: (Int, Text, Maybe Text, ByteString, Maybe UTCTime, Maybe UTCTime, Maybe Text, Int, Int, Maybe UTCTime, Maybe UTCTime, Maybe UTCTime, Maybe ByteString, Maybe ByteString, Maybe UTCTime, Maybe UTCTime, Maybe Text, Maybe UTCTime, Value) -> AuthUser
- saveQuery :: CxAuthUser c => AuthUser -> Tx c s AuthUser
- hideError :: (Show (TxError c), Show (CxError c)) => Either (SessionError c) a -> IO (Either AuthFailure a)
- readMode :: TxMode
- writeMode :: TxMode
- text2int :: Text -> Int
Documentation
newtype HasqlAuthManager s Source
(CxTx s, Show (CxError s), Show (TxError s), CxAuthUser s) => IAuthBackend (HasqlAuthManager s) Source |
:: (CxTx s, Show (CxError s), Show (TxError s), CxAuthUser s) | |
=> SnapletLens b SessionManager | Lens to the session snaplet |
-> Snaplet (Pool s) | The hasql snaplet |
-> SnapletInit b (AuthManager b) |
Initializer for the postgres backend to the auth snaplet.
defAuthTable :: Stmt c Source
Default authentication table layout
type CxAuthUser c = (CxValue c Text, CxValue c (Maybe Text), CxValue c (Maybe UTCTime), CxValue c Int, CxValue c ByteString, CxValue c (Maybe ByteString), CxValue c Value) Source
userFromTuple :: (Int, Text, Maybe Text, ByteString, Maybe UTCTime, Maybe UTCTime, Maybe Text, Int, Int, Maybe UTCTime, Maybe UTCTime, Maybe UTCTime, Maybe ByteString, Maybe ByteString, Maybe UTCTime, Maybe UTCTime, Maybe Text, Maybe UTCTime, Value) -> AuthUser Source