annotate src/lib/Shared.luan @ 13:af2b95854072

add server records
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 30 Oct 2023 21:32:42 -0600
parents 3e2cb946d511
children 80105b716a62
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
6
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
55 function Shared.discord_redirect_uri()
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
56 local request = Http.request
8
9534dd5eda89 use avatar
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
57 return request.scheme.."://"..request.headers["Host"].."/login2.html"
6
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
58 end
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
59
12
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
60 function Shared.js_error(field,message)
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
61 %>
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
62 showError( context.form, '<%=field%>', <%=json_string(message)%> );
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
63 <%
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
64 end
3e2cb946d511 form handling
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
65
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 return Shared