0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local pairs = Luan.pairs or error()
|
|
4 local ipairs = Luan.ipairs or error()
|
|
5 local stringify = Luan.stringify or error()
|
|
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.private_header or error()
|
|
11 local text_to_list = Shared.text_to_list or error()
|
|
12 local config = Shared.config or error()
|
|
13 local get_raw_config = Shared.get_raw_config or error()
|
|
14 local save_raw_config = Shared.save_raw_config or error()
|
|
15 local Logging = require "luan:logging/Logging.luan"
|
4
|
16 local logger = Logging.logger "private_users.html"
|
0
|
17
|
|
18
|
|
19 local function response(content)
|
|
20 %>
|
|
21 <!doctype html>
|
|
22 <html>
|
|
23 <head>
|
|
24 <% head() %>
|
|
25 <title>Mercurial Private Users</title>
|
|
26 </head>
|
|
27 <body>
|
|
28 <% header() %>
|
|
29 <div content>
|
|
30 <h1>Private Users</h1>
|
|
31 <%=content%>
|
|
32 </div>
|
|
33 </body>
|
|
34 </html>
|
|
35 <%
|
|
36 end
|
|
37
|
|
38 local function posted()
|
|
39 local users = Http.request.parameters.users or error()
|
|
40 users = text_to_list(users)
|
|
41 if #users == 0 then
|
|
42 return "Users cannot be empty"
|
|
43 end
|
|
44 for _, user in ipairs(users) do
|
|
45 if config.users[user] == nil then
|
|
46 return "user "..user.." is not a registered user"
|
|
47 end
|
|
48 end
|
|
49 local raw_config = get_raw_config()
|
|
50 raw_config.private = users
|
|
51 save_raw_config(raw_config)
|
|
52 return nil
|
|
53 end
|
|
54
|
|
55 return function()
|
|
56 Io.stdout = Http.response.text_writer()
|
|
57 local error_msg = ""
|
|
58 if Http.request.method == "POST" then
|
|
59 local error_msg = posted()
|
|
60 if error_msg == nil then
|
|
61 response([[<p>Private updated</p>]])
|
|
62 else
|
|
63 response([[<p error>]]..error_msg..[[</p>]])
|
|
64 end
|
|
65 return
|
|
66 end
|
|
67 %>
|
|
68 <!doctype html>
|
|
69 <html>
|
|
70 <head>
|
|
71 <% head() %>
|
|
72 <title>Mercurial Private Users</title>
|
|
73 </head>
|
|
74 <body>
|
|
75 <% header() %>
|
|
76 <div content>
|
|
77 <h1>Private Users</h1>
|
|
78 <form method=post>
|
|
79 <p>
|
|
80 <label prompt>Users (one per line)</label>
|
|
81 <textarea name=users>
|
|
82 <% for user in pairs(config.private or {}) do %>
|
|
83 <%=user%>
|
|
84 <% end %>
|
|
85 </textarea>
|
|
86 <label prompt>Users who can access /private/</label>
|
|
87 </p>
|
|
88 <p>
|
|
89 <input type=submit value="Update Private">
|
|
90 </p>
|
|
91 </form>
|
|
92 </div>
|
|
93 </body>
|
|
94 </html>
|
|
95 <%
|
|
96 end
|