Guest User

Untitled

a guest
Dec 24th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. function controller()
  2. {
  3. drawLoginPage();
  4. document.getElementById("enter").onclick = function()
  5. {
  6. const USER = document.getElementById("username").value;
  7. const PASSWORD = document.getElementById("password").value;
  8. if (USER == '' || PASSWORD == '')
  9. alert("Wrong login or password");
  10. else {
  11. window.localStorage.removeItem('userIsFind');
  12. findTheUser(USER, PASSWORD);
  13. let FindUser = localStorage['userIsFind'] || "false";
  14. if (FindUser == "true")
  15. {
  16. document.getElementById("loginFormId").remove();
  17. createStorePageForUser(Log);
  18. }
  19. else alert("Wrong login or password");
  20. }
  21. }
  22. }
  23.  
  24. function findTheUser(Log, Pas)
  25. {
  26. fetch("Users.json")
  27. .then(function(response)
  28. {
  29. return response.json();
  30. })
  31. .then(function(data)
  32. {
  33. let currentUser = 0;
  34. while ( currentUser < data.length && (data[currentUser].username != Log && data[currentUser].password != Pas )) currentUser++;
  35. localStorage['userIsFind'] = String(currentUser != data.length);
  36. });
  37. }
Add Comment
Please, Sign In to add comment