-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
SignIn.mint
48 lines (40 loc) · 978 Bytes
/
SignIn.mint
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
store Forms.SignIn {
state status : Api.Status(User) = Api.Status::Initial
state password : String = ""
state email : String = ""
fun setPassword (value : String) : Promise(Never, Void) {
next { password = value }
}
fun setEmail (value : String) : Promise(Never, Void) {
next { email = value }
}
fun reset : Promise(Never, Void) {
next
{
status = Api.Status::Initial,
password = "",
email = ""
}
}
fun submit : Promise(Never, Void) {
sequence {
next { status = Api.Status::Loading }
body =
encode {
user =
{
password = password,
email = email
}
}
newStatus =
Http.post("/users/login")
|> Http.jsonBody(body)
|> Api.send(User.fromResponse)
case (newStatus) {
Api.Status::Ok user => Application.login(user)
=> next { status = newStatus }
}
}
}
}