aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-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
3 files changed, 7 insertions, 16 deletions
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',