aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-29 16:09:50 +0100
committerChocobozzz <me@florianbigard.com>2018-01-29 16:09:50 +0100
commitba12e8b3a6de8ac82101894abe7460b392fec42a (patch)
tree5f75741fde6b3be093c885c23c582b6d0d3cec20
parent61c04fa9b3566b769b260e414fe59df77cd77031 (diff)
downloadPeerTube-ba12e8b3a6de8ac82101894abe7460b392fec42a.tar.gz
PeerTube-ba12e8b3a6de8ac82101894abe7460b392fec42a.tar.zst
PeerTube-ba12e8b3a6de8ac82101894abe7460b392fec42a.zip
Add ability to login with email
-rw-r--r--client/src/app/login/login.component.html4
-rw-r--r--server/lib/oauth-model.ts6
-rw-r--r--server/models/account/user.ts15
-rw-r--r--server/tests/api/check-params/users.ts2
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 @@
7 7
8 <form role="form" (ngSubmit)="login()" [formGroup]="form"> 8 <form role="form" (ngSubmit)="login()" [formGroup]="form">
9 <div class="form-group"> 9 <div class="form-group">
10 <label for="username">Username</label> 10 <label for="username">Username or email address</label>
11 <input 11 <input
12 type="text" id="username" placeholder="Username" required 12 type="text" id="username" placeholder="Username or email address" required
13 formControlName="username" [ngClass]="{ 'input-error': formErrors['username'] }" 13 formControlName="username" [ngClass]="{ 'input-error': formErrors['username'] }"
14 > 14 >
15 <div *ngIf="formErrors.username" class="form-error"> 15 <div *ngIf="formErrors.username" class="form-error">
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) {
25 return OAuthTokenModel.getByRefreshTokenAndPopulateClient(refreshToken) 25 return OAuthTokenModel.getByRefreshTokenAndPopulateClient(refreshToken)
26} 26}
27 27
28async function getUser (username: string, password: string) { 28async function getUser (usernameOrEmail: string, password: string) {
29 logger.debug('Getting User (username: ' + username + ', password: ******).') 29 logger.debug('Getting User (username/email: ' + usernameOrEmail + ', password: ******).')
30 30
31 const user = await UserModel.getByUsername(username) 31 const user = await UserModel.loadByUsernameOrEmail(usernameOrEmail)
32 if (!user) return null 32 if (!user) return null
33 33
34 const passwordMatch = await user.isPasswordMatch(password) 34 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<UserModel> {
121 return this.count() 121 return this.count()
122 } 122 }
123 123
124 static getByUsername (username: string) {
125 const query = {
126 where: {
127 username: username
128 },
129 include: [ { model: AccountModel, required: true } ]
130 }
131
132 return UserModel.findOne(query)
133 }
134
135 static listForApi (start: number, count: number, sort: string) { 124 static listForApi (start: number, count: number, sort: string) {
136 const query = { 125 const query = {
137 offset: start, 126 offset: start,
@@ -172,7 +161,9 @@ export class UserModel extends Model<UserModel> {
172 return UserModel.scope('withVideoChannel').findOne(query) 161 return UserModel.scope('withVideoChannel').findOne(query)
173 } 162 }
174 163
175 static loadByUsernameOrEmail (username: string, email: string) { 164 static loadByUsernameOrEmail (username: string, email?: string) {
165 if (!email) email = username
166
176 const query = { 167 const query = {
177 where: { 168 where: {
178 [ Sequelize.Op.or ]: [ { username }, { email } ] 169 [ 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 () {
523 }) 523 })
524 524
525 it('Should fail with a registered user having too many video', async function () { 525 it('Should fail with a registered user having too many video', async function () {
526 this.timeout(10000) 526 this.timeout(15000)
527 527
528 const user = { 528 const user = {
529 username: 'user3', 529 username: 'user3',