diff --git a/seasoned_api/src/user/user.js b/seasoned_api/src/user/user.js index d922fbb..bdf326a 100644 --- a/seasoned_api/src/user/user.js +++ b/seasoned_api/src/user/user.js @@ -1,5 +1,5 @@ class User { - constructor(username, email) { + constructor(username, email=undefined) { this.username = username; this.email = email; } diff --git a/seasoned_api/src/user/userRepository.js b/seasoned_api/src/user/userRepository.js index b672a4d..5a0e9b1 100644 --- a/seasoned_api/src/user/userRepository.js +++ b/seasoned_api/src/user/userRepository.js @@ -6,7 +6,7 @@ class UserRepository { this.database = database || establishedDatabase; this.queries = { read: 'select * from user where lower(user_name) = lower(?)', - create: 'insert into user (user_name, email) values(?, ?)', + create: 'insert into user (user_name) values (?)', change: 'update user set password = ? where user_name = ?', retrieveHash: 'select * from user where user_name = ?', }; @@ -20,13 +20,10 @@ class UserRepository { create(user) { return Promise.resolve() .then(() => this.database.get(this.queries.read, user.username)) - .then(row => assert.equal(row, undefined)) - .then(() => this.database.run(this.queries.create, [user.username, user.email])) + .then(() => this.database.run(this.queries.create, user.username)) .catch((error) => { - if (error.message.endsWith('email')) { - throw new Error('That email is already taken'); - } else if (error.name === 'AssertionError' || error.message.endsWith('user_name')) { - throw new Error('That username is already taken'); + if (error.name === 'AssertionError' || error.message.endsWith('user_name')) { + throw new Error('That username is already registered'); } }); } diff --git a/seasoned_api/src/user/userSecurity.js b/seasoned_api/src/user/userSecurity.js index 71583db..9cf4ba4 100644 --- a/seasoned_api/src/user/userSecurity.js +++ b/seasoned_api/src/user/userSecurity.js @@ -15,8 +15,6 @@ class UserSecurity { createNewUser(user, clearPassword) { if (user.username.trim() === '') { throw new Error('The username is empty.'); - } else if (user.email.trim() === '') { - throw new Error('The email is empty.'); } else if (clearPassword.trim() === '') { throw new Error('The password is empty.'); } else {