This commit is contained in:
fro1991
2026-01-02 22:00:52 +07:00
parent 6309e9b89f
commit f562ccf38b
4 changed files with 105 additions and 70 deletions

View File

@ -46,11 +46,11 @@ export class AuthController {
const userRepository = OrmHelper.DB.getRepository(User)
const userRefreshTokenRepository = OrmHelper.DB.getRepository(UserRefreshToken)
const user = await userRepository.findOne({
relations: ["roles", "roles.application"],
select: ["id", "email", "name", "employee_id", "password", "username", "roles"],
where: { username: param.username },
})
const user = await userRepository.findOne({
relations: ["roles", "roles.application"],
select: ["id", "email", "name", "password", "username", "roles"],
where: { username: param.username },
})
if (user != null && user.roles != null && user.roles.length > 0 && user.checkIfPasswordMatch(param.password)) {
const { browser, device, os } = UAParser(req.get("User-Agent"))
@ -85,37 +85,36 @@ export class AuthController {
return ReturnHelper.errorResponse(res, 403, 403, Language.lang.failed_access + ", you don't have any roles in this application")
} else {
// const userRole = await userRoleRepository.findOneBy({ id: role_id })
var hrms = {
uuid: null,
idx: null,
employee_id: null,
employeename: null,
title: null,
department_id: null,
departement_uuid: null,
department_name: null,
level_id: null,
level_name: null,
}
var hrms = {
uuid: null,
idx: null,
employee_id: null,
employeename: null,
title: null,
department_id: null,
departement_uuid: null,
department_name: null,
level_id: null,
level_name: null,
}
var privateKey = fs.readFileSync("src/helpers/key/private.key")
var privateKey = fs.readFileSync("src/helpers/key/private.key")
var token = jwt.sign(
{
exp: Math.floor(Date.now() / 1000) + Number(config.get("auth.access_token_lifetime")),
data: {
id: user.id,
username: user.username,
name: user.name,
id_role: role_id,
roles: roles.roles,
employee_id: user.employee_id,
hrms: hrms,
var token = jwt.sign(
{
exp: Math.floor(Date.now() / 1000) + Number(config.get("auth.access_token_lifetime")),
data: {
id: user.id,
username: user.username,
name: user.name,
id_role: role_id,
roles: roles.roles,
hrms: hrms,
},
},
},
privateKey,
{ algorithm: "RS256" }
)
privateKey,
{ algorithm: "RS256" }
)
delete user.password

View File

@ -1,6 +1,6 @@
import axios from "axios"
import config from "config"
import { Paging, User, UserRefreshToken, UserRole } from "entity"
import { HrmsEmployee, Paging, User, UserRefreshToken, UserRole } from "entity"
import exceljs from "exceljs"
import { NextFunction, Response } from "express"
import { Request } from "express-jwt"
@ -247,7 +247,7 @@ export class UserController {
password: Joi.string().pattern(new RegExp("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$")).min(8).required().label("Password"),
retype_password: Joi.ref("password"),
name: Joi.string().max(64).required().label("Name"),
employee_id: Joi.string().max(64).optional().allow("").label("Employee ID"),
employee_id: Joi.string().uuid().optional().allow("").label("Employee ID"),
status: Joi.string().required().label("Status"),
})
@ -260,8 +260,8 @@ export class UserController {
data.email = param.email
data.status = param.status
if (param.employee_id && param.employee_id! + "") {
data.employee_id = param.employee_id
if (param.employee && param.employee.id! + "") {
data.employee = param.employee
}
data.hashPassword()
@ -571,7 +571,7 @@ export class UserController {
password: Joi.string().allow("").optional().label("Password"),
retype_password: Joi.ref("password"),
name: Joi.string().max(64).required().label("Name"),
employee_id: Joi.string().max(64).optional().allow("").label("Employee ID"),
employee_id: Joi.string().uuid().optional().allow("").label("Employee ID"),
status: Joi.string().required().label("Status"),
})
@ -585,13 +585,13 @@ export class UserController {
if (data != null) {
data.name = param.name
data.employee_id = param.employee_id
data.employee = param.employee
data.username = param.username
data.email = param.email
data.status = param.status
if (param.employee_id && param.employee_id != "") {
data.employee_id = param.employee_id
if (param.employee && param.employee.id != "") {
data.employee = param.employee
}
if (param.password) {