iteration
This commit is contained in:
@@ -49,6 +49,10 @@ function hash(str)
|
||||
return hash
|
||||
end
|
||||
|
||||
function log(str)
|
||||
io.write("[" .. os.time() .. "] " .. str .. "\n")
|
||||
end
|
||||
|
||||
load_data()
|
||||
math.randomseed(os.time())
|
||||
|
||||
@@ -76,21 +80,23 @@ while true do
|
||||
save_data()
|
||||
|
||||
rednet.send(client_id, "ok")
|
||||
log(request.username .. " registered")
|
||||
end
|
||||
|
||||
if request.action == "login" then
|
||||
if request.username == nil or request.password == nil then
|
||||
rednet.send(client_id, "invalid request")
|
||||
end
|
||||
|
||||
if data.users[request.username] == nil then
|
||||
|
||||
else if data.users[request.username] == nil then
|
||||
rednet.send(client_id, "user not found")
|
||||
end
|
||||
|
||||
if convert_password(request.password) == data.users[request.username].password then
|
||||
log(request.username .. " failed log in attempt")
|
||||
else if convert_password(request.password) == data.users[request.username].password then
|
||||
local token = generate_token(request.username)
|
||||
|
||||
rednet.send(client_id, token)
|
||||
|
||||
log(request.username .. " logged in")
|
||||
else
|
||||
rednet.send(client_id, "invalid password")
|
||||
end
|
||||
@@ -100,15 +106,17 @@ while true do
|
||||
if request.action == "token" then
|
||||
if request.token == nil then
|
||||
rednet.send(client_id, "invalid request")
|
||||
end
|
||||
else
|
||||
|
||||
for user, userdata in pairs(data.users) do
|
||||
if userdata.token == request.token then
|
||||
rednet.send(client_id, user)
|
||||
for user, userdata in pairs(data.users) do
|
||||
if userdata.token == request.token then
|
||||
rednet.send(client_id, user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
rednet.send(client_id, "invalid token")
|
||||
rednet.send(client_id, "invalid token")
|
||||
log(request.username .. " failed token check")
|
||||
end
|
||||
end
|
||||
|
||||
if request.action == "profile" then
|
||||
@@ -142,6 +150,7 @@ while true do
|
||||
save_data()
|
||||
|
||||
rednet.send(client_id, "ok")
|
||||
log(request.username .. " updated their profile")
|
||||
else
|
||||
rednet.send(client_id, "invalid token")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user