Source file user.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
open Sihl_type

module type Sig = sig
  include Sihl_core.Container.Service.Sig

  val find_all : query:Database.Ql.t -> (User.t list * Database.Meta.t) Lwt.t
  val find_opt : user_id:string -> User.t option Lwt.t
  val find : user_id:string -> User.t Lwt.t
  val find_by_email : email:string -> User.t Lwt.t
  val find_by_email_opt : email:string -> User.t option Lwt.t

  val update_password
    :  ?password_policy:(string -> (unit, string) Result.t)
    -> user:User.t
    -> old_password:string
    -> new_password:string
    -> new_password_confirmation:string
    -> unit
    -> (User.t, string) Result.t Lwt.t

  val update_details
    :  user:User.t
    -> email:string
    -> username:string option
    -> User.t Lwt.t

  (** Set the password of a user without knowing the old password.

      This feature is typically used by admins. *)
  val set_password
    :  ?password_policy:(string -> (unit, string) Result.t)
    -> user:User.t
    -> password:string
    -> password_confirmation:string
    -> unit
    -> (User.t, string) Result.t Lwt.t

  (** Create and store a user. *)
  val create_user
    :  email:string
    -> password:string
    -> username:string option
    -> User.t Lwt.t

  (** Create and store a user that is also an admin. *)
  val create_admin
    :  email:string
    -> password:string
    -> username:string option
    -> User.t Lwt.t

  (** Create and store new user.

      Provide [password_policy] to check whether the password fulfills certain criteria. *)
  val register_user
    :  ?password_policy:(string -> (unit, string) result)
    -> ?username:string
    -> email:string
    -> password:string
    -> password_confirmation:string
    -> unit
    -> (User.t, User.Error.t) Result.t Lwt.t

  (** Find user by email if password matches. *)
  val login : email:string -> password:string -> (User.t, User.Error.t) Result.t Lwt.t

  val register : unit -> Sihl_core.Container.Service.t

  module Seed : sig
    val admin : email:string -> password:string -> User.t Lwt.t
    val user : email:string -> password:string -> ?username:string -> unit -> User.t Lwt.t
  end
end