0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
13
|
3 local ipairs = Luan.ipairs or error()
|
|
4 local set_metatable = Luan.set_metatable or error()
|
3
|
5 local Http = require "luan:http/Http.luan"
|
6
|
6 local Io = require "luan:Io.luan"
|
|
7 local uri = Io.uri or error()
|
|
8 local Parsers = require "luan:Parsers.luan"
|
|
9 local json_parse = Parsers.json_parse or error()
|
0
|
10 local Forum = require "site:/lib/Forum.luan"
|
6
|
11 local forum_title = Forum.title or error()
|
|
12 local mailer_url = Forum.mailer_url or error()
|
3
|
13 local User = require "site:/lib/User.luan"
|
|
14 local Logging = require "luan:logging/Logging.luan"
|
|
15 local logger = Logging.logger "Shared"
|
0
|
16
|
|
17
|
|
18 local Shared = {}
|
|
19
|
|
20 function Shared.head()
|
|
21 %>
|
|
22 <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
23 <style>
|
|
24 @import "/site.css";
|
|
25 </style>
|
7
|
26 <script src="/site.js"></script>
|
0
|
27 <%
|
|
28 end
|
|
29
|
|
30 function Shared.header()
|
3
|
31 local user = User.current()
|
0
|
32 %>
|
7
|
33 <p style="text-align:center">Yes the aesthetics suck. Will be fixed later.</p>
|
0
|
34 <div header>
|
6
|
35 <a href="/"><%=forum_title%></a>
|
3
|
36 <% if user == nil then %>
|
|
37 <a href="/login.html">login</a>
|
|
38 <% else %>
|
|
39 <a href="/account.html"><%=user.name_html%></a>
|
|
40 <% end %>
|
0
|
41 </div>
|
|
42 <%
|
|
43 end
|
|
44
|
|
45 function Shared.footer()
|
|
46 %>
|
|
47 <div footer>
|
|
48 <a href="/config.html">Configuration</a>
|
|
49 </div>
|
|
50 <%
|
|
51 end
|
|
52
|
4
|
53 function Shared.admin_header()
|
|
54 %>
|
|
55 <div header>
|
|
56 <a href="/private/admin.html">Admin</a>
|
|
57 </div>
|
|
58 <%
|
|
59 end
|
|
60
|
3
|
61 function Shared.base_url()
|
|
62 return Http.request.scheme.."://"..Http.request.headers["host"]
|
|
63 end
|
|
64
|
6
|
65 function Shared.call_mail_api(cmd,parameters)
|
|
66 local url = mailer_url.."/api/"..cmd..".json"
|
|
67 local options = {
|
|
68 parameters = parameters
|
|
69 }
|
|
70 local response = uri(url,options).read_text()
|
|
71 return json_parse(response)
|
|
72 end
|
|
73
|
13
|
74 local set_mt = {}
|
|
75 function set_mt.__index(table,key)
|
|
76 return false
|
|
77 end
|
|
78
|
|
79 function Shared.list_to_set(list)
|
|
80 local set = {}
|
|
81 for _, v in ipairs(list) do
|
|
82 set[v] = true
|
|
83 end
|
|
84 set_metatable(set,set_mt)
|
|
85 return set
|
|
86 end
|
|
87
|
0
|
88 return Shared
|