comparison src/admin/add.html.luan @ 0:dfc36e7ed22c

init
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 12 May 2022 13:51:59 +0400
parents
children a09d8bcdc0f9
comparison
equal deleted inserted replaced
-1:000000000000 0:dfc36e7ed22c
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local Io = require "luan:Io.luan"
4 local Http = require "luan:http/Http.luan"
5 local Shared = require "site:/lib/Shared.luan"
6 local head = Shared.head or error()
7 local header = Shared.admin_header or error()
8 local get_user = Shared.get_user or error()
9 local get_raw_config = Shared.get_raw_config or error()
10 local save_raw_config = Shared.save_raw_config or error()
11 local admin_return = Shared.admin_return or error()
12
13
14 local function handle()
15 local user = get_user()
16 local repo_name = Http.request.parameters.repo or error()
17 if repo_name=="_all" or repo_name=="_private" then
18 return [[<p error>Invalid rep name</p>]]
19 end
20 local raw_config = get_raw_config()
21 if raw_config.repos[repo_name] ~= nil then
22 return [[<p error>A repo named <b>]]..repo_name..[[</b> already exists</p>]]
23 end
24 raw_config.repos[repo_name] = {
25 mode = "public"
26 users = {user}
27 admins = {user}
28 }
29 save_raw_config(raw_config)
30 return [[<p>Repo <b>]]..repo_name..[[</b> created</p>]]..admin_return
31 end
32
33 return function()
34 Io.stdout = Http.response.text_writer()
35 %>
36 <!doctype html>
37 <html>
38 <head>
39 <% head() %>
40 <title>Add Mercurial Repository</title>
41 </head>
42 <body>
43 <% header() %>
44 <div content>
45 <h1>Add Repository</h1>
46 <%=handle()%>
47 </div>
48 </body>
49 </html>
50 <%
51 end