view src/register.html.luan @ 61:389e5d8e5f8a default tip

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Dec 2022 13:37:25 -0700
parents c57b84f461ae
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.header or error()
local footer = Shared.footer or error()
local base_url = Shared.base_url or error()
local call_mail_api = Shared.call_mail_api or error()
local Forum = require "site:/lib/Forum.luan"
local forum_title = Forum.title or error()
local User = require "site:/lib/User.luan"


local function page(contents)
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title><%=forum_title%> - Register</title>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Register</h1>
			<h3>Or Get or Change Password</h3>
<%
			contents()
%>
		</div>
<%		footer() %>
	</body>
</html>
<%
end

return function()
	local email = Http.request.parameters.email
	if email == nil then
		page(function()
%>
			<form>
				<p>
					<label>Email address</label>
					<input type="email" name="email" autofocus required>
				</p>
				<p><label clickable><input type=checkbox name=change> change password</label></p>
				<p><input type="submit"></p>
			</form>
<%
		end)
	else
		local change = Http.request.parameters.change ~= nil
		local user = User.get_or_create_by_email(email,change)
		local result = call_mail_api( "login_email", {
			base_url = base_url()
			from = forum_title.." <support@freedit.org>"
			email = user.email
			password = user.password
		} )
		result.okay or error(result.error)
		page(function()
%>
			<p>We have sent you an email.  Please check your email to login.</p>
<%
		end)
	end
end