Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local button = {}
- local menus = {"signIn","home"}
- local menu = "signIn"
- local native = term.current()
- local corY,corY2 = 1,1
- local usercode,username,password,pastebinWin,signInWin,submitWin
- local eventsToggle = true
- fs.open("log","w")
- local w,h = term.getSize()
- local c,r,l = 'c','r','l'
- local deftxt, defback = colors.white,colors.lightGray
- --Console(temporary)
- function logCorTab(e)
- for i = 1,4 do
- term.setBackgroundColor(defback)
- term.setCursorPos(w-15,i)
- term.write(string.rep(" ",16))
- end
- if eventsToggle then
- corY = 1
- for i = 1,#e do
- draw(e[i],r,corY)
- corY = corY + 1
- end
- end
- end
- function logCor(words)
- if eventsToggle then
- draw(words,r,corY)
- corY2 = corY2+1
- end
- end
- function log(words)
- words = tostring(words)
- local h = fs.open("log","a")
- h.writeLine(words)
- h.close()
- end
- --WindowClasses (todo = betterscrollin, movable/draggable/resizable/scrollbarable windows)
- function writeLn(self,words,txtcol,backcol,x,y)
- local w,h = self.getSize()
- txtcol = txtcol or deftxt
- backcol = backcol or defback
- if x and y then
- self.setCursorPos(x,y)
- end
- self.setBackgroundColor(backcol)
- self.setTextColor(txtcol)
- self.write(words)
- local x,y = self.getCursorPos()
- self.setCursorPos(x-#words,y+1)
- end
- function clearWin(self,backcol)
- self.setBackgroundColor(backcol)
- self.clear()
- end
- function toggle(self,bVis)
- if bVis then
- self.setVisible(true)
- else
- end
- end
- --uWordsAPI/WebtoolsAPI
- function getColors()
- for i,v in pairs(colors) do
- if tonumber(v) then
- loadstring(i.."="..v)()
- end
- end
- grey = gray
- lightGrey = lightGray
- end
- function basics(e)
- if e[1] == "key" then
- if e[2] == keys.q then
- error()
- elseif e[2] == keys.leftAlt then
- shell.run("pastebin run NybMLEHL")
- elseif e[2] == keys.tab then
- if eventsToggle == true then
- eventsToggle = false
- else
- eventsToggle = true
- end
- logCorTab(e)
- elseif e[2] == keys.delete then
- menu = "home"
- updateMenus()
- end
- end
- end
- function hitbox(e,x,y,x2,y2,num,func,...)
- --takes events (e) and compares to box(x,y,x2,y2) to see if box had been clicked, if so run function
- if e[1] == "mouse_click" and e[2] == num and e[3] >= x and e[3] <= x2 and e[4] <= y and e[4] >=y2 then
- local returns = {func(...)}
- if returns then return returns end
- end
- end
- function clearScreen(backcol)
- term.setBackgroundColor(backcol)
- term.clear()
- term.setCursorPos(1,1)
- end
- function draw(words,x,y,txtcol,backcol)
- --put at top of file/program: local c,r,l = 'c','r','l'; local deftxt,defback
- local w,h = term.getSize()
- local offset = 0
- local writeLn
- words = tostring(words)
- words = words or " "
- if not (x and y) then
- x,y = term.getCursorPos()
- writeLn = true
- elseif not x then
- x,_ = term.getCursorPos()
- writeLn = true
- elseif not y then
- _,y = term.getCursorPos()
- writeLn = true
- end
- txtcol = txtcol or deftxt
- backcol = backcol or defback
- if not tonumber(x) then
- x = x:gsub(" ", "")
- if x:sub(1, 1) == "l" then
- if x:find("+") then
- offset = tonumber(x:sub(x:find("+") + 1))
- term.setCursorPos(1 + offset, y)
- else
- term.setCursorPos(1, y)
- end
- elseif x:sub(1, 1) == "c" then
- if x:find("+") then
- offset = tonumber(x:sub(x:find("+") + 1))
- term.setCursorPos(w/2 - #words/2 + 1 + offset, y)
- elseif x:find("-") then
- offset = tonumber(x:sub(x:find("-") + 1))
- term.setCursorPos(w/2 - #words/2 + 1 - offset, y)
- else
- term.setCursorPos(w/2 - #words/2 + 1, y)
- end
- elseif x:sub(1, 1) == "r" then
- if x:find("-") then
- offset = tonumber(x:sub(x:find("-") + 1))
- term.setCursorPos(w - #words+ 1 - offset, y)
- else
- term.setCursorPos(w - #words+ 1, y)
- end
- end
- else
- term.setCursorPos(x, y)
- end
- term.setTextColor(txtcol)
- term.setBackgroundColor(backcol)
- if writeLn then
- write(words..'\n')
- else
- write(words)
- end
- end
- --ButtonMethods
- function button.signIn(x,y,txtcol,backcol,bool)
- local userdetails
- term.setCursorPos(x,y)
- term.setTextColor(txtcol)
- term.setBackgroundColor(backcol)
- term.write("___________ ")
- term.setCursorPos(x,y)
- if not bool then
- userdetails = read()
- else
- userdetails = read("*")
- end
- if userdetails then return userdetails end
- end
- function button.authenticate(user,pass)
- if user and pass then
- log("received authent")
- log("Authenticated: "..user)
- log("Authenticated: "..pass)
- draw(string.rep(" ",70),1,h-1)
- draw(string.rep(" ",70),1,h)
- draw("Connecting to Pastebin...",1,h,yellow)
- local userkey = http.post(
- "http://pastebin.com/api/api_login.php",
- "api_option=login&"..
- "api_dev_key=996a06d80a378f151e589ac86c83e865&"..
- "api_user_name="..textutils.urlEncode(username).."&"..
- "api_user_password="..textutils.urlEncode(password)
- )
- local postdata = userkey.readAll()
- term.setTextColor(colors.red)
- log(postdata)
- userkey.close()
- if postdata:sub(1,3) == 'Bad' then
- usercode = nil
- log("Authentication Request Failed")
- draw(string.rep(" ",70),1,h-1)
- draw(string.rep(" ",70),1,h)
- draw("The Username or Password is incorrect,\nPlease try again...",1,h-1,red)
- username,password = nil,nil
- else
- log("Authentication Successful")
- usercode = postdata
- menu = "home"
- updateMenus()
- end
- else
- draw(string.rep(" ",70),1,h)
- draw(string.rep(" ",70),1,h-1)
- draw("Please fill all required fields with your Username and Password...",1,h-1,red)
- end
- end
- --==0-0==--
- getColors()
- username,password = nil,nil
- pastebinWin = window.create(native,1,2,16,5,false)
- signInWin = window.create(native,w-9,2,w,4,false)
- --submitWin =
- clearWin(pastebinWin,lightBlue)
- writeLn(pastebinWin," -New Paste",gray,lightBlue)
- writeLn(pastebinWin," -Upload file",gray,lightBlue)
- writeLn(pastebinWin," -Download file",gray,lightBlue)
- writeLn(pastebinWin," -Run Pastrami",gray,lightBlue)
- function updateMenus()
- if menu == "signIn" then
- clearScreen(lightGray)
- local signInBackCol,guestBackCol = white,lightBlue
- draw("--------------",c,5,lightBlue)
- draw("PastebinCC",c,6,white,defback)
- draw("--------------",c,7,lightBlue)
- draw("Username: ___________",c,9,grey)
- draw("Password: ___________",c,11,grey)
- draw(" Sign In ",'r-13',13,black,signInBackCol)
- draw(" Sign in as Guest ",1,1,white,guestBackCol)
- elseif menu == "home" then
- clearScreen(lightGray)
- paintutils.drawLine(1,1,w,1,lightBlue)
- paintutils.drawLine(1,2,w,2,blue)
- draw("Pastebin.com",l,1,white,lightBlue)
- paintutils.drawBox(2,4,w-1,h-1,white)
- draw("[new paste]",3,4,gray,white)
- --draw("[+] create new paste [^] trending pastes",2,3,white,blue)
- --draw("sign in|my pastebin|my profile|logout",r,2,white,lightBlue)
- draw(" sign in ",r,1,white,lightBlue)
- draw(" Submit ",'r-2',h,gray,lightBlue)
- pastebinWin.redraw()
- end
- end
- updateMenus()
- while menu == "signIn" do
- local e = {os.pullEvent()}
- logCorTab(e)
- local user = hitbox(e,w/2,9,w/2+10,9,1,button.signIn,w/2+1,9,black,defback)
- if user then username = user[1]; log("Username: "..username); end
- pass = hitbox(e,w/2,11,w/2+10,11,1,button.signIn,w/2+1,11,black,defback,'secret')
- if pass then password = pass[1]; log("Password: "..password); end
- hitbox(e,29,13,38,13,1,button.authenticate,username,password)
- basics(e)
- end
- while menu == "home" do
- local e = {os.pullEvent()}
- logCorTab(e)
- basics(e)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement