annotate src/get_password.html.luan @ 7:46f6b69e8b10

better handling of missing mail_info
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 03 Jun 2022 09:57:45 -0600
parents a6be8817c05b
children a6e72cd199f1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
2 local error = Luan.error
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
4 local output_of = Io.output_of or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local Mail = require "luan:mail/Mail.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local head = Shared.head or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9 local header = Shared.header or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10 local config = Shared.config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 local new_password = Shared.new_password or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
14
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15
7
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
16 local send_mail = config.mail_info and Mail.sender(config.mail_info).send
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18 local function handle(email)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
19 local change = Http.request.parameters.change ~= nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 local password = config.users[email]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21 if password == nil or change then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 password = new_password()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 raw_config.users[email] = password
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 end
7
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
27 if send_mail == nil then
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
28 return "missing config.mail_info, your password is: "..password
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
29 end
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 local function body()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32 Your password is "<%=password%>".
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 end_function
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35 send_mail{
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 From = "Mercurial Hosting <hg@reactionary.software>"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 To = email
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 Subject = "Your Password"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 body = output_of(body)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41 return nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 local function response(content)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 <title>Mercurial - Get Password</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
52 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
53 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
54 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
55 <h1>Get Password</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
56 <%=content%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
57 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
58 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
59 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
60 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
61 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
62
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
63 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
64 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
65 local email = Http.request.parameters.email
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
66 if email ~= nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
67 local error_msg = handle(email)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
68 if error_msg == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
69 response([[<p>Your password has been emailed to <b>]]..email..[[</b>. Use your email and password for authentication.</p>]])
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
70 else
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
71 response([[<p error>]]..error_msg..[[</p>]])
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
72 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
73 return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
74 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
75 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
76 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
77 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
78 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
79 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
80 <title>Mercurial - Get Password</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
81 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
82 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
83 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
84 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
85 <h1>Get Password</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
86
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
87 <p>This site uses authentication for access. For authentication, your email address is your user name, and your password will be emailed to you.</p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
88
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
89 <p>This page is used to register, to get your password if you forgot it, or to change your password.</p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
90
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
91 <hr>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
92 <form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
93 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
94 <label prompt>Your email address</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
95 <input type=email name=email required>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
96 <label prompt clickable><input type=checkbox name=change> change password</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
97 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
98 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
99 <input type=submit value="Get Password">
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
100 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
101 </form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
102 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
103 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
104 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
105 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
106 end