From ba12e8b3a6de8ac82101894abe7460b392fec42a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 29 Jan 2018 16:09:50 +0100 Subject: [PATCH] Add ability to login with email --- client/src/app/login/login.component.html | 4 ++-- server/lib/oauth-model.ts | 6 +++--- server/models/account/user.ts | 15 +++------------ server/tests/api/check-params/users.ts | 2 +- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/client/src/app/login/login.component.html b/client/src/app/login/login.component.html index 24807987c..a69acfcb1 100644 --- a/client/src/app/login/login.component.html +++ b/client/src/app/login/login.component.html @@ -7,9 +7,9 @@
- +
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts index b3cc75590..3adcce7b0 100644 --- a/server/lib/oauth-model.ts +++ b/server/lib/oauth-model.ts @@ -25,10 +25,10 @@ function getRefreshToken (refreshToken: string) { return OAuthTokenModel.getByRefreshTokenAndPopulateClient(refreshToken) } -async function getUser (username: string, password: string) { - logger.debug('Getting User (username: ' + username + ', password: ******).') +async function getUser (usernameOrEmail: string, password: string) { + logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).') - const user = await UserModel.getByUsername(username) + const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail) if (!user) return null const passwordMatch = await user.isPasswordMatch(password) diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 8eb88062a..809e821bd 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts @@ -121,17 +121,6 @@ export class UserModel extends Model { return this.count() } - static getByUsername (username: string) { - const query = { - where: { - username: username - }, - include: [ { model: AccountModel, required: true } ] - } - - return UserModel.findOne(query) - } - static listForApi (start: number, count: number, sort: string) { const query = { offset: start, @@ -172,7 +161,9 @@ export class UserModel extends Model { return UserModel.scope('withVideoChannel').findOne(query) } - static loadByUsernameOrEmail (username: string, email: string) { + static loadByUsernameOrEmail (username: string, email?: string) { + if (!email) email = username + const query = { where: { [ Sequelize.Op.or ]: [ { username }, { email } ] diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 9938fe3a2..28fefe79f 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -523,7 +523,7 @@ describe('Test users API validators', function () { }) it('Should fail with a registered user having too many video', async function () { - this.timeout(10000) + this.timeout(15000) const user = { username: 'user3', -- 2.41.0