iteration

This commit is contained in:
2023-10-08 04:44:58 -04:00
parent 282f209217
commit 9ed504bb5f
3 changed files with 192 additions and 39 deletions

View File

@@ -6,44 +6,10 @@ if args[1] == nil then
end
local action = args[1]
settings.define("auth.token", {
description = "Authentication token",
type = "number",
default = -1
})
settings.define("auth.server", {
description = "Authentication server",
type = "string",
default = "auth.box"
})
local server = settings.get("auth.server")
function lns_lookup(hostname)
local data = {
["action"] = "lookup",
["hostname"] = hostname
}
lns_server_id = rednet.lookup("lns", lns_server)
rednet.send(lns_server_id, data, "lns")
while true do
id, msg = rednet.receive("lns")
if id == lns_server_id then
if msg == nil then
return nil
else
return msg
end
end
end
end
auth_server_id = lns_lookup(server)
auth_server_id = lns.lookup(server)
if action == "login" then
io.write("Username: ")
@@ -78,20 +44,19 @@ if action == "login" then
end
end
settings.set("auth.username", username)
settings.set("auth.token", token)
settings.save()
io.write("Logged in as " .. username .. "\n")
return
end
if action == "logout" then
elseif action == "logout" then
settings.set("auth.token", -1)
settings.save()
io.write("Logged out\n")
return
end
if action == "register" then
elseif action == "register" then
io.write("Username: ")
local username = io.read()
io.write("Password: ")
@@ -127,4 +92,24 @@ if action == "register" then
end
end
end
elseif action == "group" then
local subaction = args[2]
if subaction == nil then
io.write("Usage: auth group <list:check:add>\n")
return
end
if subaction == "list" then
local result = auth.list_user_groups(settings.get("auth.username"))
io.write("Groups: " .. result .. "\n")
elseif subaction == "add" then
local target_user = args[3]
local group = args[4]
if target_user == nil or group == nil then
io.write("Usage: auth group add <user> <group>\n")
return
end
local result = auth.add_user_group(target_user, group)
end
end