comparison src/lib/Shared.luan @ 4:8896ffd7b152

start login
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 22 Oct 2023 23:53:59 -0600
parents 5ae5fbce0d75
children aa1920665f98
comparison
equal deleted inserted replaced
3:43814e9f5802 4:8896ffd7b152
1 local Luan = require "luan:Luan.luan" 1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error 2 local error = Luan.error
3 local Time = require "luan:Time.luan" 3 local Time = require "luan:Time.luan"
4 local Http = require "luan:http/Http.luan"
4 5
5 6
6 local Shared = {} 7 local Shared = {}
7 8
8 local started = Time.now() 9 local started = Time.now()
10
11 local function get_user()
12 return Http.request.cookies.user
13 end
14 Shared.get_user = get_user
9 15
10 function Shared.head() 16 function Shared.head()
11 %> 17 %>
12 <meta name="viewport" content="width=device-width, initial-scale=1"> 18 <meta name="viewport" content="width=device-width, initial-scale=1">
13 <style> 19 <style>
14 @import "/site.css?s=<%=started%>"; 20 @import "/site.css?s=<%=started%>";
15 </style> 21 </style>
22 <script src="/site.js?s=<%=started%>"></script>
16 <% 23 <%
17 end 24 end
18 25
19 function Shared.header() 26 function Shared.header()
20 %> 27 %>
21 <div header> 28 <div header>
22 <h1><a href="/">Disearch</a></h1> 29 <h1><a href="/">Disearch</a></h1>
23 <span>login</span> 30 <% if get_user() == nil then %>
31 <a href="login.red">login</a>
32 <% else %>
33 <a href="javascript:logout()">logout</a>
34 <% end %>
24 </div> 35 </div>
25 <hr> 36 <hr>
26 <% 37 <%
27 end 38 end
28 39