Guest User

Untitled

a guest
Sep 8th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. var BEModule, UIModule, Controller;
  2.  
  3. BEModule = (function(){
  4. var account, allAccounts, loadRegistration, allocationOfData, checkValidity;
  5. var iterator = 0;
  6. account = function(username, password){
  7. this.username = username;
  8. this.password = password;
  9. }
  10.  
  11. allAccounts = {
  12. username: {
  13. admin: [],
  14. account:[],
  15. isFlagged: [],
  16. failedLoginAttempts: [],
  17. isTerminated:[]
  18. },
  19.  
  20. password: {
  21. admin:[],
  22. account:[]
  23.  
  24. }
  25. }
  26.  
  27. return {
  28.  
  29. loadRegistration: function(classLists){
  30. if(classLists.contains('sign-up')){
  31. closeRegistration('sign-up');
  32. allocationOfData('sign-up')}
  33. else {
  34. closeRegistration('log-in');
  35. (classLists.contains('log-in'))
  36. }
  37. },
  38.  
  39. accountDataExecution = function(){
  40. var username, password,loginAttempts, canLogin, accountExists;
  41. document.getElementById('submit-button').addEventListener('click', function(){
  42. username = document.getElementById('username').value;
  43. password = document.getElementById('password').value;
  44. accountExists = allAccounts.username['account'].indexOf(username);
  45. if(allAccounts.username['isFlagged'][accountExists] === false){
  46. if(registrationtype === 'sign-up'){
  47. var newRegistration;
  48. newRegistration = new account(username, password);
  49. console.log(newRegistration);
  50. checkValidity(newRegistration, 'account');
  51. } else {
  52. // If it is not sign-up then it is log-in
  53. var existingAccounts;
  54. if(accountExists != -1){ // if the account exists
  55. existingAccounts = allAccounts.username['account'].indexOf(username);
  56. if(password === allAccounts.password['account'][existingAccounts]){
  57. allAccounts.username['failedLoginAttempts'][existingAccounts] = 0;
  58. // Relay to the console the report of the account (if it is logged in)
  59. console.log('You have logged into the account ' + username);
  60. // ** Login to the account / open access to it ** (make a function that allows access) //
  61. } else if(password !== allAccounts.password['account'][accountExists]){
  62. var failedLoginAttempts;
  63. failedLoginAttempts = allAccounts.username['failedLoginAttempts'][existingAccounts];
  64. //Iterates the failed login attempts of the account.
  65. failedLoginAttempts++;
  66. //Relay report to the console (artifical)
  67. console.log('You have entered the incorrect password. ' + failedLoginAttempts + ' / 5 times. You have ' + 5 - failedLoginAttempts + 'remaining.');
  68. if(failedLoginAttempts === 5){
  69. /*canLogin === false; <-- Create into a more richer return */
  70. allAccounts.username['isFlagged'][accountExists] = true;
  71. //Relay to the console the report of the account.
  72. console.log('All access to this account has been prohibited, until further review.');
  73. }
  74. }
  75. }
  76. }
  77. } else {
  78. // account is flagged.
  79. console.log('Your account is currently flagged.');
  80. }
  81. });
  82. },
  83.  
  84.  
  85.  
  86.  
  87. checkValidity = function(account, typeOfAccount){
  88. var properPasswordLength,containsLetters,minimumUserNameLength;
  89. properPasswordLength = account.password.length >= 8;
  90. containsLetters = account.username.length != -1;
  91. minimumUserNameLength = account.username.length >= 3;
  92. if(properPasswordLength && containsLetters && minimumUserNameLength ){
  93. // Check if this account is existing
  94. if((allAccounts.username[typeOfAccount].indexOf(account.username)) === -1){
  95. // Publish the account to the object containing it.
  96. allAccounts.username[typeOfAccount].push(account.username);
  97. allAccounts.password[typeOfAccount].push(account.password);
  98. allAccounts.username['isTerminated'].push(false);
  99. allAccounts.username['failedLoginAttempts'].push(0);
  100. allAccounts.username['isFlagged'].push(false);
  101. console.log('account was successfully created.');
  102. }
  103.  
  104. else{
  105. // !--! ADD THIS TO|||THE UI MODULES !--! \
  106. var artificalConsole = document.getElementById('registration-console');
  107. artificalConsole.classList.toggle('invisible');
  108. artificalConsole.textContent = 'Account cannot be registered. ' + iterator;
  109.  
  110. }
  111. }
  112. })();
  113.  
  114.  
  115.  
  116.  
  117. UIModule = (function(){
  118. closeRegistration = function(type){
  119. document.getElementById('registration').classList.toggle('invisible');
  120. document.getElementById('registration-form').classList.toggle('invisible');
  121. document.getElementById('submit-button').classList.toggle('invisible');
  122. if(type === 'sign-up'){
  123. document.getElementById('submit-button').textContent = "Sign Up!";
  124. } else if(type === 'log-in') {
  125. document.getElementById('submit-button').textContent = "Login"; }
  126. }})();
  127.  
  128.  
  129.  
  130. Controller = (function(){
  131. var waitForEventListeners;
  132. waitForEventListeners = function(){
  133. document.getElementById('register-sign-up').addEventListener('click', function(){
  134. console.log(this.classList);
  135. BEModule.loadRegistration(this.classList);
  136. });
  137. document.getElementById('register-log-in').addEventListener('click', function(){
  138. BEModule.oadRegistration(this.classList);
  139. console.log(this.classList);
  140. });
  141. }
  142.  
  143. return {
  144. init: function(){
  145. waitForEventListeners();
  146. }
  147. }
  148. })();
  149.  
  150. Controller.init();
Add Comment
Please, Sign In to add comment