rez_core 2.0.50 → 2.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module/lead/lead.module.js +1 -1
- package/dist/module/lead/lead.module.js.map +1 -1
- package/dist/module/user/controller/login.controller.js +2 -2
- package/dist/module/user/controller/login.controller.js.map +1 -1
- package/dist/module/user/entity/user.entity.d.ts +1 -0
- package/dist/module/user/entity/user.entity.js +4 -0
- package/dist/module/user/entity/user.entity.js.map +1 -1
- package/dist/module/user/service/login.service.d.ts +3 -1
- package/dist/module/user/service/login.service.js +8 -8
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/module/user/service/user-session.service.js +1 -4
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/module/user/service/user.service.d.ts +1 -0
- package/dist/module/user/service/user.service.js +8 -0
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/lead/lead.module.ts +1 -1
- package/src/module/user/controller/login.controller.ts +2 -3
- package/src/module/user/entity/user.entity.ts +3 -0
- package/src/module/user/service/login.service.ts +40 -29
- package/src/module/user/service/user-session.service.ts +6 -4
- package/src/module/user/service/user.service.ts +12 -0
package/package.json
CHANGED
|
@@ -12,7 +12,6 @@ import { LoginService } from '../service/login.service';
|
|
|
12
12
|
import { GoogleAuthGuard } from '../../../module/auth/guards/google-auth.guard';
|
|
13
13
|
import { JwtAuthGuard } from '../../auth/guards/jwt.guard';
|
|
14
14
|
import { Request, Response } from 'express';
|
|
15
|
-
import { JwtAuthService } from 'src/module/auth/services/jwt.service';
|
|
16
15
|
import { UserSessionService } from '../service/user-session.service';
|
|
17
16
|
|
|
18
17
|
@Controller('auth')
|
|
@@ -24,8 +23,8 @@ export class LoginController {
|
|
|
24
23
|
|
|
25
24
|
@Post('login')
|
|
26
25
|
async login(@Body() body, @Res() res: Response) {
|
|
27
|
-
const { email_id, password, appcode } = body;
|
|
28
|
-
const result = await this.loginService.login(email_id, password
|
|
26
|
+
const { email_id, password, appcode, organization_id } = body;
|
|
27
|
+
const result = await this.loginService.login(email_id, password);
|
|
29
28
|
return res.status(HttpStatus.OK).json(result);
|
|
30
29
|
}
|
|
31
30
|
|
|
@@ -18,17 +18,17 @@ export class LoginService {
|
|
|
18
18
|
private userSessionService: UserSessionService,
|
|
19
19
|
private configService: ConfigService,
|
|
20
20
|
@InjectRepository(UserRoleMapping)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
private readonly userRoleMappingRepository: Repository<UserRoleMapping>,
|
|
22
|
+
@InjectRepository(Role)
|
|
23
|
+
private readonly roleRepo: Repository<Role>,
|
|
24
24
|
) {}
|
|
25
25
|
|
|
26
26
|
masterKey: string = this.configService.get('MASTER_KEY') || '';
|
|
27
27
|
masterIv: string = this.configService.get('MASTER_IV') || '';
|
|
28
28
|
|
|
29
|
-
async login(email: string, password: string
|
|
29
|
+
async login(email: string, password: string) {
|
|
30
30
|
const user = await this.userService.findByEmailId(email);
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
if (!user) {
|
|
33
33
|
return {
|
|
34
34
|
success: false,
|
|
@@ -36,7 +36,7 @@ export class LoginService {
|
|
|
36
36
|
type: 'email',
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
|
|
40
40
|
if (user.status !== 'ACTIVE') {
|
|
41
41
|
return {
|
|
42
42
|
success: false,
|
|
@@ -44,9 +44,13 @@ export class LoginService {
|
|
|
44
44
|
type: 'email',
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
const encryptedPassword = EncryptUtilService.encryptGCM(
|
|
49
|
-
|
|
47
|
+
|
|
48
|
+
const encryptedPassword = EncryptUtilService.encryptGCM(
|
|
49
|
+
password,
|
|
50
|
+
this.masterKey,
|
|
51
|
+
this.masterIv,
|
|
52
|
+
);
|
|
53
|
+
|
|
50
54
|
if (encryptedPassword !== user.password) {
|
|
51
55
|
return {
|
|
52
56
|
success: false,
|
|
@@ -54,50 +58,57 @@ export class LoginService {
|
|
|
54
58
|
type: 'password',
|
|
55
59
|
};
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
|
|
58
62
|
// ✅ Get user-role mappings for this app
|
|
59
63
|
const roleMappings = await this.userRoleMappingRepository.find({
|
|
60
64
|
where: {
|
|
61
65
|
user_id: user.id,
|
|
62
|
-
appcode: appcode,
|
|
63
66
|
},
|
|
64
67
|
});
|
|
65
|
-
|
|
68
|
+
|
|
66
69
|
if (!roleMappings.length) {
|
|
67
|
-
throw new BadRequestException(
|
|
70
|
+
throw new BadRequestException(
|
|
71
|
+
'User does not have any access mapped for this app.',
|
|
72
|
+
);
|
|
68
73
|
}
|
|
69
|
-
|
|
74
|
+
|
|
70
75
|
// ✅ Pick default access based on priority
|
|
71
76
|
const priority = { org: 1, sch: 2, brn: 3 };
|
|
72
77
|
const defaultAccess = roleMappings.sort(
|
|
73
78
|
(a, b) => priority[a.level_type] - priority[b.level_type],
|
|
74
79
|
)[0];
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
|
|
81
|
+
//appcode
|
|
82
|
+
|
|
83
|
+
let appcode = user.last_app_access;
|
|
84
|
+
|
|
85
|
+
if (!appcode) {
|
|
86
|
+
appcode = 'ADM';
|
|
87
|
+
await this.userService.setDefaultLastAccess(user.id, appcode);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const token = await this.userSessionService.createSession(
|
|
91
|
+
user,
|
|
92
|
+
user.appcode,
|
|
93
|
+
{
|
|
94
|
+
level_type: defaultAccess.level_type,
|
|
95
|
+
level_id: defaultAccess.level_id,
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
|
|
88
99
|
if (user.is_firstlogin === 1) {
|
|
89
100
|
user.invitation_status = 'ACCEPTED';
|
|
90
101
|
user.is_firstlogin = 0;
|
|
91
102
|
const { password, ...userWithoutPassword } = user;
|
|
92
103
|
await this.userService.updateEntity(userWithoutPassword, user);
|
|
93
104
|
}
|
|
94
|
-
|
|
105
|
+
|
|
95
106
|
return {
|
|
96
107
|
success: true,
|
|
97
108
|
accessToken: token,
|
|
109
|
+
appcode,
|
|
98
110
|
};
|
|
99
111
|
}
|
|
100
|
-
|
|
101
112
|
|
|
102
113
|
async loginWithGoogle(email: string, name) {
|
|
103
114
|
let user = await this.userService.findByEmailId(email);
|
|
@@ -38,8 +38,6 @@ export class UserSessionService {
|
|
|
38
38
|
sessionToken,
|
|
39
39
|
appcode,
|
|
40
40
|
email_id: user.email_id,
|
|
41
|
-
level_type: user.level_type,
|
|
42
|
-
level_id: user.level_id,
|
|
43
41
|
organization_id: user.organization_id,
|
|
44
42
|
enterprise_id: user.enterprise_id,
|
|
45
43
|
};
|
|
@@ -48,8 +46,6 @@ export class UserSessionService {
|
|
|
48
46
|
if (accessInfo) {
|
|
49
47
|
payload.level_type = accessInfo.level_type;
|
|
50
48
|
payload.level_id = accessInfo.level_id;
|
|
51
|
-
payload.role_id = accessInfo.role_id;
|
|
52
|
-
payload.role_code = accessInfo.role_code;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
const accessToken = this.jwtAuthService.generateJwt(payload);
|
|
@@ -98,6 +94,12 @@ export class UserSessionService {
|
|
|
98
94
|
level_type: currentUserLevelType,
|
|
99
95
|
appcode: data.appcode,
|
|
100
96
|
};
|
|
97
|
+
|
|
98
|
+
await this.dataSource.query(
|
|
99
|
+
`UPDATE cr_user SET last_app_access = ? WHERE id = ?`,
|
|
100
|
+
[data.appcode, userId],
|
|
101
|
+
);
|
|
102
|
+
|
|
101
103
|
// }
|
|
102
104
|
|
|
103
105
|
// Step 2: Level switch logic
|
|
@@ -252,4 +252,16 @@ export class UserService extends EntityServiceImpl {
|
|
|
252
252
|
appCode,
|
|
253
253
|
);
|
|
254
254
|
}
|
|
255
|
+
|
|
256
|
+
async setDefaultLastAccess(userId: number, appcode: string): Promise<void> {
|
|
257
|
+
const user = await this.userRepository.findById(userId);
|
|
258
|
+
|
|
259
|
+
if (!user) {
|
|
260
|
+
throw new BadRequestException('User not found');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
user.last_app_access = appcode;
|
|
264
|
+
|
|
265
|
+
await this.userRepository.saveUser(user); // This persists the updated field
|
|
266
|
+
}
|
|
255
267
|
}
|