iteration

This commit is contained in:
2023-10-09 06:54:35 -04:00
parent e6ed55bcc7
commit bb0d27b755
9 changed files with 515 additions and 77 deletions

View File

@@ -6,10 +6,6 @@ if args[1] == nil then
end
local action = args[1]
local server = settings.get("auth.server")
auth_server_id = lns.lookup(server)
if action == "login" then
io.write("Username: ")
@@ -17,43 +13,12 @@ if action == "login" then
io.write("Password: ")
local password = read("*")
local data = {
["action"] = "login",
["username"] = username,
["password"] = password
}
rednet.send(auth_server_id, data, "auth")
while true do
id, msg = rednet.receive("auth")
if id == auth_server_id then
if msg == "invalid request" then
io.write("Invalid request\n")
return
elseif msg == "user not found" then
io.write("User not found\n")
return
elseif msg == "invalid password" then
io.write("Invalid password\n")
return
else
token = msg
break
end
end
if login(username, password) then
io.write("Logged in as " .. username .. "\n")
end
settings.set("auth.username", username)
settings.set("auth.token", token)
settings.save()
io.write("Logged in as " .. username .. "\n")
return
elseif action == "logout" then
settings.set("auth.token", -1)
settings.save()
io.write("Logged out\n")
auth.logout()
return
elseif action == "register" then
@@ -69,29 +34,7 @@ elseif action == "register" then
return
end
local data = {
["action"] = "register",
["username"] = username,
["password"] = password
}
rednet.send(auth_server_id, data, "auth")
while true do
id, msg = rednet.receive("auth")
if id == auth_server_id then
if msg == "invalid request" then
io.write("Invalid request\n")
return
elseif msg == "user already exists" then
io.write("User already exists\n")
return
else
io.write("Registered user " .. username .. "\n")
return
end
end
end
auth.register(username, password)
elseif action == "group" then
local subaction = args[2]
if subaction == nil then