view src/new_thread.html.luan @ 55:c57b84f461ae

login and registration work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 28 Nov 2022 20:33:47 -0700
parents 9f8ebc757814
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 Forum = require "site:/lib/Forum.luan"
local forum_title = Forum.title or error()
local Post = require "site:/lib/Post.luan"
local User = require "site:/lib/User.luan"
local Bbcode = require "site:/bbcode/Bbcode.luan"
local preprocess = Bbcode.preprocess or error()


return function()
	local user = User.current_required()
	if user==nil then return end
	if Http.request.method == "POST" then
		local subject = Http.request.parameters.subject or error()
		local content = Http.request.parameters.bbcode or error()
		local convert_urls = Http.request.parameters.convert_urls or error()
		if convert_urls == "true" then
			content = preprocess(content)
		end
		local post = Post.new_thread(user,subject,content)
		Http.response.send_redirect("/thread.html?root="..post.id)
		return
	end
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title><%=forum_title%>: new thread</title>
		<style>
			@import "/bbcode/bbcode.css";
		</style>
	<body>
<%		header() %>
		<div content>
			<h1>New Thread</h1>
			<form method=post>
				<p>
					<label>Subject</label>
					<input name=subject required>
				</p>
				<p editor></p>
				<p><input type=submit></p>
			</form>
		</div>
<%		footer() %>
	</body>
	<script>
		bbcodeCreate('p[editor]');
	</script>
</html>
<%
end