SHARE
TWEET

Untitled

a guest Oct 23rd, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var userList = (function () {
  2.  
  3.     function User(username, password) {
  4.         if (((typeof username === 'string') && (username.length > 1)) && ((password.match(/\d+/)) && (password.match(/[A-Z]/)) && (password.match(/[a-z]/)))) {
  5.             this.username = username;
  6.             this.password = password;
  7.             this.watchedMovies = [];
  8.             this.likedMovies = [];
  9.         } else {
  10.             $('#pas').css('display', 'inline');
  11.         }
  12.     }
  13.  
  14.  
  15.     function UserList() {
  16.         if (localStorage.getItem('users') != null) {
  17.             this._users = JSON.parse(localStorage.getItem('users'));
  18.         } else {
  19.             this._users = [new User('ponko', 'Ponko1234')];
  20.             localStorage.setItem('users', JSON.stringify(this._users));
  21.         }
  22.     }
  23.  
  24.     UserList.prototype.addUser = function (username, password) {
  25.         if (!(this._users.find(function (user) {
  26.             if ((user.username === username) && (Object.keys(user).length > 0)) {
  27.                 this._users.push(new User(username, password));
  28.                 localStorage.setItem('users', JSON.stringify(this._users));
  29.             }
  30.         })));
  31.     }
  32.  
  33.     UserList.prototype.login = function (username, password) {
  34.         return this._users.find(user => username === user.username && password === user.password);
  35.     }
  36.     return new UserList();
  37. })();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top