Advertisement
Guest User

creacompte

a guest
Jun 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.82 KB | None | 0 0
  1. local args = {...}
  2.  
  3. if not fs.exists("arcui") or args[1] == "true" then
  4.    print("Downloading arcUI...")
  5.    shell.run("pastebin get NuZUGEmn arcui")
  6. end
  7.  
  8. os.loadAPI("arcui")
  9.  
  10. if not fs.exists("json") or args[1] == "true" then
  11.    print("Downloading json...")
  12.    shell.run("pastebin get 4nRg9CHU json")
  13. end
  14.  
  15. os.loadAPI("json")
  16.  
  17. local monX, monY = term.getSize()
  18. local PASSWORD = nil
  19. local USERNAME = nil
  20.  
  21.  
  22. function db()
  23.     url = "http://r3dsky.minesylv.be/bank/api.php?action=register&user="..USERNAME.."&password="..PASSWORD
  24.     db = http.get(url).readAll()
  25.     obj = json.decode(db)
  26. end
  27.  
  28.  
  29. function creacompte(monX, monY)
  30.     local monX, monY = term.getSize()
  31.     arcui.drawWindow("Création d'un nouveau compte bancaire ",false)
  32.     arcui.drawLabel('Name',2,3,"Nom du compte",colors.grey)
  33.     arcui.drawTextbox('NAME',2,4,monX / 2 - 9 ,"ex:Michelin")
  34.  
  35.   arcui.drawLabel('Firstname',30,3,"Prénom du compte",colors.grey)
  36.   arcui.drawTextbox('FIRSTNAME',30,4,40,"ex:Pascal")
  37.  
  38.  
  39.     arcui.drawLabel('PASS',2,6,"Définir un code PIN",colors.grey)
  40.     arcui.drawTextbox('PASSWORD',2,7,monX / 2 - 9 ,"ex:1234")
  41.  
  42.     arcui.drawLabel('PASSCONFIRM',2,9,"Confirmer le code PIN",colors.grey)
  43.     arcui.drawTextbox('PASSWORDCONFIRM',2,10,monX / 2 - 9 ,"ex:1234")
  44.  
  45.     arcui.drawButton("confirm_btn", 1, monY, monX, monY, colors.green, "Valider le compte")
  46. end
  47.  
  48. function crea()
  49.     while true do
  50.         event, a1, a2, a3 = os.pullEvent()
  51.  
  52.         if a1 == "PASSWORD" then
  53.             if a2 == "" then
  54.               --Do nothing
  55.             elseif not tonumber(a2) then
  56.                 arcui.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  57.                 arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  58.                 arcui.changeValue("PASSWORD", "value", "")
  59.             elseif #a2 ~= 4 then
  60.                 arcui.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit faire 4 chiffres !")
  61.                 arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  62.                 arcui.changeValue("PASSWORD", "value", "")
  63.             else
  64.                 PASSWORD = tonumber(a2)
  65.             end
  66.  
  67.       elseif a1 == "PASSWORDCONFIRM" then
  68.           if a2 == "" then
  69.               --Do nothing
  70.             elseif not tonumber(a2) then
  71.                 arcui.openDialog("PASSWORD_dialog", "Code invalide", " Le code doit être composé de chiffres !")
  72.                 arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  73.                 arcui.changeValue("PASSWORD", "value", "")
  74.             else
  75.                 PASSWORDCONFIRM = tonumber(a2)
  76.             end
  77.  
  78.       elseif a1 == "NAME" then
  79.             if a2 == "" then
  80.                   --Do nothing
  81.             elseif #a2 <= 4 then
  82.                   arcui.openDialog("USERNAME_dialog", "Nom invalide", " Le nom du compte doit faire plus de 4 lettres.")
  83.               arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  84.               arcui.changeValue("USERNAME", "value", "")
  85.             else
  86.                 NAME = a2
  87.             end
  88.  
  89.       elseif a1 == "FIRSTNAME" then
  90.           if a2 == "" then
  91.              --Do nothing
  92.           elseif #a2 <= 4 then
  93.               arcui.openDialog("USERNAME_dialog", "Prénom invalide", " Le nom du compte doit faire plus de 4 lettres.")
  94.               arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  95.               arcui.changeValue("FIRSTNAME", "value", "")
  96.             else
  97.                 FIRSTNAME = a2
  98.             end
  99.  
  100.       elseif event == "button_clicked" then
  101.             if a1 == "confirm_btn" then
  102.                 if not PASSWORD then
  103.                     arcui.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un code PIN !")
  104.                     arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  105.                 elseif not NAME then
  106.                     arcui.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un nom de compte !")
  107.                     arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  108.                 elseif not FIRSTNAME then
  109.                   arcui.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer un prénom de compte !")
  110.                   arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  111.             elseif PASSWORDCONFIRM ~= PASSWORD then
  112.                   arcui.openDialog("confirm_dialog", "Quelque chose manque..", " Vous devez entrer le même code PIN !")
  113.                   arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  114.             else
  115.                     rep = arcui.openDialog("confirm_dialog", "Sauvegarder le compte", " Voulez-vous vraiment enregistrer ce compte ?")
  116.                     arcui.redrawWindow("Création d'un nouveau compte bancaire ")
  117.  
  118.                 end
  119.             end
  120.         end
  121.     end
  122. end
  123.  
  124. parallel.waitForAll(crea, creacompte, arcui.eventHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement