view src/do_login.html.luan @ 89:3053a4fc10be

spy
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Mar 2025 17:56:39 -0600
parents a47036fd0158
children 8c3b56bb0c83
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local Table = require "luan:Table.luan"
local concat = Table.concat 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 head = Shared.head or error()
local header = Shared.header or error()
local User = require "site:/lib/User.luan"
local Utils = require "site:/lib/Utils.luan"
local to_list = Utils.to_list or error()


return function()
	local user_id = Http.request.parameters.user or error()
	local password = Http.request.parameters.password or error()
	local user = User.get_by_id(user_id)
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Login / Register</h1>
<%	if user == nil or user.password ~= password then %>
			<p>Login failed</p>
<%
	else
		user.login()
		local spy = Http.request.parameters.spy ~= nil
		if spy then
			Http.response.set_cookie("spy","yes")
		else
			Http.response.remove_cookie("spy")
		end
		local with = Http.request.parameters.with
		local location
		if with == nil then
			location = "/"
		else
			with = to_list(with)
			local t = {}
			for _, email in ipairs(with) do
				t[#t+1] = "with="..url_encode(email)
			end
			location = "/chat?"..concat(t,"&")
		end
%>
			<script> location = '<%=location%>'; </script>
<%
	end
%>
		</div>
	</body>
</html>
<%
end