Fixed data bug
This commit is contained in:
parent
d13281865f
commit
d5b2016dc3
10
bank.lua
10
bank.lua
|
@ -21,7 +21,6 @@ g.clear(term, colors.black)
|
||||||
g.drawTextCenter(term, W/2, 1, "BANK Server @ " .. HOST, colors.lime, colors.black)
|
g.drawTextCenter(term, W/2, 1, "BANK Server @ " .. HOST, colors.lime, colors.black)
|
||||||
g.drawXLine(term, 1, W, 2, colors.black, colors.gray, "-")
|
g.drawXLine(term, 1, W, 2, colors.black, colors.gray, "-")
|
||||||
g.drawText(term, W-3, 1, "Quit", colors.white, colors.red)
|
g.drawText(term, W-3, 1, "Quit", colors.white, colors.red)
|
||||||
|
|
||||||
local console = g.createConsole(W, H-2, colors.white, colors.black, "DOWN")
|
local console = g.createConsole(W, H-2, colors.white, colors.black, "DOWN")
|
||||||
|
|
||||||
local function log(msg)
|
local function log(msg)
|
||||||
|
@ -166,7 +165,7 @@ local function createUser(name, password)
|
||||||
}
|
}
|
||||||
fs.makeDir(userDir(name))
|
fs.makeDir(userDir(name))
|
||||||
writeJSON(userDataFile(name), userData) -- Flush user data file.
|
writeJSON(userDataFile(name), userData) -- Flush user data file.
|
||||||
saveAccounts(userAccountsFile(name), {}) -- Flush initial accounts file.
|
saveAccounts(name, {}) -- Flush initial accounts file.
|
||||||
createAccount(name, "Checking")
|
createAccount(name, "Checking")
|
||||||
createAccount(name, "Savings")
|
createAccount(name, "Savings")
|
||||||
log("Created new user: " .. name)
|
log("Created new user: " .. name)
|
||||||
|
@ -237,7 +236,7 @@ local function handleCreateUser(msg)
|
||||||
if not msg.data or not msg.data.username or not msg.data.password then
|
if not msg.data or not msg.data.username or not msg.data.password then
|
||||||
return {success = false, error = "Invalid request. Requires data.username and data.password."}
|
return {success = false, error = "Invalid request. Requires data.username and data.password."}
|
||||||
end
|
end
|
||||||
local success, errorMsg = createuser(msg.data.username, msg.data.password)
|
local success, errorMsg = createUser(msg.data.username, msg.data.password)
|
||||||
if not success then
|
if not success then
|
||||||
return {success = false, error = errorMsg}
|
return {success = false, error = errorMsg}
|
||||||
end
|
end
|
||||||
|
@ -322,7 +321,7 @@ local function handleNetworkEvents()
|
||||||
while RUNNING do
|
while RUNNING do
|
||||||
local remoteId, msg = rednet.receive("BANK", 3)
|
local remoteId, msg = rednet.receive("BANK", 3)
|
||||||
if remoteId ~= nil then
|
if remoteId ~= nil then
|
||||||
log("Received rednet message from computer ID " .. remoteId)
|
log("Received message from computer ID " .. remoteId)
|
||||||
local success, response = pcall(handleBankMessage, remoteId, msg)
|
local success, response = pcall(handleBankMessage, remoteId, msg)
|
||||||
if not success then
|
if not success then
|
||||||
response = {success = false, error = "An error occurred: " .. response}
|
response = {success = false, error = "An error occurred: " .. response}
|
||||||
|
@ -356,12 +355,11 @@ local function handleEvents()
|
||||||
end
|
end
|
||||||
|
|
||||||
local args = {...}
|
local args = {...}
|
||||||
|
|
||||||
if args[1] == "-i" then
|
if args[1] == "-i" then
|
||||||
print("Reinstalling from GitHub.")
|
print("Reinstalling from GitHub.")
|
||||||
fs.delete("bank.lua")
|
fs.delete("bank.lua")
|
||||||
shell.execute("wget", "https://raw.githubusercontent.com/andrewlalis/kp-bank/main/bank.lua")
|
shell.execute("wget", "https://raw.githubusercontent.com/andrewlalis/kp-bank/main/bank.lua")
|
||||||
shell.execute("bank.lua")
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
initSecurityKey()
|
initSecurityKey()
|
||||||
|
|
Loading…
Reference in New Issue