annotate src/tools/cookies.html.luan @ 5:aa1920665f98

discord login
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 23 Oct 2023 00:43:41 -0600
parents 8896ffd7b152
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local pairs = Luan.pairs or error()
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Html = require "luan:Html.luan"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local html_encode = Html.encode or error()
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Logging = require "luan:logging/Logging.luan"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local logger = Logging.logger "cookies.html"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 return function()
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local name = Http.request.parameters.name
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 if name ~= nil then
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 local value = Http.request.parameters.value
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local persistent = Http.request.parameters.persistent
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 if #value == 0 then
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 Http.response.remove_cookie(name)
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 elseif persistent ~= nil then
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 Http.response.set_persistent_cookie(name,value)
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 else
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Http.response.set_cookie(name,value)
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 end
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 Http.response.send_redirect "cookies.html"
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 Io.stdout = Http.response.text_writer()
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 %>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <!doctype html>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 <html>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <head>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <meta name="viewport" content="width=device-width, initial-scale=1">
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <style>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 form {
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 margin-bottom: 16px;
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 }
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 </style>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 </head>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <body>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <h2>Cookies Tool</h2>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 <%
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 for name, value in pairs(Http.request.cookies) do
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 name = html_encode(name)
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 value = html_encode(value)
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 %>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <form>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <input name=name value="<%=name%>" type=hidden>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <%=name%> = <input name=value value="<%=value%>" size=100>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 <label><input type=checkbox name=persistent>persistent</label>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 </form>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <% end %>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 <form>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <input name=name>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 = <input name=value size=100>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 <label><input type=checkbox name=persistent>persistent</label>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 <input type=submit>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 </form>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 </body>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 </html>
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 <%
8896ffd7b152 start login
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 end