Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var BEModule, UIModule, Controller;
- BEModule = (function(){
- var account, allAccounts, loadRegistration, allocationOfData, checkValidity;
- var iterator = 0;
- account = function(username, password){
- this.username = username;
- this.password = password;
- }
- allAccounts = {
- username: {
- admin: [],
- account:[],
- isFlagged: [],
- failedLoginAttempts: [],
- isTerminated:[]
- },
- password: {
- admin:[],
- account:[]
- }
- }
- return {
- loadRegistration: function(classLists){
- if(classLists.contains('sign-up')){
- closeRegistration('sign-up');
- allocationOfData('sign-up')}
- else {
- closeRegistration('log-in');
- (classLists.contains('log-in'))
- }
- },
- accountDataExecution = function(){
- var username, password,loginAttempts, canLogin, accountExists;
- document.getElementById('submit-button').addEventListener('click', function(){
- username = document.getElementById('username').value;
- password = document.getElementById('password').value;
- accountExists = allAccounts.username['account'].indexOf(username);
- if(allAccounts.username['isFlagged'][accountExists] === false){
- if(registrationtype === 'sign-up'){
- var newRegistration;
- newRegistration = new account(username, password);
- console.log(newRegistration);
- checkValidity(newRegistration, 'account');
- } else {
- // If it is not sign-up then it is log-in
- var existingAccounts;
- if(accountExists != -1){ // if the account exists
- existingAccounts = allAccounts.username['account'].indexOf(username);
- if(password === allAccounts.password['account'][existingAccounts]){
- allAccounts.username['failedLoginAttempts'][existingAccounts] = 0;
- // Relay to the console the report of the account (if it is logged in)
- console.log('You have logged into the account ' + username);
- // ** Login to the account / open access to it ** (make a function that allows access) //
- } else if(password !== allAccounts.password['account'][accountExists]){
- var failedLoginAttempts;
- failedLoginAttempts = allAccounts.username['failedLoginAttempts'][existingAccounts];
- //Iterates the failed login attempts of the account.
- failedLoginAttempts++;
- //Relay report to the console (artifical)
- console.log('You have entered the incorrect password. ' + failedLoginAttempts + ' / 5 times. You have ' + 5 - failedLoginAttempts + 'remaining.');
- if(failedLoginAttempts === 5){
- /*canLogin === false; <-- Create into a more richer return */
- allAccounts.username['isFlagged'][accountExists] = true;
- //Relay to the console the report of the account.
- console.log('All access to this account has been prohibited, until further review.');
- }
- }
- }
- }
- } else {
- // account is flagged.
- console.log('Your account is currently flagged.');
- }
- });
- },
- checkValidity = function(account, typeOfAccount){
- var properPasswordLength,containsLetters,minimumUserNameLength;
- properPasswordLength = account.password.length >= 8;
- containsLetters = account.username.length != -1;
- minimumUserNameLength = account.username.length >= 3;
- if(properPasswordLength && containsLetters && minimumUserNameLength ){
- // Check if this account is existing
- if((allAccounts.username[typeOfAccount].indexOf(account.username)) === -1){
- // Publish the account to the object containing it.
- allAccounts.username[typeOfAccount].push(account.username);
- allAccounts.password[typeOfAccount].push(account.password);
- allAccounts.username['isTerminated'].push(false);
- allAccounts.username['failedLoginAttempts'].push(0);
- allAccounts.username['isFlagged'].push(false);
- console.log('account was successfully created.');
- }
- else{
- // !--! ADD THIS TO|||THE UI MODULES !--! \
- var artificalConsole = document.getElementById('registration-console');
- artificalConsole.classList.toggle('invisible');
- artificalConsole.textContent = 'Account cannot be registered. ' + iterator;
- }
- }
- })();
- UIModule = (function(){
- closeRegistration = function(type){
- document.getElementById('registration').classList.toggle('invisible');
- document.getElementById('registration-form').classList.toggle('invisible');
- document.getElementById('submit-button').classList.toggle('invisible');
- if(type === 'sign-up'){
- document.getElementById('submit-button').textContent = "Sign Up!";
- } else if(type === 'log-in') {
- document.getElementById('submit-button').textContent = "Login"; }
- }})();
- Controller = (function(){
- var waitForEventListeners;
- waitForEventListeners = function(){
- document.getElementById('register-sign-up').addEventListener('click', function(){
- console.log(this.classList);
- BEModule.loadRegistration(this.classList);
- });
- document.getElementById('register-log-in').addEventListener('click', function(){
- BEModule.oadRegistration(this.classList);
- console.log(this.classList);
- });
- }
- return {
- init: function(){
- waitForEventListeners();
- }
- }
- })();
- Controller.init();
Add Comment
Please, Sign In to add comment