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