annotate src/get_password.html.luan @ 0:dfc36e7ed22c

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