Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var userList = (function () {
- function User(username, password) {
- if (((typeof username === 'string') && (username.length > 1)) && ((password.match(/\d+/)) && (password.match(/[A-Z]/)) && (password.match(/[a-z]/)))) {
- this.username = username;
- this.password = password;
- this.watchedMovies = [];
- this.likedMovies = [];
- } else {
- $('#pas').css('display', 'inline');
- }
- }
- function UserList() {
- if (localStorage.getItem('users') != null) {
- this._users = JSON.parse(localStorage.getItem('users'));
- } else {
- this._users = [new User('ponko', 'Ponko1234')];
- localStorage.setItem('users', JSON.stringify(this._users));
- }
- }
- UserList.prototype.addUser = function (username, password) {
- if (!(this._users.find(function (user) {
- if ((user.username === username) && (Object.keys(user).length > 0)) {
- this._users.push(new User(username, password));
- localStorage.setItem('users', JSON.stringify(this._users));
- }
- })));
- }
- UserList.prototype.login = function (username, password) {
- return this._users.find(user => username === user.username && password === user.password);
- }
- return new UserList();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement