annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
1
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
4 local parse = Luan.parse or error()
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
5 local Io = require "luan:Io.luan"
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
6 local uri = Io.uri or error()
2
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
7 local User = require "site:/lib/User.luan"
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
8 local current_user = User.current or error()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Shared = {}
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 function Shared.head()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 <meta name="viewport" content="width=device-width, initial-scale=1">
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 <style>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 @import "/site.css";
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 </style>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 local function header(crumbs)
2
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
23 local user = current_user()
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 %>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 <div header>
2
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
26 <span>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
27 <a href="/">Web Chat</a>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <% for _, crumb in ipairs(crumbs or {}) do %>
2
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
29 / <%=crumb%>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <% end %>
2
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
31 </span>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
32 <span>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
33 <% if user == nil then %>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
34 <a href="/login.html">Login / Register</a>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
35 <% else %>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
36 <a href="/account.html"><%= user.email %></a>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
37 <% end %>
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
38 </span>
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 </div>
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <%
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 Shared.header = header
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 function Shared.private_header()
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 header{
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 [[<a href="/private/">private</a>]]
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 [[<a href="/private/tools/">tools</a>]]
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 }
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 end
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50
1
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
51 local config_file = uri("site:/private/local/config.luano")
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
52 Shared.config_file = config_file
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
53
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
54 do
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
55 if config_file.exists() then
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
56 Shared.config = parse( config_file.read_text() )
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
57 else
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
58 Shared.config = {
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
59 mail_server = {
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
60 host = "smtpcorp.com"
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
61 port = 465
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
62 username = "xxx"
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
63 password = "xxx"
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
64 }
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
65 }
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
66 end
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
67 end
b116b6ef07bf add config
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
68
0
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 return Shared