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