comparison 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
comparison
equal deleted inserted replaced
53:cac477dd1f82 54:260abd8f8565
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local Io = require "luan:Io.luan"
4 local Http = require "luan:http/Http.luan"
5 local Shared = require "site:/lib/Shared.luan"
6 local head = Shared.head or error()
7 local header = Shared.header or error()
8 local footer = Shared.footer or error()
9 local base_url = Shared.base_url or error()
10 local call_mail_api = Shared.call_mail_api or error()
11 local Forum = require "site:/lib/Forum.luan"
12 local forum_title = Forum.title or error()
13 local User = require "site:/lib/User.luan"
14
15
16 local function page(contents)
17 Io.stdout = Http.response.text_writer()
18 %>
19 <!doctype html>
20 <html>
21 <head>
22 <% head() %>
23 <title><%=forum_title%> - Register or Get Password</title>
24 </head>
25 <body>
26 <% header() %>
27 <div content>
28 <h1>Register or Get Password</h1>
29 <%
30 contents()
31 %>
32 </div>
33 <% footer() %>
34 </body>
35 </html>
36 <%
37 end
38
39 return function()
40 local email = Http.request.parameters.email
41 if email == nil then
42 page(function()
43 %>
44 <form>
45 <label>Email address</label>
46 <input type="email" name="email" autofocus required>
47 <input type="submit" value="Register or Get Password">
48 </form>
49 <%
50 end)
51 else
52 local user = User.get_or_create_by_email(email)
53 local result = call_mail_api( "login_email", {
54 base_url = base_url()
55 from = forum_title.." <support@freedit.org>"
56 email = user.email
57 password = user.password
58 } )
59 result.okay or error(result.error)
60 page(function()
61 %>
62 <p>We have sent you an email. Please check your email to login.</p>
63 <%
64 end)
65 end
66 end