Add login script
This commit is contained in:
@@ -1 +1 @@
|
||||
["/halyde/scripts/shell.lua"]
|
||||
["/halyde/scripts/login.lua"]
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
local fs = require("filesystem")
|
||||
local json = require("json")
|
||||
|
||||
terminal.clear()
|
||||
|
||||
::retry::
|
||||
|
||||
local username = terminal.read({
|
||||
prefix = "Username: "
|
||||
})
|
||||
|
||||
local handle, data, tmpdata = fs.open("/halyde/kernel/userreg.json"), "", nil
|
||||
repeat
|
||||
tmpdata = handle:read(math.huge or math.maxinteger)
|
||||
data = data .. (tmpdata or "")
|
||||
until not tmpdata
|
||||
handle:close()
|
||||
|
||||
local userRegistry = json.decode(data)
|
||||
|
||||
local foundUser, uid = false, nil
|
||||
for i, user in pairs(userRegistry) do
|
||||
if user.name == username then
|
||||
foundUser = true
|
||||
uid = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not foundUser then
|
||||
print("User does not exist.")
|
||||
goto retry
|
||||
end
|
||||
|
||||
local password = terminal.read({
|
||||
prefix = "Password: ",
|
||||
censor = "*"
|
||||
})
|
||||
|
||||
local shellPath = "/halyde/scripts/shell.lua" -- TODO: Add shell selection (perhaps in a config file or user prompt?)
|
||||
|
||||
local handle, data, tmpdata = fs.open(shellPath), "", nil
|
||||
repeat
|
||||
tmpdata = handle:read(math.huge or math.maxinteger)
|
||||
data = data .. (tmpdata or "")
|
||||
until not tmpdata
|
||||
handle:close()
|
||||
|
||||
-- Prepare userland environment
|
||||
local temporaryGlobals = _G
|
||||
_G = nil -- This is so copying doesn't cause an infinite loop
|
||||
local userland = table.copy(temporaryGlobals)
|
||||
_G = temporaryGlobals
|
||||
userland._G = userland
|
||||
|
||||
local result, errorMessage = user.addTask(assert(load(data, "=" .. shellPath, "t", userland)), "shell", uid, password)
|
||||
if not result then
|
||||
print(errorMessage)
|
||||
goto retry
|
||||
end
|
||||
@@ -129,8 +129,6 @@ end
|
||||
local shareTable = ipc.shareWithAll()
|
||||
shareTable.shell = _G.shell
|
||||
|
||||
terminal.clear()
|
||||
|
||||
print(shellcfg["startupMessage"]:format(_OSVERSION, shellcfg.splashMessages[math.random(1, #shellcfg.splashMessages)]))
|
||||
while true do
|
||||
coroutine.yield()
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
local args = {...}
|
||||
|
||||
print(user.addTask(function()
|
||||
print("I eat rocks")
|
||||
print(tsched.getCurrentTask())
|
||||
end, "testerpester", tonumber(args[1]), args[2]))
|
||||
Reference in New Issue
Block a user