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>
|
|
24 <%
|
|
25 end
|
|
26
|
|
27 function Shared.header()
|
3
|
28 local user = User.current()
|
0
|
29 %>
|
|
30 <div header>
|
6
|
31 <a href="/"><%=forum_title%></a>
|
3
|
32 <% if user == nil then %>
|
|
33 <a href="/login.html">login</a>
|
|
34 <% else %>
|
|
35 <a href="/account.html"><%=user.name_html%></a>
|
|
36 <% end %>
|
0
|
37 </div>
|
|
38 <%
|
|
39 end
|
|
40
|
|
41 function Shared.footer()
|
|
42 %>
|
|
43 <div footer>
|
|
44 <a href="/config.html">Configuration</a>
|
|
45 </div>
|
|
46 <%
|
|
47 end
|
|
48
|
4
|
49 function Shared.admin_header()
|
|
50 %>
|
|
51 <div header>
|
|
52 <a href="/private/admin.html">Admin</a>
|
|
53 </div>
|
|
54 <%
|
|
55 end
|
|
56
|
3
|
57 function Shared.base_url()
|
|
58 return Http.request.scheme.."://"..Http.request.headers["host"]
|
|
59 end
|
|
60
|
6
|
61 function Shared.call_mail_api(cmd,parameters)
|
|
62 local url = mailer_url.."/api/"..cmd..".json"
|
|
63 local options = {
|
|
64 parameters = parameters
|
|
65 }
|
|
66 local response = uri(url,options).read_text()
|
|
67 return json_parse(response)
|
|
68 end
|
|
69
|
0
|
70 return Shared
|