When creating a account the email field is now optional.

This commit is contained in:
2018-03-06 19:18:51 +01:00
parent 34a97c069b
commit 6619184a45
3 changed files with 5 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
class User {
constructor(username, email) {
constructor(username, email=undefined) {
this.username = username;
this.email = email;
}

View File

@@ -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');
}
});
}

View File

@@ -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 {