-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library simplifying user management for web applications -- @package users @version 0.2.0.1 module Web.Users.Types -- | 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. class (Show (UserId b), Eq (UserId b), ToJSON (UserId b), FromJSON (UserId b), Typeable (UserId b), PathPiece (UserId b)) => UserStorageBackend b where type family UserId b :: * updateUserDetails backend userId f = do { _ <- updateUser backend userId $ \ user -> user {u_more = f (u_more user)}; return () } initUserBackend :: UserStorageBackend b => b -> IO () destroyUserBackend :: UserStorageBackend b => b -> IO () housekeepBackend :: UserStorageBackend b => b -> IO () getUserById :: (UserStorageBackend b, FromJSON a, ToJSON a) => b -> UserId b -> IO (Maybe (User a)) listUsers :: (UserStorageBackend b, FromJSON a, ToJSON a) => b -> Maybe (Int64, Int64) -> IO [(UserId b, User a)] countUsers :: UserStorageBackend b => b -> IO Int64 createUser :: (UserStorageBackend b, FromJSON a, ToJSON a) => b -> User a -> IO (Either CreateUserError (UserId b)) updateUser :: (UserStorageBackend b, FromJSON a, ToJSON a) => b -> UserId b -> (User a -> User a) -> IO (Either UpdateUserError ()) updateUserDetails :: (UserStorageBackend b, FromJSON a, ToJSON a) => b -> UserId b -> (a -> a) -> IO () deleteUser :: UserStorageBackend b => b -> UserId b -> IO () authUser :: UserStorageBackend b => b -> Text -> PasswordPlain -> NominalDiffTime -> IO (Maybe SessionId) verifySession :: UserStorageBackend b => b -> SessionId -> NominalDiffTime -> IO (Maybe (UserId b)) destroySession :: UserStorageBackend b => b -> SessionId -> IO () requestPasswordReset :: UserStorageBackend b => b -> UserId b -> NominalDiffTime -> IO PasswordResetToken verifyPasswordResetToken :: (UserStorageBackend b, FromJSON a, ToJSON a) => b -> PasswordResetToken -> IO (Maybe (User a)) applyNewPassword :: UserStorageBackend b => b -> PasswordResetToken -> Password -> IO (Either TokenError ()) requestActivationToken :: UserStorageBackend b => b -> UserId b -> NominalDiffTime -> IO ActivationToken activateUser :: UserStorageBackend b => b -> ActivationToken -> IO (Either TokenError ()) -- | Core user datatype. Store custom information in the u_more -- field data User a User :: !Text -> !Text -> !Password -> !Bool -> !a -> User a u_name :: User a -> !Text u_email :: User a -> !Text u_password :: User a -> !Password u_active :: User a -> !Bool u_more :: User a -> !a -- | 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. data Password PasswordHash :: !Text -> Password PasswordHidden :: Password -- | Construct a password from plaintext by hashing it makePassword :: PasswordPlain -> Password -- | Strip the password from the user type. hidePassword :: User a -> User a -- | Plaintext passsword. Used for authentification. newtype PasswordPlain PasswordPlain :: Text -> PasswordPlain unPasswordPlain :: PasswordPlain -> Text -- | Check a plaintext password against a password verifyPassword :: PasswordPlain -> Password -> Bool -- | A password reset token to send out to users via email or sms newtype PasswordResetToken PasswordResetToken :: Text -> PasswordResetToken unPasswordResetToken :: PasswordResetToken -> Text -- | An activation token to send out to users via email or sms newtype ActivationToken ActivationToken :: Text -> ActivationToken unActivationToken :: ActivationToken -> Text -- | A session id for identifying user sessions newtype SessionId SessionId :: Text -> SessionId unSessionId :: SessionId -> Text -- | Errors that happen on storage level during user creation data CreateUserError UsernameOrEmailAlreadyTaken :: CreateUserError InvalidPassword :: CreateUserError -- | Errors that happen on storage level during user updating data UpdateUserError UsernameOrEmailAlreadyExists :: UpdateUserError UserDoesntExit :: UpdateUserError -- | Errors that happen on storage level during token actions data TokenError TokenInvalid :: TokenError instance Typeable PasswordResetToken instance Typeable ActivationToken instance Typeable SessionId instance Typeable PasswordPlain instance Typeable Password instance Typeable User instance Show CreateUserError instance Eq CreateUserError instance Show UpdateUserError instance Eq UpdateUserError instance Show TokenError instance Eq TokenError instance Show PasswordResetToken instance Eq PasswordResetToken instance ToJSON PasswordResetToken instance FromJSON PasswordResetToken instance PathPiece PasswordResetToken instance Show ActivationToken instance Eq ActivationToken instance ToJSON ActivationToken instance FromJSON ActivationToken instance PathPiece ActivationToken instance Show SessionId instance Eq SessionId instance ToJSON SessionId instance FromJSON SessionId instance PathPiece SessionId instance Show PasswordPlain instance Eq PasswordPlain instance IsString PasswordPlain instance Show Password instance Eq Password instance Show a => Show (User a) instance Eq a => Eq (User a) instance FromJSON a => FromJSON (User a) instance ToJSON a => ToJSON (User a)