annotate src/get_password.html.luan @ 6:a6be8817c05b

move mail_info to config
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 02 Jun 2022 19:18:12 -0600
parents dfc36e7ed22c
children 46f6b69e8b10
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
6
a6be8817c05b move mail_info to config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
16 local mail_info = config.mail_info or error "missing config.mail_info"
a6be8817c05b move mail_info to config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
17 local send_mail = Mail.sender(mail_info).send
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
19 local function handle(email)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 local change = Http.request.parameters.change ~= nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21 local password = config.users[email]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 if password == nil or change then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 password = new_password()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 raw_config.users[email] = password
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 local function body()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 Your password is "<%=password%>".
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32 end_function
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 send_mail{
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 From = "Mercurial Hosting <hg@reactionary.software>"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35 To = email
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 Subject = "Your Password"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 body = output_of(body)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 return nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 local function response(content)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 <title>Mercurial - Get Password</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
52 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
53 <h1>Get Password</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
54 <%=content%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
55 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
56 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
57 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
58 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
59 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
60
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
61 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
62 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
63 local email = Http.request.parameters.email
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
64 if email ~= nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
65 local error_msg = handle(email)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
66 if error_msg == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
67 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
68 else
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
69 response([[<p error>]]..error_msg..[[</p>]])
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
70 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
71 return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
72 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
73 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
74 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
75 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
76 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
77 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
78 <title>Mercurial - Get Password</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
79 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
80 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
81 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
82 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
83 <h1>Get Password</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
84
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
85 <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
86
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
87 <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
88
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
89 <hr>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
90 <form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
91 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
92 <label prompt>Your email address</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
93 <input type=email name=email required>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
94 <label prompt clickable><input type=checkbox name=change> change password</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
95 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
96 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
97 <input type=submit value="Get Password">
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
98 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
99 </form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
100 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
101 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
102 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
103 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
104 end