diff src/register.html.luan @ 54:260abd8f8565

login and register
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 27 Nov 2022 23:46:27 -0700
parents src/login.html.luan@a1db5223ced1
children c57b84f461ae
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/register.html.luan	Sun Nov 27 23:46:27 2022 -0700
@@ -0,0 +1,66 @@
+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 or Get Password</title>
+	</head>
+	<body>
+<%		header() %>
+		<div content>
+			<h1>Register or Get Password</h1>
+<%
+			contents()
+%>
+		</div>
+<%		footer() %>
+	</body>
+</html>
+<%
+end
+
+return function()
+	local email = Http.request.parameters.email
+	if email == nil then
+		page(function()
+%>
+			<form>
+				<label>Email address</label>
+				<input type="email" name="email" autofocus required>
+				<input type="submit" value="Register or Get Password">
+			</form>
+<%
+		end)
+	else
+		local user = User.get_or_create_by_email(email)
+		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