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