annotate src/lib/Shared.luan @ 11:62dd23f0b549

start add server
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 29 Oct 2023 22:39:31 -0600
parents 88f425d261b3
children 3e2cb946d511
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"
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
4 local Http = require "luan:http/Http.luan"
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Shared = {}
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local started = Time.now()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
11 local function get_user()
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
12 return Http.request.cookies.user
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
13 end
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
14 Shared.get_user = get_user
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
15
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 function Shared.head()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 %>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 <meta name="viewport" content="width=device-width, initial-scale=1">
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 <style>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 @import "/site.css?s=<%=started%>";
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 </style>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
22 <script src="/site.js?s=<%=started%>"></script>
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 <%
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 end
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 function Shared.header()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 %>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <div header>
2
5ae5fbce0d75 start header
Franklin Schmidt <fschmidt@gmail.com>
parents: 1
diff changeset
29 <h1><a href="/">Disearch</a></h1>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
30 <% if get_user() == nil then %>
5
aa1920665f98 discord login
Franklin Schmidt <fschmidt@gmail.com>
parents: 4
diff changeset
31 <a href="login1.red">login</a>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
32 <% else %>
9
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
33 <span right pulldown>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
34 <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
35 <div pulldown_menu>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
36 <span username><script>document.write(localStorage.user_name)</script></span>
11
62dd23f0b549 start add server
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
37 <a href="/servers.html">Your Servers</a>
9
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
38 <a href="javascript:logout()">Log out</a>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
39 </div>
88f425d261b3 add menu
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
40 </span>
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents: 2
diff changeset
41 <% end %>
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 </div>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 <hr>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <%
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 end
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 function Shared.footer()
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 %>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <hr>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 <div footer>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 something or other in the footer
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 </div>
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 <%
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 end
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55
6
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
56 function Shared.discord_redirect_uri()
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
57 local request = Http.request
8
9534dd5eda89 use avatar
Franklin Schmidt <fschmidt@gmail.com>
parents: 6
diff changeset
58 return request.scheme.."://"..request.headers["Host"].."/login2.html"
6
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
59 end
d59ae3e468f1 login work
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
60
1
d19b150ecb83 add Shared
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 return Shared