Mercurial Hosting > hghosting
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 |
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 | |
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 | 18 |
19 local function handle(email) | |
20 local change = Http.request.parameters.change ~= nil | |
21 local password = config.users[email] | |
22 if password == nil or change then | |
23 password = new_password() | |
24 local raw_config = get_raw_config() | |
25 raw_config.users[email] = password | |
26 save_raw_config(raw_config) | |
27 end | |
28 local function body() | |
29 %> | |
30 Your password is "<%=password%>". | |
31 <% | |
32 end_function | |
33 send_mail{ | |
34 From = "Mercurial Hosting <hg@reactionary.software>" | |
35 To = email | |
36 Subject = "Your Password" | |
37 body = output_of(body) | |
38 } | |
39 return nil | |
40 end | |
41 | |
42 local function response(content) | |
43 %> | |
44 <!doctype html> | |
45 <html> | |
46 <head> | |
47 <% head() %> | |
48 <title>Mercurial - Get Password</title> | |
49 </head> | |
50 <body> | |
51 <% header() %> | |
52 <div content> | |
53 <h1>Get Password</h1> | |
54 <%=content%> | |
55 </div> | |
56 </body> | |
57 </html> | |
58 <% | |
59 end | |
60 | |
61 return function() | |
62 Io.stdout = Http.response.text_writer() | |
63 local email = Http.request.parameters.email | |
64 if email ~= nil then | |
65 local error_msg = handle(email) | |
66 if error_msg == nil then | |
67 response([[<p>Your password has been emailed to <b>]]..email..[[</b>. Use your email and password for authentication.</p>]]) | |
68 else | |
69 response([[<p error>]]..error_msg..[[</p>]]) | |
70 end | |
71 return | |
72 end | |
73 %> | |
74 <!doctype html> | |
75 <html> | |
76 <head> | |
77 <% head() %> | |
78 <title>Mercurial - Get Password</title> | |
79 </head> | |
80 <body> | |
81 <% header() %> | |
82 <div content> | |
83 <h1>Get Password</h1> | |
84 | |
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> | |
86 | |
87 <p>This page is used to register, to get your password if you forgot it, or to change your password.</p> | |
88 | |
89 <hr> | |
90 <form> | |
91 <p> | |
92 <label prompt>Your email address</label> | |
93 <input type=email name=email required> | |
94 <label prompt clickable><input type=checkbox name=change> change password</label> | |
95 </p> | |
96 <p> | |
97 <input type=submit value="Get Password"> | |
98 </p> | |
99 </form> | |
100 </div> | |
101 </body> | |
102 </html> | |
103 <% | |
104 end |