Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ugapi")
- os.loadAPI("logapi")
- local protocol = ""
- rednet.open(logapi.getModemSide())
- ugapi.fadecolors(0.1,{"black","lightGray","lightBlue","blue"})
- local makelogin = ugapi.newButton(" Create Account",5,8,16,3,colors.white,colors.green,colors.gray)
- local remlogin = ugapi.newButton(" Delete Account",31,8,16,3,colors.white,colors.red,colors.gray)
- local w,h = term.getSize()
- function gui()
- term.setBackgroundColor(colors.blue)
- term.clear()
- makelogin:draw()
- remlogin:draw()
- paintutils.drawLine(1, 1, w, 1, colors.lightBlue)
- term.setCursorPos(1,1)
- write("LogSYS - Client")
- end
- function getCreds(title)
- paintutils.drawBox(
- (w/2) - 9, (h/2) - 2, (w/2)+12, (h/2)+5,
- colors.black)
- paintutils.drawFilledBox(
- (w/2) - 10, (h/2) - 3, (w/2)+11, (h/2)+4,
- colors.lightBlue)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.white)
- paintutils.drawLine((w/2)-10,(h/2)-3,(w/2)+11,(h/2)-3)
- term.setCursorPos((w/2)-10,(h/2)-3)
- write(title)
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos((w/2)-10,(h/2)-2)
- write("Press enter twice to")
- ugapi.writexy("skip.",(w/2)-10,(h/2)-1)
- term.setCursorPos((w/2)-10,(h/2)+1)
- write("User: ")
- term.setBackgroundColor(colors.gray)
- write(string.rep(" ",14))
- term.setCursorPos((w/2)-10,(h/2)+3)
- term.setBackgroundColor(colors.lightBlue)
- write("Pass: ")
- term.setBackgroundColor(colors.gray)
- write(string.rep(" ",14))
- term.setCursorPos((w/2)-4,(h/2)+1)
- local uname = read()
- term.setCursorPos((w/2)-4,(h/2)+3)
- local upass = read("*")
- return uname, upass
- end
- function notify(title,txt,txtone,txttwo)
- paintutils.drawBox(
- (w/2) - 9, (h/2) - 2, (w/2)+12, (h/2)+2,
- colors.black)
- paintutils.drawFilledBox(
- (w/2) - 10, (h/2) - 3, (w/2)+11, (h/2)+1,
- colors.lightBlue)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.white)
- paintutils.drawLine((w/2)-10,(h/2)-3,(w/2)+11,(h/2)-3)
- term.setCursorPos((w/2)-10,(h/2)-3)
- write(title)
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos((w/2)-10,(h/2)-2)
- write(txt)
- term.setCursorPos((w/2)-10,(h/2)-1)
- write(txtone)
- term.setCursorPos((w/2)-10,(h/2))
- write(txttwo)
- os.pullEvent("key")
- end
- function areYouSure(title)
- paintutils.drawBox(
- (w/2) - 9, (h/2) - 2, (w/2)+12, (h/2)+2,
- colors.black)
- paintutils.drawFilledBox(
- (w/2) - 10, (h/2) - 3, (w/2)+11, (h/2)+1,
- colors.lightBlue)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.white)
- paintutils.drawLine((w/2)-10,(h/2)-3,(w/2)+11,(h/2)-3)
- term.setCursorPos((w/2)-10,(h/2)-3)
- write(title)
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos((w/2)-10,(h/2)-2)
- write("Are you sure?")
- local opts = {"Yes","No"}
- local selop = 2
- local function mdraw()
- for i = 1, #opts do
- term.setCursorPos( (w/2)-6 + ((i-1)*7),(h/2))
- if(i == selop)then
- write("[ " .. opts[i] .. " ]")
- else
- write(" " .. opts[i] .. " ")
- end
- end
- end
- local inmenu = true
- mdraw()
- while inmenu do
- ev = {os.pullEvent()}
- if(ev[1] == "key")then
- if(ev[2] == keys.left and selop > 1)then
- selop = selop - 1
- mdraw()
- end
- if(ev[2] == keys.right and selop < #opts)then
- selop = selop + 1
- mdraw()
- end
- if(ev[2] == keys.enter)then
- inmenu = false
- return selop
- end
- end
- end
- end
- local function createLogin()
- local name, pass = getCreds("Create Login")
- gui()
- if(name == "" and pass == "")then gui() return false end
- local make = areYouSure("Create Account")
- if(make == 1)then
- local accres = logapi.createLogin(protocol,name,pass)
- if(accres == "username-taken")then
- notify("Account Creation","Account username","already in use.","")
- gui()
- return false
- elseif(accres == "no-connection")then
- notify("Account Creation","No connection to the","server.","")
- gui()
- return false
- elseif(accres == true)then
- notify("Account Creation","Account created: ",name,"")
- gui()
- return true
- end
- else
- gui()
- return false
- end
- end
- local function remLogin()
- local name, pass = getCreds("Delete Login")
- gui()
- if(name == "" and pass == "")then gui() return false end
- local make = areYouSure("Delete Account")
- if(make == 1)then
- local accres = logapi.deleteLogin(protocol,name,pass)
- if(accres == false)then
- notify("Account deletion","Failed to delete,","wrong username or","wrong password.")
- gui()
- return false
- elseif(accres == "no-connection")then
- notify("Account deletion","No connection to the","server.","")
- gui()
- return false
- elseif(accres == true)then
- notify("Account deletion","Account deleted: ",name,"")
- gui()
- return true
- end
- else
- gui()
- return false
- end
- end
- gui()
- makelogin:onPress(createLogin)
- remlogin:onPress(remLogin)
- local inprog = true
- while inprog do
- ev = {os.pullEvent()}
- makelogin:update(ev)
- remlogin:update(ev)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement