local Luan = require "luan:Luan.luan" local error = Luan.error local String = require "luan:String.luan" 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 = config.mail_info and Mail.sender(config.mail_info).send local email_regex = String.regex[[^(\w[-+~.\w]*)@[-\w]+(\\.[-\w]+)*\.[a-zA-Z]+$]] local function handle(email) email_regex.matches(email) or error "invalid 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 if send_mail == nil then return "missing config.mail_info, your password is: "..password end local function body() %> Your password is "<%=password%>". <% end_function send_mail{ From = "Mercurial Hosting " To = email Subject = "Your Password" body = output_of(body) } return nil end local function response(content) %> <% head() %> Mercurial - Get Password <% header() %>

Get Password

<%=content%>
<% 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([[

Your password has been emailed to ]]..email..[[. Use your email and password for authentication.

]]) else response([[

]]..error_msg..[[

]]) end return end %> <% head() %> Mercurial - Get Password <% header() %>

Get Password

This site uses authentication for access. For authentication, your email address is your user name, and your password will be emailed to you.

This page is used to register, to get your password if you forgot it, or to change your password.


<% end