Advertisement
incinirate

LuaPayMock

Oct 11th, 2015
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.63 KB | None | 0 0
  1. local config = {
  2.     host = "http://lbc.my1337.xyz",
  3.     saveFile = ".lpcsave",
  4.     theme = {
  5.         bg = colors.white,
  6.         text = colors.black,
  7.         bar = colors.cyan,
  8.         bartext = colors.white,
  9.         altbg = colors.lightGray,
  10.         altbar = colors.blue,
  11.         altbartext = colors.lightGray,
  12.         alttext = colors.gray,
  13.         txtboxbg = colors.gray,
  14.         txtboxtxt = colors.white,
  15.         sideBarBg = colors.lightGray,
  16.         sideBarTxt = colors.white,
  17.     },
  18. }
  19.  
  20. local tx,ty = term.getSize()
  21. local txc,tyc = tx/2+1,ty/2+1
  22.  
  23. local currentAddress = ""
  24. local currentPin = ""
  25.  
  26. local json = {}
  27.  
  28. function deepcopy(orig)
  29.     local orig_type = type(orig)
  30.     local copy
  31.     if orig_type == 'table' then
  32.         copy = {}
  33.         for orig_key, orig_value in next, orig, nil do
  34.             copy[deepcopy(orig_key)] = deepcopy(orig_value)
  35.         end
  36.         setmetatable(copy, deepcopy(getmetatable(orig)))
  37.     else -- number, string, boolean, etc
  38.         copy = orig
  39.     end
  40.     return copy
  41. end
  42.  
  43. do
  44.     ------------------------------------------------------------------ utils
  45.     local controls = {["\n"]="\\n", ["\r"]="\\r", ["\t"]="\\t", ["\b"]="\\b", ["\f"]="\\f", ["\""]="\\\"", ["\\"]="\\\\"}
  46.  
  47.     local function isArray(t)
  48.         local max = 0
  49.         for k,v in pairs(t) do
  50.             if type(k) ~= "number" then
  51.                 return false
  52.             elseif k > max then
  53.                 max = k
  54.             end
  55.         end
  56.         return max == #t
  57.     end
  58.  
  59.     local whites = {['\n']=true; ['r']=true; ['\t']=true; [' ']=true; [',']=true; [':']=true}
  60.     function removeWhite(str)
  61.         while whites[str:sub(1, 1)] do
  62.             str = str:sub(2)
  63.         end
  64.         return str
  65.     end
  66.  
  67.     ------------------------------------------------------------------ encoding
  68.  
  69.     local function encodeCommon(val, pretty, tabLevel, tTracking)
  70.         local str = ""
  71.  
  72.         -- Tabbing util
  73.         local function tab(s)
  74.             str = str .. ("\t"):rep(tabLevel) .. s
  75.         end
  76.  
  77.         local function arrEncoding(val, bracket, closeBracket, iterator, loopFunc)
  78.             str = str .. bracket
  79.             if pretty then
  80.                 str = str .. "\n"
  81.                 tabLevel = tabLevel + 1
  82.             end
  83.             for k,v in iterator(val) do
  84.                 tab("")
  85.                 loopFunc(k,v)
  86.                 str = str .. ","
  87.                 if pretty then str = str .. "\n" end
  88.             end
  89.             if pretty then
  90.                 tabLevel = tabLevel - 1
  91.             end
  92.             if str:sub(-2) == ",\n" then
  93.                 str = str:sub(1, -3) .. "\n"
  94.             elseif str:sub(-1) == "," then
  95.                 str = str:sub(1, -2)
  96.             end
  97.             tab(closeBracket)
  98.         end
  99.  
  100.         -- Table encoding
  101.         if type(val) == "table" then
  102.             assert(not tTracking[val], "Cannot encode a table holding itself recursively")
  103.             tTracking[val] = true
  104.             if isArray(val) then
  105.                 arrEncoding(val, "[", "]", ipairs, function(k,v)
  106.                         str = str .. encodeCommon(v, pretty, tabLevel, tTracking)
  107.                     end)
  108.             else
  109.                 arrEncoding(val, "{", "}", pairs, function(k,v)
  110.                         assert(type(k) == "string", "JSON object keys must be strings", 2)
  111.                         str = str .. encodeCommon(k, pretty, tabLevel, tTracking)
  112.                         str = str .. (pretty and ": " or ":") .. encodeCommon(v, pretty, tabLevel, tTracking)
  113.                     end)
  114.             end
  115.             -- String encoding
  116.         elseif type(val) == "string" then
  117.             str = '"' .. val:gsub("[%c\"\\]", controls) .. '"'
  118.             -- Number encoding
  119.         elseif type(val) == "number" or type(val) == "boolean" then
  120.             str = tostring(val)
  121.         else
  122.             error("JSON only supports arrays, objects, numbers, booleans, and strings", 2)
  123.         end
  124.         return str
  125.     end
  126.  
  127.     function encode(val)
  128.         return encodeCommon(val, false, 0, {})
  129.     end
  130.  
  131.     function encodePretty(val)
  132.         return encodeCommon(val, true, 0, {})
  133.     end
  134.  
  135.     ------------------------------------------------------------------ decoding
  136.  
  137.     function parseBoolean(str)
  138.         if str:sub(1, 4) == "true" then
  139.             return true, removeWhite(str:sub(5))
  140.         else
  141.             return false, removeWhite(str:sub(6))
  142.         end
  143.     end
  144.  
  145.     function parseNull(str)
  146.         return nil, removeWhite(str:sub(5))
  147.     end
  148.  
  149.     local numChars = {['e']=true; ['E']=true; ['+']=true; ['-']=true; ['.']=true}
  150.     function parseNumber(str)
  151.         local i = 1
  152.         while numChars[str:sub(i, i)] or tonumber(str:sub(i, i)) do
  153.             i = i + 1
  154.         end
  155.         local val = tonumber(str:sub(1, i - 1))
  156.         str = removeWhite(str:sub(i))
  157.         return val, str
  158.     end
  159.  
  160.     function parseString(str)
  161.         local i,j = str:find('[^\\]"')
  162.         local s = str:sub(2, j - 1)
  163.  
  164.         for k,v in pairs(controls) do
  165.             s = s:gsub(v, k)
  166.         end
  167.         str = removeWhite(str:sub(j + 1))
  168.         return s, str
  169.     end
  170.  
  171.     function parseArray(str)
  172.         str = removeWhite(str:sub(2))
  173.  
  174.         local val = {}
  175.         local i = 1
  176.         while str:sub(1, 1) ~= "]" do
  177.             local v = nil
  178.             v, str = parseValue(str)
  179.             val[i] = v
  180.             i = i + 1
  181.             str = removeWhite(str)
  182.         end
  183.         str = removeWhite(str:sub(2))
  184.         return val, str
  185.     end
  186.  
  187.     function parseObject(str)
  188.         str = removeWhite(str:sub(2))
  189.  
  190.         local val = {}
  191.         while str:sub(1, 1) ~= "}" do
  192.             local k, v = nil, nil
  193.             k, v, str = parseMember(str)
  194.             val[k] = v
  195.             str = removeWhite(str)
  196.         end
  197.         str = removeWhite(str:sub(2))
  198.         return val, str
  199.     end
  200.  
  201.     function parseMember(str)
  202.         local k = nil
  203.         k, str = parseValue(str)
  204.         local val = nil
  205.         val, str = parseValue(str)
  206.         return k, val, str
  207.     end
  208.  
  209.     function parseValue(str)
  210.         local fchar = str:sub(1, 1)
  211.         if fchar == "{" then
  212.             return parseObject(str)
  213.         elseif fchar == "[" then
  214.             return parseArray(str)
  215.         elseif tonumber(fchar) ~= nil or numChars[fchar] then
  216.             return parseNumber(str)
  217.         elseif str:sub(1, 4) == "true" or str:sub(1, 5) == "false" then
  218.             return parseBoolean(str)
  219.         elseif fchar == "\"" then
  220.             return parseString(str)
  221.         elseif str:sub(1, 4) == "null" then
  222.             return parseNull(str)
  223.         end
  224.         return nil
  225.     end
  226.  
  227.     function json.decode(str)
  228.         str = removeWhite(str)
  229.         t = parseValue(str)
  230.         return t
  231.     end
  232.  
  233.     function decodeFromFile(path)
  234.         local file = assert(fs.open(path, "r"))
  235.         return json.decode(file.readAll())
  236.     end
  237. end
  238.  
  239. local glib = {}
  240.  
  241. function glib.center(t,y)
  242.     term.setCursorPos(txc-(#t/2),y)
  243.     term.write(t)
  244. end
  245.  
  246. function glib.spinner(x,y)
  247.     local invar = {"-","\\","|","/"}
  248.     while true do
  249.         for i=1,4 do
  250.             term.setCursorPos(x,y)
  251.             term.write(invar[i])
  252.             sleep(0.25)
  253.         end
  254.     end
  255. end
  256.  
  257. function glib.banner(y1,y2,col)
  258.     term.setBackgroundColor(col)
  259.     for i=y1,y2 do
  260.         term.setCursorPos(1,i)
  261.         term.write(string.rep(" ",tx))
  262.     end
  263. end
  264.  
  265. function glib.square(x1,x2,y1,y2,col)
  266.     term.setBackgroundColor(col)
  267.     for i=y1,y2 do
  268.         term.setCursorPos(x1,i)
  269.         term.write(string.rep(" ",x2-x1+1))
  270.     end
  271. end
  272.  
  273. local blib = {scene = {}}
  274.  
  275. function blib.newScene()
  276.     blib.scene = {}
  277. end
  278.  
  279. function blib.addButton(tx,x,y,px,py,cob,cot,callback)
  280.     if x=="c" then
  281.         x = txc - (#tx+px*2)/2
  282.     end
  283.     table.insert(blib.scene,{x,y,px,py,tx,cob,cot,callback})
  284. end
  285.  
  286. function blib.saveScene()
  287.     return deepcopy(blib.scene)
  288. end
  289.  
  290. function blib.loadScene(newScene)
  291.     blib.scene = newScene
  292. end
  293.  
  294. function blib.deployScene()
  295.     local bcheck = {}
  296.     for k,v in ipairs(blib.scene) do
  297.         term.setBackgroundColor(v[6])
  298.         term.setTextColor(v[7])
  299.         for i=1,v[4]*2+1 do
  300.             term.setCursorPos(v[1],v[2]+i-1)
  301.             term.write(string.rep(" ",#v[5]+(v[3]*2)))
  302.         end
  303.         term.setCursorPos(v[1]+v[3],v[2]+v[4])
  304.         term.write(v[5])
  305.         table.insert(bcheck, {v[1],v[2],v[1]+#v[5]+v[3]*2-1,v[2]+v[4]*2,k})
  306.     end
  307.     while true do
  308.         local e,p1,p2,p3 = os.pullEvent()
  309.         local success = false
  310.         if e=="mouse_click" then
  311.             local b,x,y = p1,p2,p3
  312.             --local bufferdebug = x..";"..y..": "
  313.             for k,v in ipairs(bcheck) do
  314.                 --bufferdebug = bufferdebug.."("..math.floor(v[1])..","..math.floor(v[2]).."-"..math.floor(v[3])..","..math.floor(v[4])..") "
  315.                 if x >= math.floor(v[1]) and x <= math.floor(v[3]) then
  316.                     if y >= math.floor(v[2]) and y <= math.floor(v[4]) then
  317.                         blib.scene[v[5]][8]()
  318.                         success = true
  319.                         break
  320.                     end
  321.                 end
  322.             end
  323.             --term.setCursorPos(1,ty)
  324.             --term.write(bufferdebug)
  325.         end
  326.         if success then break end
  327.     end
  328. end
  329.  
  330. function limitRead( nlim, cOverlay)
  331.     cOverlay=cOverlay or nil
  332.     local px,py = term.getCursorPos()
  333.     local txt = ""
  334.     local boxOffset = 0
  335.     local strPos = 1
  336.     term.setCursorBlink(true)
  337.     while true do
  338.         e,p1 = os.pullEvent()
  339.         if e=="key" then
  340.             local key = p1
  341.             if key==keys.left then
  342.                 if strPos>1 then
  343.                     strPos=strPos-1
  344.                     if strPos-boxOffset==0 then
  345.                         boxOffset=boxOffset-1
  346.                     end
  347.                 end
  348.             elseif key==keys.right then
  349.                 if strPos<=#txt then
  350.                     strPos=strPos+1
  351.                     if strPos-boxOffset>nlim then
  352.                         boxOffset=boxOffset+1
  353.                     end
  354.                 end
  355.             elseif key==keys.enter then
  356.                 break
  357.             elseif key==keys.backspace then
  358.                 if strPos~=1 then
  359.                     txt=txt:sub(1,strPos-2)..txt:sub(strPos,#txt)
  360.                     strPos=strPos-1
  361.                     if strPos-boxOffset==0 then
  362.                         boxOffset=boxOffset-1
  363.                     end
  364.                 end
  365.             elseif key==keys.delete then
  366.                 if strPos-1~=#txt then
  367.                     txt=txt:sub(1,strPos-1)..txt:sub(strPos+1,#txt)
  368.                 end
  369.             end
  370.         elseif e=="char" then
  371.             txt = txt:sub(1,strPos-1)..p1..txt:sub(strPos,#txt)
  372.             strPos=strPos+1
  373.             if strPos-1-boxOffset>=nlim then
  374.                 boxOffset=boxOffset+1
  375.             end
  376.         elseif e=="paste" then
  377.             txt = txt:sub(1,strPos-1)..p1..txt:sub(strPos,#txt)
  378.         end
  379.         term.setCursorPos(px,py)
  380.         write(string.rep(" ",nlim))
  381.         term.setCursorPos(px,py)
  382.  
  383.         if cOverlay==nil then
  384.             write(txt:sub(boxOffset+1,boxOffset+nlim))
  385.         else
  386.             write(string.rep(cOverlay,#txt):sub(boxOffset+1,nlim+boxOffset))
  387.         end
  388.         term.setCursorPos(px+strPos-1-boxOffset,py)
  389.     end
  390.     term.setCursorBlink(false)
  391.     return txt
  392. end
  393.  
  394. function httpCall(url,verify)
  395.     http.request(url)
  396.     while true do
  397.         local x = {os.pullEvent()}
  398.         local e = x[1]
  399.         table.remove(x,1)
  400.  
  401.         if e=="http_success" then
  402.             local get = x[2].readAll():match("[^%s]+")
  403.             if verify(get) then
  404.                 return true,get
  405.             end
  406.             break
  407.         elseif e=="http_failure" then
  408.             break
  409.         end
  410.     end
  411. end
  412.  
  413. function getInfo(x1,x2,y,label,colorsch,verify,over)
  414.     label = label or ""
  415.     local ubg = config.theme.bg
  416.     local utx = config.theme.text
  417.     if colorsch == "alt" then
  418.         ubg = config.theme.altbg
  419.         utx = config.theme.alttext
  420.     end
  421.     local stx = x1
  422.     local enx = x2
  423.     if verify then
  424.         enx = enx-1
  425.     end
  426.     if label ~= "" then
  427.         stx = x1+#label+1
  428.     end
  429.  
  430.     term.setCursorPos(x1,y)
  431.     term.setBackgroundColor(ubg)
  432.     term.setTextColor(utx)
  433.     term.write(label)
  434.  
  435.  
  436.     local get = ""
  437.     local function doIt()
  438.         term.setCursorPos(stx,y)
  439.         term.setBackgroundColor(config.theme.txtboxbg)
  440.         term.setTextColor(config.theme.txtboxtxt)
  441.         term.write(string.rep(" ",enx-stx+1))
  442.         term.setCursorPos(stx,y)
  443.         return limitRead(enx-stx+1,over)
  444.     end
  445.  
  446.     if verify then
  447.         --[[
  448.         verify = {
  449.         subdom = "/api/changePin"
  450.         exq = {
  451.         oldPin = "$INPUT$",
  452.         newPin = "$INPUT$",
  453.         address = "0000123412341234"
  454.     }
  455.         callback = function(inp)
  456.         if inp=="SUCCESS_PIN_CHANGED" then
  457.         return true
  458.     end
  459.         return false
  460.     end
  461.     }
  462.         ]]
  463.         local success = false
  464.         local reinp
  465.         term.setBackgroundColor(colors.orange)
  466.         term.setCursorPos(x2,y)
  467.         term.write(" ")
  468.         while not success do
  469.             reinp = doIt()
  470.             if verify.preprocess then
  471.                 reinp = verify.preprocess(reinp)    
  472.             end
  473.             local sbhost = config.host..verify.subdom.."?"
  474.             for k,v in pairs(verify.exq) do
  475.                 if v=="$INPUT$" then
  476.                     v = tostring(reinp)
  477.                 end
  478.                 sbhost = sbhost..tostring(k).."="..v.."&"
  479.             end
  480.             sbhost = sbhost:sub(1,#sbhost-1)
  481.             term.setBackgroundColor(ubg)
  482.             term.setTextColor(utx)
  483.             parallel.waitForAny(function() glib.spinner(x2,y) end, function()
  484.                     success = httpCall(sbhost,verify.callback)
  485.                 end)
  486.             if not success then
  487.                 term.setCursorPos(x2,y)
  488.                 term.setBackgroundColor(colors.red)
  489.                 term.write(" ")
  490.             end
  491.         end
  492.         term.setCursorPos(x2,y)
  493.         term.setBackgroundColor(colors.green)
  494.         term.write(" ")
  495.         return reinp
  496.     else
  497.         return doIt()    
  498.     end
  499. end
  500.  
  501. function getInfoPrerender(x1,x2,y,label,colorsch,verify)
  502.     label = label or ""
  503.     local ubg = config.theme.bg
  504.     local utx = config.theme.text
  505.     if colorsch == "alt" then
  506.         ubg = config.theme.altbg
  507.         utx = config.theme.alttext
  508.     end
  509.     local stx = x1
  510.     local enx = x2
  511.     if verify then
  512.         enx = enx-1
  513.     end
  514.     if label ~= "" then
  515.         stx = x1+#label+1
  516.     end
  517.  
  518.     term.setCursorPos(x1,y)
  519.     term.setBackgroundColor(ubg)
  520.     term.setTextColor(utx)
  521.     term.write(label)
  522.  
  523.     term.setCursorPos(stx,y)
  524.     term.setBackgroundColor(config.theme.txtboxbg)
  525.     term.setTextColor(config.theme.txtboxtxt)
  526.     term.write(string.rep(" ",enx-stx+1))
  527.  
  528.     if verify then
  529.         term.setBackgroundColor(colors.orange)
  530.         term.setCursorPos(x2,y)
  531.         term.write(" ")    
  532.     end
  533. end
  534.  
  535. local pages = {}
  536. pages.nextAction = ""
  537.  
  538. function pages.setup()
  539.     term.setBackgroundColor(config.theme.bg)
  540.     term.clear()
  541.     term.setBackgroundColor(config.theme.altbg)
  542.     term.setTextColor(config.theme.alttext)
  543.     glib.banner(tyc-3,tyc+3,config.theme.altbg)
  544.     glib.center("Please enter LBC account information:",tyc-2)
  545.  
  546.     getInfoPrerender(2, tx-1,tyc+2,"PIN:","alt",true)
  547.  
  548.     local inpAD, inpPIN
  549.  
  550.     inpAD = getInfo(2,tx-1,tyc,"LBC Address:","alt",{
  551.             subdom = "/api/checkBalance",
  552.             exq = {
  553.                 address = "$INPUT$",        
  554.             },
  555.             preprocess = function(inp)
  556.                 return inp:gsub("%-","")            
  557.             end,
  558.             callback = function(inp)
  559.                 if tonumber(inp) then
  560.                     return true
  561.                 end
  562.             end
  563.         })
  564.  
  565.     inpPIN = getInfo(2, tx-1, tyc+2,"PIN:","alt",{
  566.             subdom = "/api/changePin",
  567.             exq = {
  568.                 oldPin = "$INPUT$",
  569.                 newPin = "$INPUT$",
  570.                 address = inpAD
  571.             },
  572.             callback = function(inp)
  573.                 if inp=="SUCCESS_PIN_CHANGED" then
  574.                     return true
  575.                 end
  576.                 return false
  577.             end
  578.         },"*")
  579.  
  580.     local handle = fs.open(config.saveFile,"w")
  581.     handle.write(inpAD..";"..inpPIN)
  582.     handle.close()
  583.     currentAddress = inpAD
  584.     pages.main()
  585. end
  586.  
  587. function pages.create()
  588.     term.setBackgroundColor(config.theme.bg)
  589.     term.clear()
  590.     term.setBackgroundColor(config.theme.altbg)
  591.     term.setTextColor(config.theme.alttext)
  592.     glib.banner(tyc-3,tyc+3,config.theme.altbg)
  593.     local succ,info = httpCall(config.host.."/api/newAddress",function()
  594.             return true
  595.         end)
  596.     local split = info:find("%;")
  597.     local addr = info:sub(1,split-1)
  598.     local pin = info:sub(split+1)
  599.     local addru = addr:sub(1,4).."-"..addr:sub(5,8).."-"..addr:sub(9,12).."-"..addr:sub(13,16)
  600.     glib.center("Your Account Information: "..addru,tyc-2)
  601.     glib.center("PIN: "..pin,tyc)
  602.     local npin = getInfo(2,tx-1,tyc+2,"New PIN (Empty to Keep Old):","alt", {
  603.             subdom = "/api/changePin",
  604.             exq = {
  605.                 oldPin = pin,
  606.                 newPin = "$INPUT$",
  607.                 address = addr,
  608.             },
  609.             callback = function(inp)
  610.                 if inp=="SUCCESS_PIN_CHANGED" then
  611.                     return true
  612.                 end
  613.                 return false
  614.             end,
  615.             preprocess = function(inp)
  616.                 if inp=="" then
  617.                     return pin
  618.                 else
  619.                     return inp
  620.                 end
  621.             end,
  622.         })
  623.     local handle = fs.open(config.saveFile,"w")
  624.     handle.write(addr..";"..npin)
  625.     handle.close()
  626.     currentAddress = addr
  627.     pages.nextAction = "main"
  628. end
  629.  
  630. function pages.first()
  631.     term.setBackgroundColor(config.theme.bg)
  632.     term.clear()
  633.     term.setBackgroundColor(config.theme.altbg)
  634.     term.setTextColor(config.theme.alttext)
  635.     glib.banner(tyc-3,tyc+3,config.theme.altbg)
  636.     glib.center("Welcome to LPC",tyc-2)
  637.  
  638.     blib.newScene()
  639.     --blib.addButton(tx,x,y,px,py,cob,cot)
  640.     blib.addButton("Account  Login","c",tyc,0,0,config.theme.txtboxbg,config.theme.txtboxtxt,function()
  641.             pages.setup()
  642.         end)
  643.     blib.addButton("Create Account","c",tyc+2,0,0,config.theme.txtboxbg,config.theme.txtboxtxt,function()
  644.             pages.create()
  645.         end)
  646.    
  647.     blib.addButton("X",tx,1,0,0,colors.red,colors.white,function() pages.nextAction = "exitApp" end)
  648.  
  649.     blib.deployScene()
  650. end
  651.  
  652. function pages.main()
  653.     term.setBackgroundColor(config.theme.bg)
  654.     term.clear()
  655.     glib.banner(1,3,config.theme.bar)
  656.     glib.center("Loading...",2)
  657.     local succ,balance = httpCall(config.host.."/api/checkBalance?address="..currentAddress,function() return true end)
  658.     term.setTextColor(config.theme.bartext)
  659.     glib.center("Your current balance is "..balance.."LBC",2)
  660.  
  661.     blib.newScene()
  662.     --blib.addButton(tx,x,y,px,py,cob,cot,callback)
  663.     blib.addButton("Refresh",1,ty,txc-4,0,colors.gray,colors.white,function()
  664.             glib.banner(1,3,config.theme.bar)
  665.             parallel.waitForAny(function() glib.spinner(txc,2) end, function()
  666.                     term.setBackgroundColor(config.theme.bar)
  667.                     term.setTextColor(config.theme.bartext)
  668.                     local succ,balance = httpCall(config.host.."/api/checkBalance?address="..currentAddress,function() return true end)
  669.                     glib.center("Your current balance is "..balance.."LBC",2)
  670.                 end)
  671.         end)
  672.  
  673.     --[[blib.addButton("Sign out",tx-8,1,0,0,config.theme.altbar,config.theme.altbartext,function()
  674.             fs.delete(config.saveFile)
  675.             currentAddress = ""
  676.             currentPin = ""
  677.             pages.nextAction = "first"
  678.         end)]]
  679.  
  680.     blib.addButton("X",tx,1,0,0,colors.red,colors.white,function() pages.nextAction = "exitApp" end)
  681.    
  682.     blib.addButton(">",1,(ty-3)/2+2,0,1,config.theme.sideBarBg,config.theme.sideBarTxt,function()
  683.             local oldScene = blib.saveScene()
  684.             term.setBackgroundColor(config.theme.sideBarBg)
  685.             for i=1,16,2.5 do
  686.                 for j=4,ty-1 do
  687.                     term.setCursorPos(1,j)
  688.                     term.write(string.rep(" ",i))
  689.                 end
  690.                 sleep(0)
  691.             end
  692.            
  693.             local menuActions = {
  694.                 {"Sign Out",function()
  695.                     fs.delete(config.saveFile)
  696.                     currentAddress = ""
  697.                     currentPin = ""
  698.                     pages.nextAction = "first"
  699.                 end,ty-2}
  700.             }
  701.            
  702.             blib.newScene()
  703.            
  704.             local regCount = 0
  705.             for k,v in ipairs(menuActions) do
  706.                 blib.addButton(v[1],9-(#v[1]/2),v[3] or regCount*2+3,0,0,config.theme.sideBarBg,config.theme.sideBarTxt,v[2])
  707.                 if v[3] then regCount = regCount+1 end
  708.             end
  709.             blib.addButton("<",16,(ty-3)/2+2,0,1,config.theme.sideBarBg,config.theme.sideBarTxt,function() glib.banner(4,ty-1,config.theme.bg) end)
  710.            
  711.             blib.deployScene()
  712.             blib.loadScene(oldScene)
  713.         end)
  714.    
  715.     while pages.nextAction == "" do
  716.         blib.deployScene()
  717.     end
  718. end
  719.  
  720. function pageMan()
  721.     while pages.nextAction~="exitApp" do
  722.         local tstore = pages.nextAction
  723.         pages.nextAction=""
  724.         pages[tstore]()
  725.     end
  726. end
  727.  
  728. local success = false
  729. if fs.exists(config.saveFile) then
  730.     local handle = fs.open(config.saveFile,"r")
  731.     local info = handle.readAll()
  732.     handle.close()
  733.     local semi = info:find(";")
  734.     if semi then
  735.         local addr = info:sub(1,semi-1)
  736.         local pin = info:sub(semi+1)
  737.         if #addr==16 then
  738.             success = httpCall(config.host.."/api/changePin?address="..addr.."&oldPin="..pin.."&newPin="..pin,function(get)
  739.                     if get=="SUCCESS_PIN_CHANGED" then
  740.                         return true
  741.                     end
  742.                 end)
  743.             if success then
  744.                 currentAddress = addr
  745.                 currentPin = pin
  746.                 pages.nextAction = "main"
  747.             end
  748.         end
  749.     end
  750. end
  751. if not success then
  752.     pages.nextAction = "first"
  753. end
  754.  
  755. pageMan()
  756. term.setBackgroundColor(colors.black)
  757. term.setTextColor(colors.white)
  758. term.clear()
  759. glib.center("Thank you for using LPC!",2)
  760. term.setCursorPos(1,4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement