Db.UserSourceThis module is used for low-level user management with database.
userid_of_email email returns the userid of the user which has the email email.
is_registered email returns true if the email is already registered. Else, it returns false.
is_email_validated userid email returns true if email has been validated by the user with id userid.
set_email_validated userid email valids email for the user with id userid.
val add_actionlinkkey :
?autoconnect:bool ->
?action:
[< `AccountActivation
| `Custom of string
| `PasswordReset AccountActivation ] ->
?data:string ->
?validity:int64 ->
?expiry:CalendarLib.Calendar.t ->
act_key:string ->
userid:Types.User.id ->
email:string ->
unit ->
unit Lwt.tadd_preregister email preregisters email in the database.
remove_preregister email removes email from the database.
is_preregistered email returns true if email is already registered. Else, it returns false.
all ?limit () get all email addresses with a limit of limit (default is 10).
val create :
?password:string ->
?avatar:string ->
?language:string ->
?email:string ->
firstname:string ->
lastname:string ->
unit ->
Types.User.id Lwt.tcreate ?password ?avatar ?language ~firstname ~lastname email creates a new user in the database and returns the userid of the new user. Email, first name, last name and language are mandatory to create a new user. If password is passed as an empty string, it fails with the message "empty password". TODO: change it to an exception?
val update :
?password:string ->
?avatar:string ->
?language:string ->
firstname:string ->
lastname:string ->
Types.User.id ->
unit Lwt.tupdate ?password ?avatar ?language ~firstname ~lastname userid updates the user profile with userid. If password is passed as an empty string, it fails with the message "empty password". TODO: change it to an exception?
update_password ~userid ~new_password updates the password of the user with ID userid. If password is passed as an empty string, it fails with the message "empty password". TODO: change it to an exception?
update_avatar ~userid ~avatar updates the avatar of the user with ID userid.
update_main_email ~userid ~email updates the main email of the user with ID userid.
update_language ~userid ~language updates the language of the user with ID userid.
verify_password ~email ~password returns the userid if user with email email is registered with the password password. If password the password is wrong, it fails with exception Wrong_password. If user exists but account is not validated, it fails with exception Account_not_activated. If user has no password, it fails with exception Password_not_set. If user is not found, it fails with exception No_such_user. If password is empty, it fails with exception Empty_password.
verify_password_phone ~number ~password returns the userid if user who owns number and whose password is password. If password the password is wrong, it fails with exception Wrong_password. If user has no password, it fails with exception Password_not_set. If user is not found, it fails with exception No_such_user. If password is empty, it fails with exception Empty_password.
val user_of_userid :
Types.User.id ->
(Types.User.id * string * string * string option * bool * string option)
Lwt.tuser_of_userid userid returns a tuple (userid, firstname, lastname, avatar, bool_password, language) describing the information about the user with ID userid. bool_password is a boolean. Its value is true if a password has been set. Else false. If there is no such user, it fails with No_such_resource.
get_actionlinkkey_info key returns the information about the action link key as a type Types.Action_link_key.info.
emails_of_userid userid returns all emails registered for the user with ID userid. If there is no user with userid as ID, it fails with No_such_resource.
Like emails_of_userid, but also returns validation status. This way we perform fewer DB queries.
email_of_userid userid returns the main email registered for the user with ID userid. If there is no such user, it fails with No_such_resource.
is_main_email ~email ~userid returns true if the main email of the user with ID userid is email. If there is no such user or if email is not the main email, it returns false.
add_email_to_user ~userid ~email add email to user with ID userid.
remove_email_from_user ~userid ~email removes the email email from the emails list of user with ID userid. If email is the main email, it fails with Main_email_removal_attempt.
get_language userid returns the language of the user with ID userid
val get_users :
?pattern:string ->
unit ->
(Types.User.id * string * string * string option * bool * string option) list
Lwt.tget_users ~pattern () returns all users matching the pattern pattern as a tuple (userid, firstname, lastname, avatar, bool_password, language).