|
0
|
1 local Luan = require "luan:Luan.luan"
|
|
|
2 local error = Luan.error
|
|
5
|
3 local ipairs = Luan.ipairs or error()
|
|
|
4 local Table = require "luan:Table.luan"
|
|
|
5 local concat = Table.concat or error()
|
|
0
|
6 local Io = require "luan:Io.luan"
|
|
|
7 local Http = require "luan:http/Http.luan"
|
|
|
8 local Shared = require "site:/lib/Shared.luan"
|
|
|
9 local head = Shared.head or error()
|
|
|
10 local header = Shared.header or error()
|
|
3
|
11 local User = require "site:/lib/User.luan"
|
|
5
|
12 local Utils = require "site:/lib/Utils.luan"
|
|
|
13 local to_list = Utils.to_list or error()
|
|
0
|
14
|
|
|
15
|
|
|
16 return function()
|
|
3
|
17 local user_id = Http.request.parameters.user or error()
|
|
|
18 local password = Http.request.parameters.password or error()
|
|
|
19 local user = User.get_by_id(user_id)
|
|
0
|
20 Io.stdout = Http.response.text_writer()
|
|
|
21 %>
|
|
|
22 <!doctype html>
|
|
|
23 <html>
|
|
|
24 <head>
|
|
|
25 <% head() %>
|
|
|
26 </head>
|
|
|
27 <body>
|
|
|
28 <% header() %>
|
|
|
29 <div content>
|
|
3
|
30 <h1>Login / Register</h1>
|
|
|
31 <% if user == nil or user.password ~= password then %>
|
|
|
32 <p>Login failed</p>
|
|
|
33 <%
|
|
|
34 else
|
|
|
35 user.login()
|
|
5
|
36 local with = Http.request.parameters.with
|
|
|
37 local location
|
|
|
38 if with == nil then
|
|
|
39 location = "/"
|
|
|
40 else
|
|
|
41 with = to_list(with)
|
|
|
42 local t = {}
|
|
|
43 for _, email in ipairs(with) do
|
|
|
44 t[#t+1] = "with="..email
|
|
|
45 end
|
|
21
|
46 location = "/?"..concat(t,"&")
|
|
5
|
47 end
|
|
3
|
48 %>
|
|
5
|
49 <script> location = '<%=location%>'; </script>
|
|
3
|
50 <%
|
|
|
51 end
|
|
|
52 %>
|
|
0
|
53 </div>
|
|
|
54 </body>
|
|
|
55 </html>
|
|
|
56 <%
|
|
|
57 end
|