Module type Sihl_user.Sig
module Web : sig ... end
val search : ?ctx:(string * string) list -> ?sort:[ `Desc | `Asc ] -> ?filter:string -> ?limit:int -> ?offset:int -> unit -> (t list * int) Lwt.t
search ?ctx ?sort ?filter ?limit ?offset ()
returns a list of users that is a partial view on all stored users.sort
is the default sorting order of the created date. By default, this value is`Desc
.filter
is a search keyword that is applied in a best-effort way on user details. The keyword has to occur in only one field (such as email).limit
is the length of the returned list.offset
is the pagination offset of the partial view.
val find_opt : ?ctx:(string * string) list -> string -> t option Lwt.t
find_opt ?ctx id
returns a user withid
.
val find : ?ctx:(string * string) list -> string -> t Lwt.t
find ?ctx id
returns a user withid
,None
otherwise.
val find_by_email : ?ctx:(string * string) list -> string -> t Lwt.t
find_by_email ?ctx email
returns aUser.t
if there is a user with email addressemail
. The lookup is case-insensitive. Raises an{!Exception}
otherwise.
val find_by_email_opt : ?ctx:(string * string) list -> string -> t option Lwt.t
find_by_email_opt ?ctx email
returns aUser.t
if there is a user with email addressemail
.
val update_password : ?ctx:(string * string) list -> ?password_policy:(string -> (unit, string) Result.t) -> t -> old_password:string -> new_password:string -> new_password_confirmation:string -> (t, string) Result.t Lwt.t
update_password ?ctx ?password_policy user ~old_password ~new_password ~new_password_confirmation
updates the password of auser
tonew_password
and returns the user. Theold_password
is the current password that the user has to enter.new_password
has to equalnew_password_confirmation
.password_policy
is a function that validates thenew_password
based on some password policy. By default, the policy is that a password has to be at least 8 characters long.
val update : ?ctx:(string * string) list -> ?email:string -> ?username:string -> ?name:string -> ?given_name:string -> ?status:status -> t -> t Lwt.t
update ?ctx?email ?username ?name ?given_name ?status user
stores the updateduser
and returns it.
val update_details : user:t -> email:string -> username:string option -> t Lwt.t
val set_password : ?ctx:(string * string) list -> ?password_policy:(string -> (unit, string) Result.t) -> t -> password:string -> password_confirmation:string -> (t, string) Result.t Lwt.t
set_password ?ctx ?policy user ~password ~password_confirmation
overrides the current password of auser
and returns that user.password
has to equalpassword_confirmation
.password_policy
is a function that validates thenew_password
based on some password policy. By default, the policy is that a password has to be at least 8 characters long.The current password doesn't have to be provided, therefore you should not expose this function to users but only admins. If you want the user to update their own password use
update_password
instead.
val create_user : ?ctx:(string * string) list -> ?username:string -> ?name:string -> ?given_name:string -> password:string -> string -> t Lwt.t
create_user ?ctx ?username ?name ?given_name email password
returns a non-admin user. Note that usingcreate_user
skips the registration workflow and should only be used with care.
val create_admin : ?ctx:(string * string) list -> ?username:string -> ?name:string -> ?given_name:string -> password:string -> string -> t Lwt.t
create_admin ?ctx ?username ?name ?given_name email password
returns an admin user.
val register_user : ?ctx:(string * string) list -> ?password_policy:(string -> (unit, string) Stdlib.result) -> ?username:string -> ?name:string -> ?given_name:string -> string -> password:string -> password_confirmation:string -> (t, [ `Already_registered | `Invalid_password_provided of string ]) Result.t Lwt.t
register_user ?ctx ?password_policy ?username ?name ?given_name email password password_confirmation
creates a new user if the password is valid and if the email address was not already registered.Provide
password_policy
to check whether the password fulfills certain criteria.
val login : ?ctx:(string * string) list -> string -> password:string -> (t, [ `Does_not_exist | `Incorrect_password ]) Result.t Lwt.t
login ?ctx email ~password
returns the user associated withemail
ifpassword
matches the current password.
val register : unit -> Sihl__.Core_container.Service.t
include Sihl__.Core_container.Service.Sig
val lifecycle : Sihl__.Core_lifecycle.lifecycle