Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  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. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement