Copyright | (c) Anton Gushcha 2016 |
---|---|
License | MIT |
Maintainer | ncrashed@gmail.com |
Stability | experimental |
Portability | Portable |
Safe Haskell | None |
Language | Haskell2010 |
Servant.Server.Auth.Token.Model
Description
- data UserImpl = UserImpl {
- userImplLogin :: !Login
- userImplPassword :: !Password
- userImplEmail :: !Email
- data UserPerm = UserPerm {}
- data AuthToken = AuthToken {}
- data UserRestore = UserRestore {}
- data AuthUserGroup = AuthUserGroup {}
- data AuthUserGroupUsers = AuthUserGroupUsers {}
- data AuthUserGroupPerms = AuthUserGroupPerms {}
- data UserSingleUseCode = UserSingleUseCode {}
- data UserImplId
- data UserPermId
- data AuthTokenId
- data UserRestoreId
- data AuthUserGroupId
- data AuthUserGroupUsersId
- data AuthUserGroupPermsId
- data UserSingleUseCodeId
- class MonadIO m => HasStorage m where
- passToByteString :: Password -> ByteString
- byteStringToPass :: ByteString -> Password
- userToUserInfo :: WithId UserImplId UserImpl -> [Permission] -> [UserGroupId] -> RespUserInfo
- readUserInfo :: HasStorage m => UserId -> m (Maybe RespUserInfo)
- readUserInfoByLogin :: HasStorage m => Login -> m (Maybe RespUserInfo)
- getUserPermissions :: HasStorage m => UserImplId -> m [Permission]
- setUserPermissions :: HasStorage m => UserImplId -> [Permission] -> m ()
- createUser :: HasStorage m => Int -> Login -> Password -> Email -> [Permission] -> m UserImplId
- hasPerms :: HasStorage m => UserImplId -> [Permission] -> m Bool
- createAdmin :: HasStorage m => Int -> Login -> Password -> Email -> m UserImplId
- ensureAdmin :: HasStorage m => Int -> Login -> Password -> Email -> m ()
- patchUser :: HasStorage m => Int -> PatchUser -> WithId UserImplId UserImpl -> m (WithId UserImplId UserImpl)
- setUserPassword' :: MonadIO m => Int -> Password -> UserImpl -> m UserImpl
- getUserGroups :: HasStorage m => UserImplId -> m [UserGroupId]
- setUserGroups :: HasStorage m => UserImplId -> [UserGroupId] -> m ()
- validateGroups :: HasStorage m => [UserGroupId] -> m [AuthUserGroupId]
- getGroupPermissions :: HasStorage m => UserGroupId -> m [Permission]
- getUserGroupPermissions :: HasStorage m => UserImplId -> m [Permission]
- getUserAllPermissions :: HasStorage m => UserImplId -> m [Permission]
- readUserGroup :: HasStorage m => UserGroupId -> m (Maybe UserGroup)
- toAuthUserGroup :: UserGroup -> (AuthUserGroup, AuthUserGroupId -> [AuthUserGroupUsers], AuthUserGroupId -> [AuthUserGroupPerms])
- insertUserGroup :: HasStorage m => UserGroup -> m UserGroupId
- updateUserGroup :: HasStorage m => UserGroupId -> UserGroup -> m ()
- deleteUserGroup :: HasStorage m => UserGroupId -> m ()
- patchUserGroup :: HasStorage m => UserGroupId -> PatchUserGroup -> m ()
- makeUserInfo :: HasStorage m => WithId UserImplId UserImpl -> m RespUserInfo
DB entities
Internal user implementation
Constructors
UserImpl | |
Fields
|
Internal implementation of permission (1-M)
Constructors
UserPerm | |
Fields
|
Internal implementation of authorisation token
Constructors
AuthToken | |
Fields
|
data UserRestore Source #
Internal implementation of restoration code
Constructors
UserRestore | |
Fields
|
Instances
data AuthUserGroup Source #
Internal implementation of user group
Constructors
AuthUserGroup | |
Fields
|
Instances
data AuthUserGroupUsers Source #
Implementation of M-M between user and group
Constructors
AuthUserGroupUsers | |
Instances
data AuthUserGroupPerms Source #
Implementation of M-M between permission and group
Constructors
AuthUserGroupPerms | |
Instances
data UserSingleUseCode Source #
Internal implementation of single use code
Constructors
UserSingleUseCode | |
Fields
|
Instances
IDs of entities
data UserRestoreId Source #
ID of restoration code
data AuthUserGroupId Source #
ID of user group
data AuthUserGroupUsersId Source #
ID of user-group binding
data AuthUserGroupPermsId Source #
ID of permission-group binding
data UserSingleUseCodeId Source #
ID of single use code
DB interface
class MonadIO m => HasStorage m where Source #
Abstract storage interface. External libraries can implement this in terms of PostgreSQL or acid-state.
Minimal complete definition
getUserImpl, getUserImplByLogin, listUsersPaged, getUserImplPermissions, deleteUserPermissions, insertUserPerm, insertUserImpl, replaceUserImpl, deleteUserImpl, hasPerm, getFirstUserByPerm, selectUserImplGroups, clearUserImplGroups, insertAuthUserGroup, insertAuthUserGroupUsers, insertAuthUserGroupPerms, getAuthUserGroup, listAuthUserGroupPermissions, listAuthUserGroupUsers, replaceAuthUserGroup, clearAuthUserGroupUsers, clearAuthUserGroupPerms, deleteAuthUserGroup, listGroupsPaged, setAuthUserGroupName, setAuthUserGroupParent, insertSingleUseCode, setSingleUseCodeUsed, getUnusedCode, invalidatePermamentCodes, selectLastRestoreCode, insertUserRestore, findRestoreCode, replaceRestoreCode, findAuthToken, findAuthTokenByValue, insertAuthToken, replaceAuthToken
Methods
getUserImpl :: UserImplId -> m (Maybe UserImpl) Source #
Getting user from storage
getUserImplByLogin :: Login -> m (Maybe (WithId UserImplId UserImpl)) Source #
Getting user from storage by login
listUsersPaged :: Page -> PageSize -> m ([WithId UserImplId UserImpl], Word) Source #
Get paged list of users and total count of users
getUserImplPermissions :: UserImplId -> m [WithId UserPermId UserPerm] Source #
Get user permissions, ascending by tag
deleteUserPermissions :: UserImplId -> m () Source #
Delete user permissions
insertUserPerm :: UserPerm -> m UserPermId Source #
Insertion of new user permission
insertUserImpl :: UserImpl -> m UserImplId Source #
Insertion of new user
replaceUserImpl :: UserImplId -> UserImpl -> m () Source #
Replace user with new value
deleteUserImpl :: UserImplId -> m () Source #
Delete user by id
hasPerm :: UserImplId -> Permission -> m Bool Source #
Check whether the user has particular permission
getFirstUserByPerm :: Permission -> m (Maybe (WithId UserImplId UserImpl)) Source #
Get any user with given permission
selectUserImplGroups :: UserImplId -> m [WithId AuthUserGroupUsersId AuthUserGroupUsers] Source #
Select user groups and sort them by ascending name
clearUserImplGroups :: UserImplId -> m () Source #
Remove user from all groups
insertAuthUserGroup :: AuthUserGroup -> m AuthUserGroupId Source #
Add new user group
insertAuthUserGroupUsers :: AuthUserGroupUsers -> m AuthUserGroupUsersId Source #
Add user to given group
insertAuthUserGroupPerms :: AuthUserGroupPerms -> m AuthUserGroupPermsId Source #
Add permission to given group
getAuthUserGroup :: AuthUserGroupId -> m (Maybe AuthUserGroup) Source #
Find user group by id
listAuthUserGroupPermissions :: AuthUserGroupId -> m [WithId AuthUserGroupPermsId AuthUserGroupPerms] Source #
Get list of permissions of given group
listAuthUserGroupUsers :: AuthUserGroupId -> m [WithId AuthUserGroupUsersId AuthUserGroupUsers] Source #
Get list of all users of the group
replaceAuthUserGroup :: AuthUserGroupId -> AuthUserGroup -> m () Source #
Replace record of user group
clearAuthUserGroupUsers :: AuthUserGroupId -> m () Source #
Remove all users from group
clearAuthUserGroupPerms :: AuthUserGroupId -> m () Source #
Remove all permissions from group
deleteAuthUserGroup :: AuthUserGroupId -> m () Source #
Delete user group from storage
listGroupsPaged :: Page -> PageSize -> m ([WithId AuthUserGroupId AuthUserGroup], Word) Source #
Get paged list of user groups with total count
setAuthUserGroupName :: AuthUserGroupId -> Text -> m () Source #
Set group name
setAuthUserGroupParent :: AuthUserGroupId -> Maybe AuthUserGroupId -> m () Source #
Set group parent
insertSingleUseCode :: UserSingleUseCode -> m UserSingleUseCodeId Source #
Add new single use code
setSingleUseCodeUsed :: UserSingleUseCodeId -> Maybe UTCTime -> m () Source #
Set usage time of the single use code
getUnusedCode :: SingleUseCode -> UserImplId -> UTCTime -> m (Maybe (WithId UserSingleUseCodeId UserSingleUseCode)) Source #
Find unused code for the user and expiration time greater than the given time
invalidatePermamentCodes :: UserImplId -> UTCTime -> m () Source #
Invalidate all permament codes for user and set use time for them
selectLastRestoreCode :: UserImplId -> UTCTime -> m (Maybe (WithId UserRestoreId UserRestore)) Source #
Select last valid restoration code by the given current time
insertUserRestore :: UserRestore -> m UserRestoreId Source #
Insert new restore code
findRestoreCode :: UserImplId -> RestoreCode -> UTCTime -> m (Maybe (WithId UserRestoreId UserRestore)) Source #
Find unexpired by the time restore code
replaceRestoreCode :: UserRestoreId -> UserRestore -> m () Source #
Replace restore code with new value
findAuthToken :: UserImplId -> UTCTime -> m (Maybe (WithId AuthTokenId AuthToken)) Source #
Find first non-expired by the time token for user
findAuthTokenByValue :: SimpleToken -> m (Maybe (WithId AuthTokenId AuthToken)) Source #
Find token by value
insertAuthToken :: AuthToken -> m AuthTokenId Source #
Insert new token
replaceAuthToken :: AuthTokenId -> AuthToken -> m () Source #
Replace auth token with new value
Operations
passToByteString :: Password -> ByteString Source #
Convert password to bytestring
byteStringToPass :: ByteString -> Password Source #
Convert bytestring into password
User
userToUserInfo :: WithId UserImplId UserImpl -> [Permission] -> [UserGroupId] -> RespUserInfo Source #
Helper to convert user to response
readUserInfo :: HasStorage m => UserId -> m (Maybe RespUserInfo) Source #
Get user by id
readUserInfoByLogin :: HasStorage m => Login -> m (Maybe RespUserInfo) Source #
Get user by login
getUserPermissions :: HasStorage m => UserImplId -> m [Permission] Source #
Return list of permissions for the given user (only permissions that are assigned to him directly)
setUserPermissions :: HasStorage m => UserImplId -> [Permission] -> m () Source #
Return list of permissions for the given user
createUser :: HasStorage m => Int -> Login -> Password -> Email -> [Permission] -> m UserImplId Source #
Creation of new user
hasPerms :: HasStorage m => UserImplId -> [Permission] -> m Bool Source #
Check whether the user has particular permissions
createAdmin :: HasStorage m => Int -> Login -> Password -> Email -> m UserImplId Source #
Creates user with admin privileges
ensureAdmin :: HasStorage m => Int -> Login -> Password -> Email -> m () Source #
Ensures that DB has at leas one admin, if not, creates a new one with specified info.
Arguments
:: HasStorage m | |
=> Int | Password strength |
-> PatchUser | |
-> WithId UserImplId UserImpl | |
-> m (WithId UserImplId UserImpl) |
Apply patches for user
Update password of user
User groups
getUserGroups :: HasStorage m => UserImplId -> m [UserGroupId] Source #
Get all groups the user belongs to
setUserGroups :: HasStorage m => UserImplId -> [UserGroupId] -> m () Source #
Rewrite all user groups
validateGroups :: HasStorage m => [UserGroupId] -> m [AuthUserGroupId] Source #
Leave only existing groups
getGroupPermissions :: HasStorage m => UserGroupId -> m [Permission] Source #
Getting permission of a group and all it parent groups
getUserGroupPermissions :: HasStorage m => UserImplId -> m [Permission] Source #
Get user permissions that are assigned to him/her via groups only
getUserAllPermissions :: HasStorage m => UserImplId -> m [Permission] Source #
Get user permissions that are assigned to him/her either by direct way or by his/her groups.
readUserGroup :: HasStorage m => UserGroupId -> m (Maybe UserGroup) Source #
Collect full info about user group from RDBMS
toAuthUserGroup :: UserGroup -> (AuthUserGroup, AuthUserGroupId -> [AuthUserGroupUsers], AuthUserGroupId -> [AuthUserGroupPerms]) Source #
Helper to convert user group into values of several tables
insertUserGroup :: HasStorage m => UserGroup -> m UserGroupId Source #
Insert user group into RDBMS
updateUserGroup :: HasStorage m => UserGroupId -> UserGroup -> m () Source #
Replace user group with new value
deleteUserGroup :: HasStorage m => UserGroupId -> m () Source #
Erase user group from RDBMS, cascade
patchUserGroup :: HasStorage m => UserGroupId -> PatchUserGroup -> m () Source #
Partial update of user group
Low-level
makeUserInfo :: HasStorage m => WithId UserImplId UserImpl -> m RespUserInfo Source #
Low level operation for collecting info about user