| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Web.Users.Types
Synopsis
- class IsUserBackend b => UserStorageBackend b where
- type UserId b :: *
- initUserBackend :: b -> IO ()
- destroyUserBackend :: b -> IO ()
- housekeepBackend :: b -> IO ()
- getUserIdByName :: b -> Text -> IO (Maybe (UserId b))
- getUserById :: b -> UserId b -> IO (Maybe User)
- listUsers :: b -> Maybe (Int64, Int64) -> SortBy UserField -> IO [(UserId b, User)]
- countUsers :: b -> IO Int64
- createUser :: b -> User -> IO (Either CreateUserError (UserId b))
- updateUser :: b -> UserId b -> (User -> User) -> IO (Either UpdateUserError ())
- deleteUser :: b -> UserId b -> IO ()
- authUser :: b -> Text -> PasswordPlain -> NominalDiffTime -> IO (Maybe SessionId)
- withAuthUser :: b -> Text -> (User -> Bool) -> (UserId b -> IO r) -> IO (Maybe r)
- verifySession :: b -> SessionId -> NominalDiffTime -> IO (Maybe (UserId b))
- createSession :: b -> UserId b -> NominalDiffTime -> IO (Maybe SessionId)
- destroySession :: b -> SessionId -> IO ()
- requestPasswordReset :: b -> UserId b -> NominalDiffTime -> IO PasswordResetToken
- verifyPasswordResetToken :: b -> PasswordResetToken -> IO (Maybe User)
- applyNewPassword :: b -> PasswordResetToken -> Password -> IO (Either TokenError ())
- requestActivationToken :: b -> UserId b -> NominalDiffTime -> IO ActivationToken
- activateUser :: b -> ActivationToken -> IO (Either TokenError ())
- data User = User {}
- data Password
- makePassword :: PasswordPlain -> Password
- hidePassword :: User -> User
- newtype PasswordPlain = PasswordPlain {}
- verifyPassword :: PasswordPlain -> Password -> Bool
- data UserField
- newtype PasswordResetToken = PasswordResetToken {}
- newtype ActivationToken = ActivationToken {}
- newtype SessionId = SessionId {
- unSessionId :: Text
- data CreateUserError
- data UpdateUserError
- data TokenError = TokenInvalid
- data SortBy t
The core type class
class IsUserBackend b => UserStorageBackend b where #
An abstract backend for managing users. A backend library should implement the interface and an end user should build applications on top of this interface.
Methods
initUserBackend :: b -> IO () #
Initialise the backend. Call once on application launch to for example create missing database tables
destroyUserBackend :: b -> IO () #
Destory the backend. WARNING: This is only for testing! It deletes all tables and data.
housekeepBackend :: b -> IO () #
This cleans up invalid sessions and other tokens. Call periodically as needed.
getUserIdByName :: b -> Text -> IO (Maybe (UserId b)) #
Retrieve a user id from the database
getUserById :: b -> UserId b -> IO (Maybe User) #
Retrieve a user from the database
listUsers :: b -> Maybe (Int64, Int64) -> SortBy UserField -> IO [(UserId b, User)] #
List all users unlimited, or limited, sorted by a UserField
countUsers :: b -> IO Int64 #
Count all users
createUser :: b -> User -> IO (Either CreateUserError (UserId b)) #
Create a user
updateUser :: b -> UserId b -> (User -> User) -> IO (Either UpdateUserError ()) #
Modify a user
deleteUser :: b -> UserId b -> IO () #
Delete a user
authUser :: b -> Text -> PasswordPlain -> NominalDiffTime -> IO (Maybe SessionId) #
Authentificate a user using username/email and password. The NominalDiffTime describes the session duration
withAuthUser :: b -> Text -> (User -> Bool) -> (UserId b -> IO r) -> IO (Maybe r) #
Authentificate a user and execute a single action.
verifySession :: b -> SessionId -> NominalDiffTime -> IO (Maybe (UserId b)) #
Verify a SessionId. The session duration can be extended by NominalDiffTime
createSession :: b -> UserId b -> NominalDiffTime -> IO (Maybe SessionId) #
Force create a session for a user. This is useful for support/admin login. If the user does not exist, this will fail.
destroySession :: b -> SessionId -> IO () #
Destroy a session
requestPasswordReset :: b -> UserId b -> NominalDiffTime -> IO PasswordResetToken #
Request a PasswordResetToken for a given user, valid for NominalDiffTime
verifyPasswordResetToken :: b -> PasswordResetToken -> IO (Maybe User) #
Check if a PasswordResetToken is still valid and retrieve the owner of it
applyNewPassword :: b -> PasswordResetToken -> Password -> IO (Either TokenError ()) #
Apply a new password to the owner of PasswordResetToken iff the token is still valid
requestActivationToken :: b -> UserId b -> NominalDiffTime -> IO ActivationToken #
Request an ActivationToken for a given user, valid for NominalDiffTime
activateUser :: b -> ActivationToken -> IO (Either TokenError ()) #
Activate the owner of ActivationToken iff the token is still valid
User representation
Core user datatype
Password representation. When updating or creating a user, use makePassword to create one.
The implementation details of this type are ONLY for use in backend implementations.
Constructors
| PasswordHash !Text | |
| PasswordHidden |
makePassword :: PasswordPlain -> Password #
Construct a password from plaintext by hashing it
hidePassword :: User -> User #
Strip the password from the user type.
newtype PasswordPlain #
Plaintext passsword. Used for authentification.
Constructors
| PasswordPlain | |
Fields | |
Instances
| Eq PasswordPlain # | |
Defined in Web.Users.Types Methods (==) :: PasswordPlain -> PasswordPlain -> Bool # (/=) :: PasswordPlain -> PasswordPlain -> Bool # | |
| Show PasswordPlain # | |
Defined in Web.Users.Types Methods showsPrec :: Int -> PasswordPlain -> ShowS # show :: PasswordPlain -> String # showList :: [PasswordPlain] -> ShowS # | |
| IsString PasswordPlain # | |
Defined in Web.Users.Types Methods fromString :: String -> PasswordPlain # | |
verifyPassword :: PasswordPlain -> Password -> Bool #
Check a plaintext password against a password
Fields of user datatype
Token types
newtype PasswordResetToken #
A password reset token to send out to users via email or sms
Constructors
| PasswordResetToken | |
Fields | |
Instances
| Eq PasswordResetToken # | |
Defined in Web.Users.Types Methods (==) :: PasswordResetToken -> PasswordResetToken -> Bool # (/=) :: PasswordResetToken -> PasswordResetToken -> Bool # | |
| Show PasswordResetToken # | |
Defined in Web.Users.Types Methods showsPrec :: Int -> PasswordResetToken -> ShowS # show :: PasswordResetToken -> String # showList :: [PasswordResetToken] -> ShowS # | |
| ToJSON PasswordResetToken # | |
Defined in Web.Users.Types Methods toJSON :: PasswordResetToken -> Value # toEncoding :: PasswordResetToken -> Encoding # toJSONList :: [PasswordResetToken] -> Value # toEncodingList :: [PasswordResetToken] -> Encoding # | |
| FromJSON PasswordResetToken # | |
Defined in Web.Users.Types Methods parseJSON :: Value -> Parser PasswordResetToken # parseJSONList :: Value -> Parser [PasswordResetToken] # | |
| PathPiece PasswordResetToken # | |
Defined in Web.Users.Types Methods fromPathPiece :: Text -> Maybe PasswordResetToken # toPathPiece :: PasswordResetToken -> Text # | |
newtype ActivationToken #
An activation token to send out to users via email or sms
Constructors
| ActivationToken | |
Fields | |
Instances
| Eq ActivationToken # | |
Defined in Web.Users.Types Methods (==) :: ActivationToken -> ActivationToken -> Bool # (/=) :: ActivationToken -> ActivationToken -> Bool # | |
| Show ActivationToken # | |
Defined in Web.Users.Types Methods showsPrec :: Int -> ActivationToken -> ShowS # show :: ActivationToken -> String # showList :: [ActivationToken] -> ShowS # | |
| ToJSON ActivationToken # | |
Defined in Web.Users.Types Methods toJSON :: ActivationToken -> Value # toEncoding :: ActivationToken -> Encoding # toJSONList :: [ActivationToken] -> Value # toEncodingList :: [ActivationToken] -> Encoding # | |
| FromJSON ActivationToken # | |
Defined in Web.Users.Types Methods parseJSON :: Value -> Parser ActivationToken # parseJSONList :: Value -> Parser [ActivationToken] # | |
| PathPiece ActivationToken # | |
Defined in Web.Users.Types | |
A session id for identifying user sessions
Constructors
| SessionId | |
Fields
| |
Error types
data CreateUserError #
Errors that happen on storage level during user creation
Instances
| Eq CreateUserError # | |
Defined in Web.Users.Types Methods (==) :: CreateUserError -> CreateUserError -> Bool # (/=) :: CreateUserError -> CreateUserError -> Bool # | |
| Show CreateUserError # | |
Defined in Web.Users.Types Methods showsPrec :: Int -> CreateUserError -> ShowS # show :: CreateUserError -> String # showList :: [CreateUserError] -> ShowS # | |
data UpdateUserError #
Errors that happen on storage level during user updating
Constructors
| UsernameAlreadyExists | |
| EmailAlreadyExists | |
| UserDoesntExist |
Instances
| Eq UpdateUserError # | |
Defined in Web.Users.Types Methods (==) :: UpdateUserError -> UpdateUserError -> Bool # (/=) :: UpdateUserError -> UpdateUserError -> Bool # | |
| Show UpdateUserError # | |
Defined in Web.Users.Types Methods showsPrec :: Int -> UpdateUserError -> ShowS # show :: UpdateUserError -> String # showList :: [UpdateUserError] -> ShowS # | |
data TokenError #
Errors that happen on storage level during token actions
Constructors
| TokenInvalid |
Instances
| Eq TokenError # | |
Defined in Web.Users.Types | |
| Show TokenError # | |
Defined in Web.Users.Types Methods showsPrec :: Int -> TokenError -> ShowS # show :: TokenError -> String # showList :: [TokenError] -> ShowS # | |