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