annotate src/register.html.luan @ 54:260abd8f8565

login and register
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 27 Nov 2022 23:46:27 -0700
parents src/login.html.luan@a1db5223ced1
children c57b84f461ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local header = Shared.header or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local footer = Shared.footer or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local base_url = Shared.base_url or error()
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
10 local call_mail_api = Shared.call_mail_api or error()
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Forum = require "site:/lib/Forum.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local forum_title = Forum.title or error()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local User = require "site:/lib/User.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local function page(contents)
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 Io.stdout = Http.response.text_writer()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <!doctype html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 <html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 <head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <% head() %>
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
23 <title><%=forum_title%> - Register or Get Password</title>
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 </head>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 <% header() %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 <div content>
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
28 <h1>Register or Get Password</h1>
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 contents()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <% footer() %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 </body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 </html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 return function()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 local email = Http.request.parameters.email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 if email == nil then
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 page(function()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <form>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <label>Email address</label>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <input type="email" name="email" autofocus required>
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
47 <input type="submit" value="Register or Get Password">
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 </form>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 end)
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
51 else
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 local user = User.get_or_create_by_email(email)
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
53 local result = call_mail_api( "login_email", {
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
54 base_url = base_url()
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
55 from = forum_title.." <support@freedit.org>"
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
56 email = user.email
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
57 password = user.password
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
58 } )
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
59 result.okay or error(result.error)
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 page(function()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 %>
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
62 <p>We have sent you an email. Please check your email to login.</p>
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 end)
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 end