mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 13:53:22 +02:00
fix bug on user name management (#799)
Signed-off-by: Denis barbaron <denis.barbaron@orange.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright © 2019 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
||||
* Copyright © 2019-2024 contains code contributed by Orange SA, authors: Denis Barbaron - Licensed under the Apache license 2.0
|
||||
**/
|
||||
|
||||
var http = require('http')
|
||||
@@ -117,6 +117,15 @@ module.exports = function(options) {
|
||||
req.checkBody('name').notEmpty()
|
||||
req.checkBody('email').isEmail()
|
||||
})
|
||||
.then(function() {
|
||||
return dbapi.checkUserBeforeLogin(req.body)
|
||||
})
|
||||
.then(function(isValidCredential) {
|
||||
if (!isValidCredential) {
|
||||
return Promise.reject('InvalidCredentialsError')
|
||||
}
|
||||
return isValidCredential
|
||||
})
|
||||
.then(function() {
|
||||
log.info('Authenticated "%s"', req.body.email)
|
||||
var token = jwtutil.encode({
|
||||
@@ -146,12 +155,22 @@ module.exports = function(options) {
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Unexpected error', err.stack)
|
||||
res.status(500)
|
||||
.json({
|
||||
success: false
|
||||
, error: 'ServerError'
|
||||
})
|
||||
if (err === 'InvalidCredentialsError') {
|
||||
log.warn('Authentication failure for "%s"', req.body.email)
|
||||
res.status(400)
|
||||
.json({
|
||||
success: false
|
||||
, error: 'InvalidCredentialsError'
|
||||
})
|
||||
}
|
||||
else {
|
||||
log.error('Unexpected error', err.stack)
|
||||
res.status(500)
|
||||
.json({
|
||||
success: false
|
||||
, error: 'ServerError'
|
||||
})
|
||||
}
|
||||
})
|
||||
break
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user