view src/private/tools/configure_mail.html.luan @ 16:50a1fe272c10

more security
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 01 Oct 2023 21:36:34 -0600
parents a6be8817c05b
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local stringify = Luan.stringify or error()
local parse = Luan.parse 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.private_header or error()
local config = Shared.config or error()
local get_raw_config = Shared.get_raw_config or error()
local save_raw_config = Shared.save_raw_config or error()


local function posted()
	local mail_info = Http.request.parameters.mail_info or error()
	mail_info = parse(mail_info)
	local raw_config = get_raw_config()
	raw_config.mail_info = mail_info
	save_raw_config(raw_config)
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title>Mercurial Configure Email</title>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Configure Email</h1>
			<p>Updated</p>
		</div>
	</body>
</html>
<%
end

return function()
	local mail_info = stringify(config.mail_info or {
		host = "smtpcorp.com"
		username = "xxx"
		password = "xxx"
		port = 2525
	})
	Io.stdout = Http.response.text_writer()
	if Http.request.method == "POST" then
		posted()
		return
	end
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title>Mercurial Configure Email</title>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Configure Email</h1>
			<form method=post>
				<p>
					<textarea name=mail_info rows=6 cols=40><%=mail_info%></textarea>
				</p>
				<p>
					<input type=submit value="Update">
				</p>
			</form>
		</div>
	</body>
</html>
<%
end