-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.ur
30 lines (25 loc) · 1017 Bytes
/
api.ur
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
val textMime = blessMime "text/plain"
fun ok [t ::: Type] (message : string) : transaction t = returnBlob (textBlob ("OK\n" ^ message)) textMime
fun fail [t ::: Type] (message : string) : transaction t = returnBlob (textBlob ("FAIL\n" ^ message)) textMime
fun addAccount (r : {Email : string, Username : string, Password : string}) : transaction page =
case StringTypes.fromString r.Email of
None => fail ("INVALID EMAIL: " ^ r.Email)
| Some email => success <- MailAuth.newAccount r.Username r.Password email;
if success then
ok ""
else
fail ""
fun apiLogin r : transaction page =
maybeUser <- MailAuth.signIn r.Username r.Password;
case maybeUser of
None => fail ""
| Some u => tokenOut <- MailAuth.newToken u;
ok (show tokenOut)
fun apiTestToken r : transaction page =
case (MailAuth.readToken r.Token) of
None => fail "Bad token!"
| Some token =>
maybeUser <- MailAuth.loadUser token;
case maybeUser of
None => fail ""
| Some _ => ok ""