Guest User

Untitled

a guest
Feb 8th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. // registration//
  12.  
  13. if( index = localStorage.getItem('active__user') ){
  14. location.replace('user.html')
  15. }
  16.  
  17. signUpBtn.addEventListener('click', (event) => {
  18. event.preventDefault();
  19.  
  20. const email = document.getElementById('email');
  21. const fullName = document.getElementById('fullName');
  22. const userName = document.getElementById('userName');
  23. const phone = document.getElementById('phone')
  24. const pass = document.getElementById('pass');
  25.  
  26. let RegisterUsers = JSON.parse(localStorage.getItem('userInfo'))
  27.  
  28. if(!RegisterUsers) {
  29. RegisterUsers = [];
  30. }
  31. const userInfo = {
  32. email: email.value,
  33. fullName: fullName.value,
  34. userName: userName.value,
  35. phone: phone.value,
  36. pass: pass.value,
  37. }
  38. let lastIndex = RegisterUsers.push(userInfo) - 1;
  39.  
  40. localStorage.setItem('userInfo', JSON.stringify(userInfo));
  41. localStorage.setItem('active__user', lastIndex);
  42. });
  43.  
  44.  
  45. // log in //
  46.  
  47.  
  48. logInBtnFunc = () => {
  49. if(userName.value === userInfo.userName && pass.value === userInfo.pass) {
  50. location.replace('user.html');
  51. } else if ( userName.value === "admin" && pass.value === "123123") {
  52. location.replace('admin.html');
  53. }
  54. else {
  55. alert("Wrong Username or Password.")
  56. };
  57. };
  58. logInBtn.addEventListener('click', logInBtnFunc);
  59. </script>
  60.  
  61.  
  62.  
  63. <script id="jsbin-source-javascript" type="text/javascript">// registration//
  64.  
  65. if( index = localStorage.getItem('active__user') ){
  66. location.replace('user.html')
  67. }
  68.  
  69. signUpBtn.addEventListener('click', (event) => {
  70. event.preventDefault();
  71.  
  72. const email = document.getElementById('email');
  73. const fullName = document.getElementById('fullName');
  74. const userName = document.getElementById('userName');
  75. const phone = document.getElementById('phone')
  76. const pass = document.getElementById('pass');
  77.  
  78. let RegisterUsers = JSON.parse(localStorage.getItem('userInfo'))
  79.  
  80. if(!RegisterUsers) {
  81. RegisterUsers = [];
  82. }
  83. const userInfo = {
  84. email: email.value,
  85. fullName: fullName.value,
  86. userName: userName.value,
  87. phone: phone.value,
  88. pass: pass.value,
  89. }
  90. let lastIndex = RegisterUsers.push(userInfo) - 1;
  91.  
  92. localStorage.setItem('userInfo', JSON.stringify(userInfo));
  93. localStorage.setItem('active__user', lastIndex);
  94. });
  95.  
  96.  
  97. // log in //
  98.  
  99.  
  100. logInBtnFunc = () => {
  101. if(userName.value === userInfo.userName && pass.value === userInfo.pass) {
  102. location.replace('user.html');
  103. } else if ( userName.value === "admin" && pass.value === "123123") {
  104. location.replace('admin.html');
  105. }
  106. else {
  107. alert("Wrong Username or Password.")
  108. };
  109. };
  110. logInBtn.addEventListener('click', logInBtnFunc);</script></body>
  111. </html>
Add Comment
Please, Sign In to add comment