fix(auth): error login on user or password is incorrect
This commit is contained in:
@ -21,18 +21,18 @@ const log: Logger<ILogObj> = new Logger({ name: "[UserController]", type: "prett
|
||||
export class AuthController {
|
||||
static async login(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||
/*
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
$ref: "#/components/schemas/login"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
$ref: "#/components/schemas/login"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
const schema = Joi.object().keys({
|
||||
@ -52,6 +52,10 @@ export class AuthController {
|
||||
where: { username: param.username },
|
||||
})
|
||||
|
||||
if (!user) {
|
||||
return ReturnHelper.errorResponse(res, 401, 401, Language.lang.failed_access + ", username or password is incorrect")
|
||||
}
|
||||
|
||||
if (user != null && user.roles != null && user.roles.length > 0 && user.checkIfPasswordMatch(param.password)) {
|
||||
const { browser, device, os } = UAParser(req.get("User-Agent"))
|
||||
|
||||
@ -146,9 +150,9 @@ export class AuthController {
|
||||
}
|
||||
|
||||
if (user.roles == null || user.roles.length == 0) {
|
||||
return ReturnHelper.errorResponse(res, 403, 401, Language.lang.failed_access + ", you don\t have any roles in this application")
|
||||
return ReturnHelper.errorResponse(res, 401, 401, Language.lang.failed_access + ", you don't have any roles in this application")
|
||||
} else {
|
||||
return ReturnHelper.errorResponse(res, 403, 402, Language.lang.failed_access)
|
||||
return ReturnHelper.errorResponse(res, 401, 401, Language.lang.failed_access + ", username or password is incorrect")
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
log.error(e)
|
||||
@ -248,14 +252,14 @@ export class AuthController {
|
||||
|
||||
static async logout(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||
/*
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.parameters['refresh_token'] = {
|
||||
in: 'path',
|
||||
description: 'Refresh Token',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
*/
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.parameters['refresh_token'] = {
|
||||
in: 'path',
|
||||
description: 'Refresh Token',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
const schema = Joi.object().keys({
|
||||
@ -283,20 +287,20 @@ export class AuthController {
|
||||
|
||||
static async resetPassword(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||
/*
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.parameters['email'] = {
|
||||
in: 'path',
|
||||
description: 'Email',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.parameters['application'] = {
|
||||
in: 'path',
|
||||
description: 'Application',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
*/
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.parameters['email'] = {
|
||||
in: 'path',
|
||||
description: 'Email',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.parameters['application'] = {
|
||||
in: 'path',
|
||||
description: 'Application',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
const schema = Joi.object().keys({
|
||||
@ -357,20 +361,20 @@ export class AuthController {
|
||||
|
||||
static async renewToken(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||
/*
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.parameters['refresh_token'] = {
|
||||
in: 'path',
|
||||
description: 'Refresh Token',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.parameters['application'] = {
|
||||
in: 'path',
|
||||
description: 'Application',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
*/
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.parameters['refresh_token'] = {
|
||||
in: 'path',
|
||||
description: 'Refresh Token',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.parameters['application'] = {
|
||||
in: 'path',
|
||||
description: 'Application',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
*/
|
||||
try {
|
||||
const schema = Joi.object().keys({
|
||||
refresh_token: Joi.string().uuid().required().label("Refresh Token"),
|
||||
@ -445,27 +449,27 @@ export class AuthController {
|
||||
|
||||
static async updatePassword(req: Request, res: Response, next: NextFunction): Promise<Response> {
|
||||
/*
|
||||
#swagger.tags = ['Auth']
|
||||
#swagger.tags = ['Auth']
|
||||
|
||||
#swagger.parameters['token'] = {
|
||||
in: 'path',
|
||||
description: 'Token',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
#swagger.parameters['token'] = {
|
||||
in: 'path',
|
||||
description: 'Token',
|
||||
required: true,
|
||||
type: 'string'
|
||||
}
|
||||
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
description: "This action will effect to user related token",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
$ref: "#/components/schemas/user_password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
#swagger.requestBody = {
|
||||
required: true,
|
||||
description: "This action will effect to user related token",
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: {
|
||||
$ref: "#/components/schemas/user_password"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
const schema = Joi.object().keys({
|
||||
|
||||
@ -18,7 +18,7 @@ const doc = {
|
||||
login: {
|
||||
$username: "admin",
|
||||
$password: "12345aA!",
|
||||
$application: "hrms",
|
||||
$application: "saude",
|
||||
},
|
||||
user: {
|
||||
$employee_id: "EMP001",
|
||||
|
||||
Reference in New Issue
Block a user