Advertisement
zeke

Untitled

Jan 16th, 2013
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.18 KB | None | 0 0
  1. local devKey = "3575e50cc6635311078014a550bc3f9f"
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. -- limit read function
  5. local function limitRead(limX, rChar)
  6. term.setCursorBlink(true)
  7. local origX, origY = term.getCursorPos()
  8. local returnString = ""
  9. while true do
  10.   local xPos, yPos = term.getCursorPos()
  11.   local event, p1, p2 = os.pullEvent()
  12.   if event == "char" then
  13.    returnString = returnString..p1
  14.    if not rChar then
  15.     if not limX then
  16.          term.setTextColor(colors.blue)
  17.          write(p1)
  18.     else
  19.          if string.len(returnString) >= limX then
  20.           term.setTextColor(colors.blue)
  21.           term.setCursorPos(origX, origY)
  22.           write(string.sub(returnString, (string.len(returnString)-limX)+1))
  23.          elseif string.len(returnString) < limX then
  24.           term.setTextColor(colors.blue)
  25.           write(p1)
  26.          end
  27.     end
  28.    else
  29.     if not limX then
  30.          term.setTextColor(colors.blue)
  31.          write(rChar)
  32.     else
  33.          if string.len(returnString) >= limX then
  34.           term.setTextColor(colors.blue)
  35.           term.setCursorPos(origX, origY)
  36.           write(string.rep(rChar, limX))
  37.          elseif string.len(returnString) < limX then
  38.           term.setTextColor(colors.blue)
  39.           write(rChar)
  40.          end
  41.     end
  42.    end
  43.   elseif event == "key" and p1 == 14 then --backspace
  44.    returnString = string.sub(returnString, 1, (string.len(returnString))-1)
  45.    term.setCursorPos(xPos-1,yPos)
  46.    term.setTextColor(colors.blue)
  47.    write(" ")
  48.    term.setCursorPos(origX, origY)
  49.    if string.len(returnString) >= limX then
  50.     if not rChar then
  51.          term.setTextColor(colors.blue)
  52.          write(string.sub(returnString, (string.len(returnString)-limX)+1))
  53.     else
  54.          term.setTextColor(colors.blue)
  55.          write(string.rep(rChar,limX))
  56.     end
  57.    else
  58.     if not rChar then
  59.          term.setTextColor(colors.blue)
  60.          write(returnString)
  61.     else
  62.          term.setTextColor(colors.blue)
  63.          write(string.rep(rChar, string.len(returnString)))
  64.     end
  65.    end
  66.   elseif event == "key" and p1 == 15 then --tab
  67.    break
  68.   elseif event == "key" and p1 == 28 then --enter
  69.    break
  70.   end
  71. end
  72. term.setCursorBlink(false)
  73. return returnString
  74. end
  75. -- End limitRead() --
  76.  
  77. -- Start loginScript() --
  78. local function loginScript()
  79. paintutils.drawLine(10,6,40,6, colors.blue)
  80. term.setCursorPos(10, 6)
  81. term.setTextColor(colors.white)
  82. term.setBackgroundColor(colors.blue)
  83. write("Please login")
  84. for i = 1, 7 do
  85.   paintutils.drawLine(10, 6 + i, 40, 6 + i, colors.lightGray)
  86. end
  87. local loginObjects = {
  88.   {name = "Username:",
  89.   nameX = 11,
  90.   nameY = 9,
  91.   color = colors.black,
  92.   BGcolor = colors.lightGray},
  93.   {name = "Username:             ",
  94.   nameX = 21,
  95.   nameY = 9,
  96.   color = colors.white,
  97.   BGcolor = colors.white},
  98.   {name = "Password:",
  99.   nameX = 11,
  100.   nameY = 11,
  101.   color = colors.black,
  102.   BGcolor = colors.lightGray},
  103.   {name = "Password:             ",
  104.   nameX = 21,
  105.   nameY = 11,
  106.   color = colors.white,
  107.   BGcolor = colors.white}
  108.   }
  109. for i = 1, #loginObjects do
  110.   term.setCursorPos(loginObjects[i].nameX, loginObjects[i].nameY)
  111.   term.setTextColor(loginObjects[i].color)
  112.   term.setBackgroundColor(loginObjects[i].BGcolor)
  113.   write(loginObjects[i].name)
  114. end
  115.  
  116. term.setCursorPos(22, 9)
  117. while true do
  118.   username = limitRead(16)
  119.   if username ~= "TEMP_USER" then
  120.    print(username)
  121.    break
  122.   end
  123. end
  124. term.setCursorPos(22, 11)
  125. while true do
  126.   password = limitRead(16, "*")
  127.   if password ~= "TEMP_PASSWORD" then
  128.    print(password)
  129.    break
  130.   end
  131. end
  132. local response = http.post(
  133.          "http://pastebin.com/api/api_login.php", "api_dev_key="..textutils.urlEncode(devKey).."&api_user_name="..textutils.urlEncode(username).."&api_user_password="..textutils.urlEncode(password)
  134.          ).readAll()
  135. local badRequests = {
  136.   "Bad API request, invalid login",
  137.   "Bad API request, account not active"
  138.   }
  139. if response then
  140.   term.setCursorPos(1,1)
  141.   term.setTextColor(colors.white)
  142.   print(response)
  143.   if sResponse == badRequests[1] then
  144.    term.setCursorPos(11,7)
  145.    term.setBackgroundColor(colors.lightGray)
  146.    term.setTextColor(colors.red)
  147.    write("Invalid login!")
  148.   end
  149. end
  150. end
  151. loginScript()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement