Add ability to login with email

This commit is contained in:
Chocobozzz 2018-01-29 16:09:50 +01:00
parent 61c04fa9b3
commit ba12e8b3a6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 9 additions and 18 deletions

View File

@ -7,9 +7,9 @@
<form role="form" (ngSubmit)="login()" [formGroup]="form">
<div class="form-group">
<label for="username">Username</label>
<label for="username">Username or email address</label>
<input
type="text" id="username" placeholder="Username" required
type="text" id="username" placeholder="Username or email address" required
formControlName="username" [ngClass]="{ 'input-error': formErrors['username'] }"
>
<div *ngIf="formErrors.username" class="form-error">

View File

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

View File

@ -121,17 +121,6 @@ export class UserModel extends Model<UserModel> {
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<UserModel> {
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 } ]

View File

@ -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',