3
|
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()
|
6
|
10 local call_mail_api = Shared.call_mail_api or error()
|
3
|
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() %>
|
54
|
23 <title><%=forum_title%> - Register or Get Password</title>
|
3
|
24 </head>
|
|
25 <body>
|
|
26 <% header() %>
|
|
27 <div content>
|
54
|
28 <h1>Register or Get Password</h1>
|
3
|
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>
|
54
|
47 <input type="submit" value="Register or Get Password">
|
3
|
48 </form>
|
|
49 <%
|
|
50 end)
|
54
|
51 else
|
3
|
52 local user = User.get_or_create_by_email(email)
|
6
|
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)
|
3
|
60 page(function()
|
|
61 %>
|
54
|
62 <p>We have sent you an email. Please check your email to login.</p>
|
3
|
63 <%
|
|
64 end)
|
|
65 end
|
|
66 end
|