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