Update settings.lua
This commit is contained in:
parent
15e078e3fe
commit
5c15bcf17e
1 changed files with 98 additions and 37 deletions
|
@ -1,5 +1,8 @@
|
||||||
local pwChange
|
local pwChange,mouse,x,y
|
||||||
local pwChangeRep
|
local pwChangeRep
|
||||||
|
local skipped = false
|
||||||
|
local w,h = term.getSize()
|
||||||
|
local password
|
||||||
|
|
||||||
local menu = {
|
local menu = {
|
||||||
"Update",
|
"Update",
|
||||||
|
@ -19,26 +22,50 @@ local function clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function changeUsername()
|
local function changeUsername()
|
||||||
|
local newUsername
|
||||||
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)
|
||||||
|
term.setCursorPos(w,1)
|
||||||
|
term.setBackgroundColor(sPhone.theme["header"])
|
||||||
|
term.setTextColor(sPhone.theme["headerText"])
|
||||||
|
write("X")
|
||||||
|
term.setBackgroundColor(sPhone.theme["backgroundColor"])
|
||||||
term.setTextColor(sPhone.theme["text"])
|
term.setTextColor(sPhone.theme["text"])
|
||||||
visum.align("center"," New Username",false,3)
|
visum.align("center"," New Username",false,3)
|
||||||
term.setCursorPos(2,5)
|
term.setCursorPos(2,5)
|
||||||
write("Username: ")
|
write("Username: ")
|
||||||
local newUsername = read()
|
while true do
|
||||||
|
newUsername,mouse,x,y = sPhone.read(nil,nil,nil,true)
|
||||||
|
if mouse then
|
||||||
|
if y == 1 and x == w then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
sPhone.user = newUsername
|
sPhone.user = newUsername
|
||||||
config.write("/.sPhone/config/sPhone","username",newUsername)
|
config.write("/.sPhone/config/sPhone","username",newUsername)
|
||||||
sPhone.winOk("Username","Changed")
|
sPhone.winOk("Username","Changed")
|
||||||
end
|
end
|
||||||
|
|
||||||
local function changePassword()
|
local function changePassword()
|
||||||
|
skipped = false
|
||||||
|
sPhone.wrongPassword = false
|
||||||
while true do
|
while true do
|
||||||
|
local usingPW = config.read("/.sPhone/config/sPhone","lockEnabled")
|
||||||
|
if not usingPW then
|
||||||
|
break
|
||||||
|
end
|
||||||
term.setBackgroundColor(sPhone.theme["lock.background"])
|
term.setBackgroundColor(sPhone.theme["lock.background"])
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
sPhone.header(sPhone.user)
|
sPhone.header(sPhone.user)
|
||||||
|
term.setCursorPos(w,1)
|
||||||
|
term.setBackgroundColor(sPhone.theme["header"])
|
||||||
|
term.setTextColor(sPhone.theme["headerText"])
|
||||||
|
write("X")
|
||||||
paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"])
|
paintutils.drawBox(7,9,20,11,sPhone.theme["lock.inputSide"])
|
||||||
term.setBackgroundColor(sPhone.theme["lock.inputBackground"])
|
term.setBackgroundColor(sPhone.theme["lock.inputBackground"])
|
||||||
if sPhone.wrongPassword then
|
if sPhone.wrongPassword then
|
||||||
|
@ -55,7 +82,16 @@ local function changePassword()
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.setTextColor(sPhone.theme["lock.inputText"])
|
term.setTextColor(sPhone.theme["lock.inputText"])
|
||||||
local password = read("*")
|
while true do
|
||||||
|
password,mouse,x,y = sPhone.read("*",nil,nil,true)
|
||||||
|
if mouse then
|
||||||
|
if y == 1 and x == w then
|
||||||
|
term.redirect(sPhone.mainTerm)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
term.redirect(sPhone.mainTerm)
|
term.redirect(sPhone.mainTerm)
|
||||||
local fpw = config.read("/.sPhone/config/sPhone","password")
|
local fpw = config.read("/.sPhone/config/sPhone","password")
|
||||||
if sha256.sha256(password) ~= fpw then
|
if sha256.sha256(password) ~= fpw then
|
||||||
|
@ -82,15 +118,27 @@ local function changePassword()
|
||||||
term.setTextColor(sPhone.theme["lock.text"])
|
term.setTextColor(sPhone.theme["lock.text"])
|
||||||
term.setBackgroundColor(sPhone.theme["lock.background"])
|
term.setBackgroundColor(sPhone.theme["lock.background"])
|
||||||
visum.align("center"," New Password",false,7)
|
visum.align("center"," New Password",false,7)
|
||||||
|
local t = "Disable Password"
|
||||||
|
term.setCursorPos(w-#t+1,h)
|
||||||
|
write(t)
|
||||||
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["lock.inputBackground"])
|
term.setBackgroundColor(sPhone.theme["lock.inputBackground"])
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.setTextColor(sPhone.theme["lock.inputText"])
|
term.setTextColor(sPhone.theme["lock.inputText"])
|
||||||
pwChange = read("*")
|
while true do
|
||||||
|
pwChange,mouse,x,y = sPhone.read("*",nil,nil,true)
|
||||||
|
if mouse then
|
||||||
|
if y == h and (x >= 10 and x <= w) then
|
||||||
|
skipped = true
|
||||||
|
config.write("/.sPhone/config/sPhone","lockEnabled",false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
term.redirect(sPhone.mainTerm)
|
term.redirect(sPhone.mainTerm)
|
||||||
|
if not skipped then
|
||||||
term.setBackgroundColor(sPhone.theme["lock.background"])
|
term.setBackgroundColor(sPhone.theme["lock.background"])
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
|
@ -107,30 +155,43 @@ local function changePassword()
|
||||||
term.setTextColor(sPhone.theme["lock.inputText"])
|
term.setTextColor(sPhone.theme["lock.inputText"])
|
||||||
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
|
|
||||||
|
|
||||||
else
|
|
||||||
sPhone.wrongPassword = false
|
sPhone.wrongPassword = false
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not sPhone.wrongPassword then
|
|
||||||
config.write("/.sPhone/config/sPhone","password",sha256.sha256(pwChangeRep))
|
config.write("/.sPhone/config/sPhone","password",sha256.sha256(pwChangeRep))
|
||||||
end
|
config.write("/.sPhone/config/sPhone","lockEnabled",true)
|
||||||
sPhone.header(sPhone.user)
|
sPhone.winOk("Password","changed")
|
||||||
term.setTextColor(sPhone.theme["lock.text"])
|
|
||||||
term.setBackgroundColor(sPhone.theme["lock.background"])
|
|
||||||
visum.align("center", "All Set!", false, 3)
|
|
||||||
sleep(2)
|
|
||||||
return
|
return
|
||||||
|
else
|
||||||
|
sPhone.wrongPassword = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
config.write("/.sPhone/config/sPhone","lockEnabled",false)
|
||||||
|
sPhone.winOk("Password","disabled")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function changeLabel()
|
local function changeLabel()
|
||||||
|
local newLabel
|
||||||
sPhone.header(sPhone.user)
|
sPhone.header(sPhone.user)
|
||||||
visum.align("center", " Set Label",false,3)
|
visum.align("center", " Set Label",false,3)
|
||||||
|
term.setCursorPos(w,1)
|
||||||
|
term.setBackgroundColor(sPhone.theme["header"])
|
||||||
|
term.setTextColor(sPhone.theme["headerText"])
|
||||||
|
write("X")
|
||||||
|
term.setBackgroundColor(sPhone.theme["backgroundColor"])
|
||||||
|
term.setTextColor(sPhone.theme["text"])
|
||||||
term.setCursorPos(2,5)
|
term.setCursorPos(2,5)
|
||||||
local newLabel = read()
|
while true do
|
||||||
|
newLabel,mouse,x,y = sPhone.read(nil,nil,nil,true)
|
||||||
|
if mouse then
|
||||||
|
if y == 1 and x == w then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
newLabel = newLabel:gsub("&", string.char(0xc2)..string.char(0xa7)) --yay colors
|
newLabel = newLabel:gsub("&", string.char(0xc2)..string.char(0xa7)) --yay colors
|
||||||
os.setComputerLabel(newLabel)
|
os.setComputerLabel(newLabel)
|
||||||
sPhone.winOk("Computer Label set")
|
sPhone.winOk("Computer Label set")
|
||||||
|
|
Loading…
Reference in a new issue