annotate src/register.html.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents c57b84f461ae
children
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() %>
55
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
23 <title><%=forum_title%> - Register</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>
55
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
28 <h1>Register</h1>
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
29 <h3>Or Get or Change Password</h3>
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 contents()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <% footer() %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 </body>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 </html>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 return function()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 local email = Http.request.parameters.email
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 if email == nil then
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 page(function()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <form>
55
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
46 <p>
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
47 <label>Email address</label>
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
48 <input type="email" name="email" autofocus required>
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
49 </p>
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
50 <p><label clickable><input type=checkbox name=change> change password</label></p>
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
51 <p><input type="submit"></p>
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 </form>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 end)
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
55 else
55
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
56 local change = Http.request.parameters.change ~= nil
c57b84f461ae login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents: 54
diff changeset
57 local user = User.get_or_create_by_email(email,change)
6
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
58 local result = call_mail_api( "login_email", {
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
59 base_url = base_url()
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
60 from = forum_title.." <support@freedit.org>"
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
61 email = user.email
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
62 password = user.password
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
63 } )
9166f6a14021 add email api
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
64 result.okay or error(result.error)
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 page(function()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 %>
54
260abd8f8565 login and register
Franklin Schmidt <fschmidt@gmail.com>
parents: 29
diff changeset
67 <p>We have sent you an email. Please check your email to login.</p>
3
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 end)
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 end