Mercurial Hosting > freedit
annotate src/login.html.luan @ 56:7ce54f6d93f2
add change name
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 28 Nov 2022 22:00:43 -0700 |
parents | c57b84f461ae |
children |
rev | line source |
---|---|
3 | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | |
3 local Html = require "luan:Html.luan" | |
4 local url_encode = Html.url_encode or error() | |
5 local Io = require "luan:Io.luan" | |
6 local Http = require "luan:http/Http.luan" | |
7 local Shared = require "site:/lib/Shared.luan" | |
8 local head = Shared.head or error() | |
9 local header = Shared.header or error() | |
10 local footer = Shared.footer or error() | |
11 local Forum = require "site:/lib/Forum.luan" | |
12 local forum_title = Forum.title or error() | |
13 local User = require "site:/lib/User.luan" | |
14 | |
15 | |
16 local function page(contents) | |
17 Io.stdout = Http.response.text_writer() | |
18 %> | |
19 <!doctype html> | |
20 <html> | |
21 <head> | |
22 <% head() %> | |
54 | 23 <title><%=forum_title%> - Login</title> |
24 <script> | |
25 function show(checkbox) { | |
26 document.querySelector('input[name="password"]').type = checkbox.checked ? 'text' : 'password'; | |
27 } | |
28 </script> | |
3 | 29 </head> |
30 <body> | |
31 <% header() %> | |
32 <div content> | |
54 | 33 <h1>Login</h1> |
3 | 34 <% |
35 contents() | |
36 %> | |
37 </div> | |
38 <% footer() %> | |
39 </body> | |
40 </html> | |
41 <% | |
42 end | |
43 | |
44 return function() | |
45 local email = Http.request.parameters.email | |
46 local password = Http.request.parameters.password | |
54 | 47 local error_message = nil |
48 if Http.request.method == "POST" then | |
49 local user = User.get_by_email(email) | |
50 if user == nil then | |
51 error_message = "email not found" | |
52 elseif user.password ~= password then | |
53 error_message = "wrong password" | |
54 end | |
55 if error_message == nil then | |
56 if user.name == nil then | |
57 Http.response.send_redirect("/set_name.html?email="..url_encode(email).."&password="..password) | |
58 return | |
59 end | |
60 user.login() | |
61 page(function() | |
3 | 62 %> |
54 | 63 <p>You are now logged in.</p> |
64 <% | |
65 end) | |
66 return | |
67 end | |
68 end | |
69 page(function() | |
70 if error_message ~= nil then %> | |
71 <p error>Error: <%= error_message %></p> | |
72 <% end %> | |
73 <form action="login.html" method=post> | |
74 <p> | |
75 <label>Email address</label> | |
76 <input type="email" name="email" value="<%= email or "" %>" autofocus required> | |
77 </p> | |
78 <p> | |
79 <label>Password</label> | |
55
c57b84f461ae
login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents:
54
diff
changeset
|
80 <input type="password" name="password" value="<%= password or "" %>" required> |
54 | 81 <label clickable><input type=checkbox onclick="show(this)">Show</label> |
82 </p> | |
83 <p><input type="submit" value="Login"></p> | |
3 | 84 </form> |
55
c57b84f461ae
login and registration work
Franklin Schmidt <fschmidt@gmail.com>
parents:
54
diff
changeset
|
85 <p><a href="/register.html">Get or change password</a></p> |
3 | 86 <% |
54 | 87 end) |
3 | 88 end |