view src/login.js.luan @ 88:7b339b1ccd11

add tools/users.html
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 16:18:39 -0600
parents a47036fd0158
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local Html = require "luan:Html.luan"
local url_encode = Html.url_encode or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local send_mail_async = Shared.send_mail_async or error()
local Utils = require "site:/lib/Utils.luan"
local to_list = Utils.to_list or error()
local User = require "site:/lib/User.luan"


return function()
	local email = Http.request.parameters.email or error()
	local user = User.get_or_create_by_email(email)
	local url = user.login_url()
	local with = Http.request.parameters.with
	with = to_list(with)
	for _, email in ipairs(with) do
		url = url.."&with="..url_encode(email)
	end
	send_mail_async {
		To = email
		Subject = "Login"
		body = `%>
Here is the link to login:

<%= url %>

Or login with your email and the password: <%=user.password%>
<%		`
	}
	Io.stdout = Http.response.text_writer()
%>
	location = '/login_sent.html';
<%
end