Added sPhone.list function and username can be changed

This commit is contained in:
Ale32bit 2016-10-30 21:38:19 +01:00 committed by GitHub
parent e4deff5856
commit 9b2932e99e

View file

@ -4,6 +4,7 @@ local pwChangeRep
local menu = { local menu = {
"Update", "Update",
"Edit Theme", "Edit Theme",
"Change Username",
"Change Password", "Change Password",
"Set Label", "Set Label",
"Clear Label", "Clear Label",
@ -17,88 +18,105 @@ local function clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
end end
local function changeUsername()
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1,1)
sPhone.header(sPhone.user)
term.setTextColor(sPhone.theme["text"])
visum.align("center"," New Username",false,3)
term.setCursorPos(2,5)
write("Username: ")
local newUsername = read()
sPhone.user = newUsername
f = fs.open("/.sPhone/config/username","w")
f.write(sPhone.user)
f.close()
sPhone.winOk("Username","Changed")
end
local function changePassword() local function changePassword()
while true do while true do
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1,1)
sPhone.header(sPhone.user)
paintutils.drawBox(7,9,20,11,sPhone.theme["window.background"])
term.setBackgroundColor(sPhone.theme["backgroundColor"])
if sPhone.wrongPassword then
term.setTextColor(colors.red)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
visum.align("center"," Wrong Password",false,13) term.clear()
end term.setCursorPos(1,1)
term.setTextColor(sPhone.theme["text"]) sPhone.header(sPhone.user)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) paintutils.drawBox(7,9,20,11,sPhone.theme["window.background"])
visum.align("center"," Current Password",false,7) term.setBackgroundColor(sPhone.theme["backgroundColor"])
local loginTerm = window.create(term.native(), 8,10,12,1, true) if sPhone.wrongPassword then
term.redirect(loginTerm) term.setTextColor(colors.red)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear() visum.align("center"," Wrong Password",false,13)
term.setCursorPos(1,1) end
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
local password = read("*") term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.redirect(sPhone.mainTerm) visum.align("center"," Current Password",false,7)
local fpw = fs.open("/.sPhone/config/.password","r") local loginTerm = window.create(term.native(), 8,10,12,1, true)
if sha256.sha256(password) ~= fpw.readLine() then term.redirect(loginTerm)
sPhone.wrongPassword = true term.setBackgroundColor(sPhone.theme["backgroundColor"])
else term.clear()
sPhone.wrongPassword = false term.setCursorPos(1,1)
fpw.close() term.setTextColor(sPhone.theme["text"])
break local password = read("*")
end term.redirect(sPhone.mainTerm)
local fpw = fs.open("/.sPhone/config/.password","r")
if sha256.sha256(password) ~= fpw.readLine() then
sPhone.wrongPassword = true
else
sPhone.wrongPassword = false
fpw.close()
break
end
end end
while true do while true do
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1,1)
sPhone.header(sPhone.user)
paintutils.drawBox(7,9,20,11,sPhone.theme["window.background"])
term.setBackgroundColor(sPhone.theme["backgroundColor"])
if sPhone.wrongPassword then
term.setTextColor(colors.red)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
visum.align("center"," Wrong Password",false,13) term.clear()
end term.setCursorPos(1,1)
term.setTextColor(sPhone.theme["text"]) sPhone.header(sPhone.user)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) paintutils.drawBox(7,9,20,11,sPhone.theme["window.background"])
visum.align("center"," New Password",false,7) term.setBackgroundColor(sPhone.theme["backgroundColor"])
local loginTerm = window.create(term.native(), 8,10,12,1, true) if sPhone.wrongPassword then
term.redirect(loginTerm) term.setTextColor(colors.red)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear() visum.align("center"," Wrong Password",false,13)
term.setCursorPos(1,1) end
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
pwChange = read("*") term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.redirect(sPhone.mainTerm) visum.align("center"," New Password",false,7)
local loginTerm = window.create(term.native(), 8,10,12,1, true)
term.redirect(loginTerm)
term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear()
term.setCursorPos(1,1)
term.setTextColor(sPhone.theme["text"])
pwChange = read("*")
term.redirect(sPhone.mainTerm)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
sPhone.header(sPhone.user) sPhone.header(sPhone.user)
paintutils.drawBox(7,9,20,11,sPhone.theme["window.background"]) paintutils.drawBox(7,9,20,11,sPhone.theme["window.background"])
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
visum.align("center"," Repeat Password",false,7) visum.align("center"," Repeat Password",false,7)
local loginTerm = window.create(term.native(), 8,10,12,1, true) local loginTerm = window.create(term.native(), 8,10,12,1, true)
term.redirect(loginTerm) term.redirect(loginTerm)
term.setBackgroundColor(sPhone.theme["backgroundColor"]) term.setBackgroundColor(sPhone.theme["backgroundColor"])
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
pwChangeRep = read("*") pwChangeRep = read("*")
term.redirect(sPhone.mainTerm) term.redirect(sPhone.mainTerm)
if sha256.sha256(pwChange) ~= sha256.sha256(pwChangeRep) then if sha256.sha256(pwChange) ~= sha256.sha256(pwChangeRep) then
sPhone.wrongPassword = true sPhone.wrongPassword = true
else else
sPhone.wrongPassword = false sPhone.wrongPassword = false
break break
end end
end end
if not sPhone.wrongPassword then if not sPhone.wrongPassword then
local f = fs.open("/.sPhone/config/.password","w") local f = fs.open("/.sPhone/config/.password","w")
@ -181,25 +199,22 @@ local function editTheme()
fs.copy("/.sPhone/config/theme", saveTheme) fs.copy("/.sPhone/config/theme", saveTheme)
sPhone.winOk("Theme saved!") sPhone.winOk("Theme saved!")
elseif id == 7 then elseif id == 7 then
sPhone.header() local loadTheme = sPhone.list()
visum.align("center", "Load Theme",false,3) if loadTheme then
term.setCursorPos(2,5) if fs.exists(loadTheme) and not fs.isDir(loadTheme) then
local loadTheme = read() for k, v in pairs(sPhone.theme) do -- Load theme
if fs.exists(loadTheme) and not fs.isDir(loadTheme) then sPhone.theme[k] = config.read(loadTheme, k)
for k, v in pairs(sPhone.theme) do -- Load theme end
sPhone.theme[k] = config.read(loadTheme, k) for k, v in pairs(sPhone.theme) do -- Overwrite theme config
config.write("/.sPhone/config/theme", k, v)
end
sPhone.winOk("Theme loaded!")
else
sPhone.winOk("Theme not found!")
end end
for k, v in pairs(sPhone.theme) do -- Overwrite theme config
config.write("/.sPhone/config/theme", k, v)
end
sPhone.winOk("Theme loaded!")
else
sPhone.winok("Theme not found!")
end end
elseif id == 8 then elseif id == 8 then
for k, v in pairs(sPhone.defaultTheme) do fs.delete("/.sPhone/config/theme")
config.write("/.sPhone/config/theme", k, v)
end
sPhone.theme = sPhone.defaultTheme sPhone.theme = sPhone.defaultTheme
sPhone.winOk("Removed Theme") sPhone.winOk("Removed Theme")
end end
@ -217,15 +232,9 @@ local function defaultApps()
elseif id == 1 then elseif id == 1 then
while true do while true do
clear() local defaultHome = sPhone.list()
sPhone.header("Default Apps: Home")
visum.align("center","Set default home app",false,3)
term.setCursorPos(2,5)
print("Leave blank for default")
write(" Path: /")
local defaultHome = read()
if defaultHome == "" then if not defaultHome then
sPhone.setDefaultApp("home","/.sPhone/apps/home") sPhone.setDefaultApp("home","/.sPhone/apps/home")
sPhone.winOk("Done!","Reboot to apply") sPhone.winOk("Done!","Reboot to apply")
break break
@ -253,12 +262,14 @@ while true do
elseif id == 2 then elseif id == 2 then
editTheme() editTheme()
elseif id == 3 then elseif id == 3 then
changePassword() changeUsername()
elseif id == 4 then elseif id == 4 then
changeLabel() changePassword()
elseif id == 5 then elseif id == 5 then
clearLabel() changeLabel()
elseif id == 6 then elseif id == 6 then
clearLabel()
elseif id == 7 then
defaultApps() defaultApps()
end end
end end