annotate src/lib/Shared.luan @ 14:80105b716a62

start bot
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 31 Oct 2023 23:56:48 -0600
parents af2b95854072
children 552d6f944acb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Time = require "luan:Time.luan"
12
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
4 local Parsers = require "luan:Parsers.luan"
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
5 local json_string = Parsers.json_string or error()
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
6 local Http = require "luan:http/Http.luan"
13
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
7 local Utils = require "site:/lib/Utils.luan"
af2b95854072 add server records
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
8 local get_user = Utils.get_user or error()
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Shared = {}
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local started = Time.now()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 function Shared.head()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 %>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 <meta name="viewport" content="width=device-width, initial-scale=1">
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 <style>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 @import "/site.css?s=<%=started%>";
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 </style>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
21 <script src="/site.js?s=<%=started%>"></script>
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 <%
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 function Shared.header()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 %>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 <div header>
2
5ae5fbce0d75 start header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
28 <h1><a href="/">Disearch</a></h1>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
29 <% if get_user() == nil then %>
5
aa1920665f98 discord login
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
30 <a href="login1.red">login</a>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
31 <% else %>
9
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
32 <span right pulldown>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
33 <script>document.write(`<img src="https://cdn.discordapp.com/avatars/${localStorage.user_id}/${localStorage.user_avatar}.png" onclick="clickMenu(this)">`)</script>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
34 <div pulldown_menu>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
35 <span username><script>document.write(localStorage.user_name)</script></span>
11
62dd23f0b549 start add server
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
36 <a href="/servers.html">Your Servers</a>
9
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
37 <a href="javascript:logout()">Log out</a>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
38 </div>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
39 </span>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
40 <% end %>
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 </div>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <hr>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 <%
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 end
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 function Shared.footer()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 %>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <hr>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <div footer>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 something or other in the footer
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 </div>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <%
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 end
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54
14
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
55 local function base_url()
6
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
56 local request = Http.request
14
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
57 return request.scheme.."://"..request.headers["Host"]
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
58 end
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
59 Shared.base_url = base_url
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
60
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
61 function Shared.discord_redirect_uri()
80105b716a62 start bot
Franklin Schmidt <fschmidt@gmail.com>
parents: 13
diff changeset
62 return base_url().."/login2.html"
6
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
63 end
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
64
12
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
65 function Shared.js_error(field,message)
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
66 %>
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
67 showError( context.form, '<%=field%>', <%=json_string(message)%> );
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
68 <%
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
69 end
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
70
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 return Shared