view src/lib/Shared.luan @ 2:ee1f91e67509

add Db
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 24 Oct 2024 15:37:35 -0600
parents b116b6ef07bf
children 2c63b10781e1
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs or error()
local parse = Luan.parse or error()
local Io = require "luan:Io.luan"
local uri = Io.uri or error()
local User = require "site:/lib/User.luan"
local current_user = User.current or error()


local Shared = {}

function Shared.head()
%>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<style>
			@import "/site.css";
		</style>
<%
end

local function header(crumbs)
	local user = current_user()
%>
		<div header>
			<span>
				<a href="/">Web Chat</a>
<%	for _, crumb in ipairs(crumbs or {}) do %>
				/ <%=crumb%>
<%	end %>
			</span>
			<span>
<%	if user == nil then %>
				<a href="/login.html">Login / Register</a>
<%	else %>
				<a href="/account.html"><%= user.email %></a>
<%	end %>
			</span>
		</div>
<%
end
Shared.header = header

function Shared.private_header()
	header{
		[[<a href="/private/">private</a>]]
		[[<a href="/private/tools/">tools</a>]]
	}
end

local config_file = uri("site:/private/local/config.luano")
Shared.config_file = config_file

do
	if config_file.exists() then
		Shared.config = parse( config_file.read_text() )
	else
		Shared.config = {
			mail_server = {
				host = "smtpcorp.com"
				port = 465
				username = "xxx"
				password = "xxx"
			}
		}
	end
end

return Shared