annotate src/get_password.html.luan @ 17:3e8c7d089e30

URL update
author Vadim Filimonov <fffilimonov@yandex.ru>
date Mon, 02 Oct 2023 12:23:02 +0300
parents a6e72cd199f1
children b14073ab9d07
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
15
a6e72cd199f1 email security
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
3 local String = require "luan:String.luan"
a6e72cd199f1 email security
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
4 local matches = String.matches or error()
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local output_of = Io.output_of or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local Mail = require "luan:mail/Mail.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10 local head = Shared.head or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 local header = Shared.header or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12 local config = Shared.config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13 local new_password = Shared.new_password or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
14 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
16
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17
7
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
18 local send_mail = config.mail_info and Mail.sender(config.mail_info).send
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
19
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 local function handle(email)
15
a6e72cd199f1 email security
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
21 matches( email, [[^(\w[-+~.\w]*)@[-\w]+(\\.[-\w]+)*\.[a-zA-Z]+$]] ) or error "invalid email"
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 local change = Http.request.parameters.change ~= nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 local password = config.users[email]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 if password == nil or change then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 password = new_password()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 raw_config.users[email] = password
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 end
7
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
30 if send_mail == nil then
46f6b69e8b10 better handling of missing mail_info
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
31 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
32 end
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 local function body()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35 Your password is "<%=password%>".
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 end_function
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 send_mail{
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 From = "Mercurial Hosting <hg@reactionary.software>"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40 To = email
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41 Subject = "Your Password"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 body = output_of(body)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 return nil
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 local function response(content)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
52 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
53 <title>Mercurial - Get Password</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
54 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
55 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
56 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
57 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
58 <h1>Get Password</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
59 <%=content%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
60 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
61 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
62 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
63 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
64 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
65
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
66 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
67 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
68 local email = Http.request.parameters.email
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
69 if email ~= nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
70 local error_msg = handle(email)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
71 if error_msg == nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
72 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
73 else
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
74 response([[<p error>]]..error_msg..[[</p>]])
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
75 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
76 return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
77 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
78 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
79 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
80 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
81 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
82 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
83 <title>Mercurial - Get Password</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
84 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
85 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
86 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
87 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
88 <h1>Get Password</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
89
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
90 <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
91
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
92 <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
93
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
94 <hr>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
95 <form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
96 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
97 <label prompt>Your email address</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
98 <input type=email name=email required>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
99 <label prompt clickable><input type=checkbox name=change> change password</label>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
100 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
101 <p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
102 <input type=submit value="Get Password">
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
103 </p>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
104 </form>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
105 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
106 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
107 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
108 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
109 end