Mercurial Hosting > hghosting
view src/get_password.html.luan @ 4:028e74c8889d
add all_users
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 12 May 2022 16:54:11 -0600 |
parents | dfc36e7ed22c |
children | a6be8817c05b |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local Io = require "luan:Io.luan" local output_of = Io.output_of or error() local Http = require "luan:http/Http.luan" local Mail = require "luan:mail/Mail.luan" local Shared = require "site:/lib/Shared.luan" local head = Shared.head or error() local header = Shared.header or error() local config = Shared.config or error() local new_password = Shared.new_password or error() local get_raw_config = Shared.get_raw_config or error() local save_raw_config = Shared.save_raw_config or error() local send_mail = Mail.sender{ host = "smtpcorp.com" username = "smtp@luan.software" password = "luanhost" port = 2525 }.send local function handle(email) local change = Http.request.parameters.change ~= nil local password = config.users[email] if password == nil or change then password = new_password() local raw_config = get_raw_config() raw_config.users[email] = password save_raw_config(raw_config) end local function body() %> Your password is "<%=password%>". <% end_function send_mail{ From = "Mercurial Hosting <hg@reactionary.software>" To = email Subject = "Your Password" body = output_of(body) } return nil end local function response(content) %> <!doctype html> <html> <head> <% head() %> <title>Mercurial - Get Password</title> </head> <body> <% header() %> <div content> <h1>Get Password</h1> <%=content%> </div> </body> </html> <% end return function() Io.stdout = Http.response.text_writer() local email = Http.request.parameters.email if email ~= nil then local error_msg = handle(email) if error_msg == nil then response([[<p>Your password has been emailed to <b>]]..email..[[</b>. Use your email and password for authentication.</p>]]) else response([[<p error>]]..error_msg..[[</p>]]) end return end %> <!doctype html> <html> <head> <% head() %> <title>Mercurial - Get Password</title> </head> <body> <% header() %> <div content> <h1>Get Password</h1> <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> <p>This page is used to register, to get your password if you forgot it, or to change your password.</p> <hr> <form> <p> <label prompt>Your email address</label> <input type=email name=email required> <label prompt clickable><input type=checkbox name=change> change password</label> </p> <p> <input type=submit value="Get Password"> </p> </form> </div> </body> </html> <% end