]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add ability to login with email
authorChocobozzz <me@florianbigard.com>
Mon, 29 Jan 2018 15:09:50 +0000 (16:09 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 29 Jan 2018 15:09:50 +0000 (16:09 +0100)
client/src/app/login/login.component.html
server/lib/oauth-model.ts
server/models/account/user.ts
server/tests/api/check-params/users.ts

index 24807987c63f25b59de67002bdeac7db7f574283..a69acfcb1ae3b85786b5cd465634ef1e6f17b0c2 100644 (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">
index b3cc75590724775fbb57245f1bb78bf146f61d32..3adcce7b0e1d4f25c01c784b2041c2340dcec364 100644 (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)
index 8eb88062ae4b3f0bc784a1976ffe1bf4cc3cb359..809e821bd389bbee3cf9a9b2d99ac841657017cc 100644 (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 } ]
index 9938fe3a290c0712e34da4a56c20197f6fd08e60..28fefe79fa07201bbbaf8ad7b5d392dd4e1513f6 100644 (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',