@tomei/sso 0.15.4 → 0.15.6
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/__tests__/unit/components/login-user/login-user.spec.ts +16 -16
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +15 -15
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -1
- package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +19 -1
- package/dist/src/components/login-user/login-user.d.ts +54 -9
- package/dist/src/components/login-user/login-user.js +169 -21
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/enum/index.d.ts +1 -0
- package/dist/src/enum/index.js +18 -0
- package/dist/src/enum/index.js.map +1 -0
- package/dist/src/enum/yn.enum.d.ts +4 -0
- package/dist/src/enum/yn.enum.js +9 -0
- package/dist/src/enum/yn.enum.js.map +1 -0
- package/dist/src/models/user.entity.d.ts +16 -6
- package/dist/src/models/user.entity.js +85 -25
- package/dist/src/models/user.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/20240314080603-create-user-table.js +108 -0
- package/migrations/{04-create-user-user-group-table.js → 20240314080604-create-user-user-group-table.js} +1 -1
- package/migrations/{05-create-login-history-table.js → 20240314080605-create-login-history-table.js} +1 -1
- package/package.json +2 -1
- package/src/components/login-user/interfaces/user-info.interface.ts +21 -1
- package/src/components/login-user/login-user.ts +226 -34
- package/src/enum/index.ts +1 -0
- package/src/enum/yn.enum.ts +4 -0
- package/src/models/user.entity.ts +69 -19
@@ -0,0 +1,108 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/** @type {import('sequelize-cli').Migration} */
|
4
|
+
module.exports = {
|
5
|
+
async up(queryInterface, Sequelize) {
|
6
|
+
await queryInterface.createTable('sso_User', {
|
7
|
+
UserId: {
|
8
|
+
primaryKey: true,
|
9
|
+
type: Sequelize.INTEGER,
|
10
|
+
allowNull: false,
|
11
|
+
autoIncrement: true,
|
12
|
+
},
|
13
|
+
Email: {
|
14
|
+
type: Sequelize.STRING,
|
15
|
+
allowNull: false,
|
16
|
+
unique: true,
|
17
|
+
},
|
18
|
+
Password: {
|
19
|
+
type: Sequelize.STRING,
|
20
|
+
allowNull: false,
|
21
|
+
},
|
22
|
+
Status: {
|
23
|
+
type: Sequelize.STRING,
|
24
|
+
allowNull: false,
|
25
|
+
},
|
26
|
+
DefaultPasswordChangedYN: {
|
27
|
+
type: Sequelize.CHAR(1),
|
28
|
+
allowNull: true,
|
29
|
+
},
|
30
|
+
FirstLoginAt: {
|
31
|
+
type: Sequelize.DATE,
|
32
|
+
allowNull: true,
|
33
|
+
},
|
34
|
+
LastLoginAt: {
|
35
|
+
type: Sequelize.DATE,
|
36
|
+
allowNull: true,
|
37
|
+
},
|
38
|
+
MFAEnabled: {
|
39
|
+
type: Sequelize.TINYINT,
|
40
|
+
allowNull: true,
|
41
|
+
},
|
42
|
+
MFAConfig: {
|
43
|
+
type: Sequelize.TEXT,
|
44
|
+
allowNull: true,
|
45
|
+
},
|
46
|
+
RecoveryEmail: {
|
47
|
+
type: Sequelize.STRING,
|
48
|
+
allowNull: true,
|
49
|
+
},
|
50
|
+
FailedLoginAttemptCount: {
|
51
|
+
type: Sequelize.INTEGER,
|
52
|
+
allowNull: false,
|
53
|
+
},
|
54
|
+
LastFailedLoginAt: {
|
55
|
+
type: Sequelize.DATE,
|
56
|
+
allowNull: true,
|
57
|
+
},
|
58
|
+
LastPasswordChangedAt: {
|
59
|
+
type: Sequelize.DATE,
|
60
|
+
allowNull: true,
|
61
|
+
},
|
62
|
+
NeedToChangePasswordYN: {
|
63
|
+
type: Sequelize.CHAR(1),
|
64
|
+
allowNull: true,
|
65
|
+
},
|
66
|
+
CreatedAt: {
|
67
|
+
allowNull: false,
|
68
|
+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3)'),
|
69
|
+
type: Sequelize.DATE,
|
70
|
+
},
|
71
|
+
CreatedById: {
|
72
|
+
type: Sequelize.INTEGER,
|
73
|
+
allowNull: true,
|
74
|
+
references: {
|
75
|
+
model: 'sso_User',
|
76
|
+
key: 'UserId',
|
77
|
+
},
|
78
|
+
onDelete: 'CASCADE',
|
79
|
+
onUpdate: 'CASCADE',
|
80
|
+
},
|
81
|
+
UpdatedAt: {
|
82
|
+
allowNull: false,
|
83
|
+
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)'),
|
84
|
+
type: Sequelize.DATE,
|
85
|
+
},
|
86
|
+
UpdatedById: {
|
87
|
+
type: Sequelize.INTEGER,
|
88
|
+
allowNull: true,
|
89
|
+
references: {
|
90
|
+
model: 'sso_User',
|
91
|
+
key: 'UserId',
|
92
|
+
},
|
93
|
+
onDelete: 'CASCADE',
|
94
|
+
onUpdate: 'CASCADE',
|
95
|
+
},
|
96
|
+
|
97
|
+
});
|
98
|
+
},
|
99
|
+
|
100
|
+
async down(queryInterface, Sequelize) {
|
101
|
+
/**
|
102
|
+
* Add reverting commands here.
|
103
|
+
*
|
104
|
+
* Example:
|
105
|
+
* await queryInterface.dropTable('users');
|
106
|
+
*/
|
107
|
+
}
|
108
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tomei/sso",
|
3
|
-
"version": "0.15.
|
3
|
+
"version": "0.15.6",
|
4
4
|
"description": "Tomei SSO Package",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"scripts": {
|
@@ -46,6 +46,7 @@
|
|
46
46
|
"prettier": "^2.7.1",
|
47
47
|
"prisma": "^4.14.0",
|
48
48
|
"redis-mock": "^0.56.3",
|
49
|
+
"sequelize-cli": "^6.6.2",
|
49
50
|
"ts-jest": "^29.1.0",
|
50
51
|
"ts-node": "^10.9.1",
|
51
52
|
"tsc-watch": "^5.0.3",
|
@@ -1,9 +1,29 @@
|
|
1
|
+
import { YN } from '../../../enum';
|
2
|
+
|
1
3
|
export interface IUserInfo {
|
2
4
|
FullName: string;
|
3
5
|
IDNo: string;
|
4
6
|
Email: string;
|
5
7
|
ContactNo: string;
|
6
|
-
|
8
|
+
UserId: number;
|
7
9
|
Password: string;
|
8
10
|
staffs?: any;
|
9
11
|
}
|
12
|
+
|
13
|
+
export interface IUserAttr extends IUserInfo {
|
14
|
+
Status: string;
|
15
|
+
DefaultPasswordChangedYN: YN;
|
16
|
+
FirstLoginAt: Date;
|
17
|
+
LastLoginAt: Date;
|
18
|
+
MFAEnabled: number;
|
19
|
+
MFAConfig: string;
|
20
|
+
RecoveryEmail: string;
|
21
|
+
FailedLoginAttemptCount: number;
|
22
|
+
LastFailedLoginAt: Date;
|
23
|
+
LastPasswordChangedAt: Date;
|
24
|
+
NeedToChangePasswordYN: YN;
|
25
|
+
CreatedById: number;
|
26
|
+
CreatedAt: Date;
|
27
|
+
UpdatedById: number;
|
28
|
+
UpdatedAt: Date;
|
29
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { LoginUserBase } from '@tomei/general';
|
2
2
|
import { ISessionService } from '../../session/interfaces/session-service.interface';
|
3
|
-
import {
|
3
|
+
import { IUserAttr } from './interfaces/user-info.interface';
|
4
4
|
import { UserRepository } from './user.repository';
|
5
5
|
import { SystemRepository } from '../system/system.repository';
|
6
6
|
import { SystemAccessRepository } from '../system-access/system-access.repository';
|
@@ -16,18 +16,29 @@ import LoginHistory from '../../models/login-history.entity';
|
|
16
16
|
import GroupSystemPrivilege from '../../models/group-system-privilege.entity';
|
17
17
|
import GroupRolePrivilege from '../../models/group-role-privilege.entity';
|
18
18
|
import UserGroup from '../../models/user-group.entity';
|
19
|
+
import { YN } from '../../enum/yn.enum';
|
19
20
|
|
20
21
|
export class LoginUser extends LoginUserBase {
|
21
|
-
FullName: string;
|
22
|
-
IDNo: string;
|
23
|
-
IDType: string;
|
24
|
-
Email: string;
|
25
|
-
ContactNo: string;
|
26
|
-
Password: string;
|
27
|
-
DefaultAddress: IAddress;
|
28
22
|
ObjectId: string;
|
23
|
+
Email: string;
|
24
|
+
private _Password: string;
|
25
|
+
private _Status: string;
|
26
|
+
private _DefaultPasswordChangedYN: YN;
|
27
|
+
private _FirstLoginAt: Date;
|
28
|
+
private _LastLoginAt: Date;
|
29
|
+
private _MFAEnabled: number;
|
30
|
+
private _MFAConfig: string;
|
31
|
+
private _RecoveryEmail: string;
|
32
|
+
private _FailedLoginAttemptCount: number;
|
33
|
+
private _LastFailedLoginAt: Date;
|
34
|
+
private _LastPasswordChangedAt: Date;
|
35
|
+
private _NeedToChangePasswordYN: YN;
|
36
|
+
private _CreatedById: number;
|
37
|
+
private _CreatedAt: Date;
|
38
|
+
private _UpdatedById: number;
|
39
|
+
private _UpdatedAt: Date;
|
29
40
|
ObjectName = 'User';
|
30
|
-
TableName = '
|
41
|
+
TableName = 'sso_Users';
|
31
42
|
ObjectType = 'User';
|
32
43
|
staffs: any;
|
33
44
|
|
@@ -42,6 +53,142 @@ export class LoginUser extends LoginUserBase {
|
|
42
53
|
private static _UserGroupRepository = new UserGroupRepository();
|
43
54
|
private _dbTransaction: any;
|
44
55
|
|
56
|
+
get UserId(): number {
|
57
|
+
return parseInt(this.ObjectId);
|
58
|
+
}
|
59
|
+
|
60
|
+
private set UserId(value: number) {
|
61
|
+
this.ObjectId = value.toString();
|
62
|
+
}
|
63
|
+
|
64
|
+
get Password(): string {
|
65
|
+
return this._Password;
|
66
|
+
}
|
67
|
+
|
68
|
+
private set Password(value: string) {
|
69
|
+
this._Password = value;
|
70
|
+
}
|
71
|
+
|
72
|
+
get Status(): string {
|
73
|
+
return this._Status;
|
74
|
+
}
|
75
|
+
|
76
|
+
private set Status(value: string) {
|
77
|
+
this._Status = value;
|
78
|
+
}
|
79
|
+
|
80
|
+
get DefaultPasswordChangedYN(): YN {
|
81
|
+
return this._DefaultPasswordChangedYN;
|
82
|
+
}
|
83
|
+
|
84
|
+
private set DefaultPasswordChangedYN(value: YN) {
|
85
|
+
this._DefaultPasswordChangedYN = value;
|
86
|
+
}
|
87
|
+
|
88
|
+
get FirstLoginAt(): Date {
|
89
|
+
return this._FirstLoginAt;
|
90
|
+
}
|
91
|
+
|
92
|
+
private set FirstLoginAt(value: Date) {
|
93
|
+
this._FirstLoginAt = value;
|
94
|
+
}
|
95
|
+
|
96
|
+
get LastLoginAt(): Date {
|
97
|
+
return this._LastLoginAt;
|
98
|
+
}
|
99
|
+
|
100
|
+
private set LastLoginAt(value: Date) {
|
101
|
+
this._LastLoginAt = value;
|
102
|
+
}
|
103
|
+
|
104
|
+
get MFAEnabled(): number {
|
105
|
+
return this._MFAEnabled;
|
106
|
+
}
|
107
|
+
|
108
|
+
private set MFAEnabled(value: number) {
|
109
|
+
this._MFAEnabled = value;
|
110
|
+
}
|
111
|
+
|
112
|
+
get MFAConfig(): string {
|
113
|
+
return this._MFAConfig;
|
114
|
+
}
|
115
|
+
|
116
|
+
private set MFAConfig(value: string) {
|
117
|
+
this._MFAConfig = value;
|
118
|
+
}
|
119
|
+
|
120
|
+
get RecoveryEmail(): string {
|
121
|
+
return this._RecoveryEmail;
|
122
|
+
}
|
123
|
+
|
124
|
+
private set RecoveryEmail(value: string) {
|
125
|
+
this._RecoveryEmail = value;
|
126
|
+
}
|
127
|
+
|
128
|
+
get FailedLoginAttemptCount(): number {
|
129
|
+
return this._FailedLoginAttemptCount;
|
130
|
+
}
|
131
|
+
|
132
|
+
private set FailedLoginAttemptCount(value: number) {
|
133
|
+
this._FailedLoginAttemptCount = value;
|
134
|
+
}
|
135
|
+
|
136
|
+
get LastFailedLoginAt(): Date {
|
137
|
+
return this._LastFailedLoginAt;
|
138
|
+
}
|
139
|
+
|
140
|
+
private set LastFailedLoginAt(value: Date) {
|
141
|
+
this._LastFailedLoginAt = value;
|
142
|
+
}
|
143
|
+
|
144
|
+
get LastPasswordChangedAt(): Date {
|
145
|
+
return this._LastPasswordChangedAt;
|
146
|
+
}
|
147
|
+
|
148
|
+
private set LastPasswordChangedAt(value: Date) {
|
149
|
+
this._LastPasswordChangedAt = value;
|
150
|
+
}
|
151
|
+
|
152
|
+
get NeedToChangePasswordYN(): YN {
|
153
|
+
return this._NeedToChangePasswordYN;
|
154
|
+
}
|
155
|
+
|
156
|
+
private set NeedToChangePasswordYN(value: YN) {
|
157
|
+
this._NeedToChangePasswordYN = value;
|
158
|
+
}
|
159
|
+
|
160
|
+
get CreatedById(): number {
|
161
|
+
return this._CreatedById;
|
162
|
+
}
|
163
|
+
|
164
|
+
private set CreatedById(value: number) {
|
165
|
+
this._CreatedById = value;
|
166
|
+
}
|
167
|
+
|
168
|
+
get CreatedAt(): Date {
|
169
|
+
return this._CreatedAt;
|
170
|
+
}
|
171
|
+
|
172
|
+
private set CreatedAt(value: Date) {
|
173
|
+
this._CreatedAt = value;
|
174
|
+
}
|
175
|
+
|
176
|
+
get UpdatedById(): number {
|
177
|
+
return this._UpdatedById;
|
178
|
+
}
|
179
|
+
|
180
|
+
private set UpdatedById(value: number) {
|
181
|
+
this._UpdatedById = value;
|
182
|
+
}
|
183
|
+
|
184
|
+
get UpdatedAt(): Date {
|
185
|
+
return this._UpdatedAt;
|
186
|
+
}
|
187
|
+
|
188
|
+
private set UpdatedAt(value: Date) {
|
189
|
+
this._UpdatedAt = value;
|
190
|
+
}
|
191
|
+
|
45
192
|
async getDetails(): Promise<{
|
46
193
|
FullName: string;
|
47
194
|
IDNo: string;
|
@@ -61,7 +208,7 @@ export class LoginUser extends LoginUserBase {
|
|
61
208
|
private constructor(
|
62
209
|
sessionService: ISessionService,
|
63
210
|
dbTransaction?: any,
|
64
|
-
userInfo?:
|
211
|
+
userInfo?: IUserAttr,
|
65
212
|
) {
|
66
213
|
super();
|
67
214
|
this._SessionService = sessionService;
|
@@ -71,7 +218,7 @@ export class LoginUser extends LoginUserBase {
|
|
71
218
|
}
|
72
219
|
// set all the class properties
|
73
220
|
if (userInfo) {
|
74
|
-
this.
|
221
|
+
this.UserId = userInfo.UserId;
|
75
222
|
this.FullName = userInfo.FullName;
|
76
223
|
this.IDNo = userInfo.IDNo;
|
77
224
|
this.Email = userInfo.Email;
|
@@ -83,7 +230,7 @@ export class LoginUser extends LoginUserBase {
|
|
83
230
|
|
84
231
|
static async init(
|
85
232
|
sessionService: ISessionService,
|
86
|
-
userId?:
|
233
|
+
userId?: number,
|
87
234
|
dbTransaction = null,
|
88
235
|
): Promise<LoginUser> {
|
89
236
|
if (userId) {
|
@@ -92,7 +239,7 @@ export class LoginUser extends LoginUserBase {
|
|
92
239
|
}
|
93
240
|
const user = await LoginUser._Repository.findOne({
|
94
241
|
where: {
|
95
|
-
|
242
|
+
UserId: userId,
|
96
243
|
},
|
97
244
|
include: [
|
98
245
|
{
|
@@ -106,17 +253,32 @@ export class LoginUser extends LoginUserBase {
|
|
106
253
|
}
|
107
254
|
|
108
255
|
if (user) {
|
109
|
-
const
|
110
|
-
|
256
|
+
const userAttr: IUserAttr = {
|
257
|
+
UserId: user.UserId,
|
111
258
|
FullName: user.Staff.FullName,
|
112
259
|
IDNo: user.Staff.IdNo,
|
113
260
|
ContactNo: user.Staff.Mobile,
|
114
261
|
Email: user.Email,
|
115
262
|
Password: user.Password,
|
263
|
+
Status: user.Status,
|
264
|
+
DefaultPasswordChangedYN: user.DefaultPasswordChangedYN,
|
265
|
+
FirstLoginAt: user.FirstLoginAt,
|
266
|
+
LastLoginAt: user.LastLoginAt,
|
267
|
+
MFAEnabled: user.MFAEnabled,
|
268
|
+
MFAConfig: user.MFAConfig,
|
269
|
+
RecoveryEmail: user.RecoveryEmail,
|
270
|
+
FailedLoginAttemptCount: user.FailedLoginAttemptCount,
|
271
|
+
LastFailedLoginAt: user.LastFailedLoginAt,
|
272
|
+
LastPasswordChangedAt: user.LastPasswordChangedAt,
|
273
|
+
NeedToChangePasswordYN: user.NeedToChangePasswordYN,
|
274
|
+
CreatedById: user.CreatedById,
|
275
|
+
CreatedAt: user.CreatedAt,
|
276
|
+
UpdatedById: user.UpdatedById,
|
277
|
+
UpdatedAt: user.UpdatedAt,
|
116
278
|
staffs: user.Staff,
|
117
279
|
};
|
118
280
|
|
119
|
-
return new LoginUser(sessionService, dbTransaction,
|
281
|
+
return new LoginUser(sessionService, dbTransaction, userAttr);
|
120
282
|
} else {
|
121
283
|
throw new Error('User not found');
|
122
284
|
}
|
@@ -144,23 +306,53 @@ export class LoginUser extends LoginUserBase {
|
|
144
306
|
],
|
145
307
|
});
|
146
308
|
|
147
|
-
const
|
148
|
-
|
309
|
+
const userAttr: IUserAttr = {
|
310
|
+
UserId: user.UserId,
|
149
311
|
FullName: user.Staff.FullName,
|
150
312
|
IDNo: user.Staff.IdNo,
|
151
313
|
ContactNo: user.Staff.Mobile,
|
152
|
-
Email: user.
|
314
|
+
Email: user.Email,
|
153
315
|
Password: user.Password,
|
316
|
+
Status: user.Status,
|
317
|
+
DefaultPasswordChangedYN: user.DefaultPasswordChangedYN,
|
318
|
+
FirstLoginAt: user.FirstLoginAt,
|
319
|
+
LastLoginAt: user.LastLoginAt,
|
320
|
+
MFAEnabled: user.MFAEnabled,
|
321
|
+
MFAConfig: user.MFAConfig,
|
322
|
+
RecoveryEmail: user.RecoveryEmail,
|
323
|
+
FailedLoginAttemptCount: user.FailedLoginAttemptCount,
|
324
|
+
LastFailedLoginAt: user.LastFailedLoginAt,
|
325
|
+
LastPasswordChangedAt: user.LastPasswordChangedAt,
|
326
|
+
NeedToChangePasswordYN: user.NeedToChangePasswordYN,
|
327
|
+
CreatedById: user.CreatedById,
|
328
|
+
CreatedAt: user.CreatedAt,
|
329
|
+
UpdatedById: user.UpdatedById,
|
330
|
+
UpdatedAt: user.UpdatedAt,
|
154
331
|
staffs: user.Staff,
|
155
332
|
};
|
156
333
|
|
157
|
-
this.
|
158
|
-
this.FullName =
|
159
|
-
this.IDNo =
|
160
|
-
this.Email =
|
161
|
-
this.ContactNo =
|
162
|
-
this.Password =
|
163
|
-
this.
|
334
|
+
this.UserId = userAttr.UserId;
|
335
|
+
this.FullName = userAttr.FullName;
|
336
|
+
this.IDNo = userAttr.IDNo;
|
337
|
+
this.Email = userAttr.Email;
|
338
|
+
this.ContactNo = userAttr.ContactNo;
|
339
|
+
this.Password = userAttr.Password;
|
340
|
+
this.Status = userAttr.Status;
|
341
|
+
this.DefaultPasswordChangedYN = userAttr.DefaultPasswordChangedYN;
|
342
|
+
this.FirstLoginAt = userAttr.FirstLoginAt;
|
343
|
+
this.LastLoginAt = userAttr.LastLoginAt;
|
344
|
+
this.MFAEnabled = userAttr.MFAEnabled;
|
345
|
+
this.MFAConfig = userAttr.MFAConfig;
|
346
|
+
this.RecoveryEmail = userAttr.RecoveryEmail;
|
347
|
+
this.FailedLoginAttemptCount = userAttr.FailedLoginAttemptCount;
|
348
|
+
this.LastFailedLoginAt = userAttr.LastFailedLoginAt;
|
349
|
+
this.LastPasswordChangedAt = userAttr.LastPasswordChangedAt;
|
350
|
+
this.NeedToChangePasswordYN = userAttr.NeedToChangePasswordYN;
|
351
|
+
this.CreatedById = userAttr.CreatedById;
|
352
|
+
this.CreatedAt = userAttr.CreatedAt;
|
353
|
+
this.UpdatedById = userAttr.UpdatedById;
|
354
|
+
this.UpdatedAt = userAttr.UpdatedAt;
|
355
|
+
this.staffs = userAttr.staffs;
|
164
356
|
}
|
165
357
|
|
166
358
|
if (this.ObjectId && this.Email !== email) {
|
@@ -189,9 +381,9 @@ export class LoginUser extends LoginUserBase {
|
|
189
381
|
}
|
190
382
|
|
191
383
|
//validate system access
|
192
|
-
await this.checkSystemAccess(this.
|
384
|
+
await this.checkSystemAccess(this.UserId, system.id);
|
193
385
|
// alert user if new login
|
194
|
-
|
386
|
+
await this.alertNewLogin(this.ObjectId, system.id.toString(), ipAddress);
|
195
387
|
|
196
388
|
// fetch user session if exists
|
197
389
|
const userSession = await this._SessionService.retrieveUserSession(
|
@@ -225,20 +417,20 @@ export class LoginUser extends LoginUserBase {
|
|
225
417
|
|
226
418
|
// record new login history
|
227
419
|
await LoginUser._LoginHistoryRepository.create({
|
228
|
-
UserId: this.
|
420
|
+
UserId: this.UserId,
|
229
421
|
SystemId: system.id,
|
230
422
|
OriginIp: ipAddress,
|
231
423
|
CreatedAt: new Date(),
|
232
424
|
});
|
233
425
|
|
234
|
-
return `${this.
|
426
|
+
return `${this.UserId}:${sessionId}`;
|
235
427
|
} catch (error) {
|
236
428
|
throw error;
|
237
429
|
}
|
238
430
|
}
|
239
431
|
|
240
432
|
private async checkSystemAccess(
|
241
|
-
userId:
|
433
|
+
userId: number,
|
242
434
|
systemId: number,
|
243
435
|
): Promise<void> {
|
244
436
|
try {
|
@@ -423,7 +615,7 @@ export class LoginUser extends LoginUserBase {
|
|
423
615
|
try {
|
424
616
|
return await LoginUser._UserUserGroupRepository.findAll({
|
425
617
|
where: {
|
426
|
-
UserId: this.
|
618
|
+
UserId: this.UserId,
|
427
619
|
SystemId: systemCode,
|
428
620
|
},
|
429
621
|
include: {
|
@@ -453,7 +645,7 @@ export class LoginUser extends LoginUserBase {
|
|
453
645
|
try {
|
454
646
|
const userRole = await LoginUser._Repository.findOne({
|
455
647
|
where: {
|
456
|
-
|
648
|
+
UserId: this.ObjectId,
|
457
649
|
},
|
458
650
|
include: {
|
459
651
|
model: SystemPrivilege,
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './yn.enum';
|
@@ -23,61 +23,108 @@ import SystemRole from './system-role.entity';
|
|
23
23
|
import UserSystemRole from './user-system-role.entity';
|
24
24
|
import SystemPrivilege from './system-privilege.entity';
|
25
25
|
import UserSystemPrivileges from './user-system-privileges.entity';
|
26
|
+
import { YN } from '../enum/yn.enum';
|
26
27
|
|
27
28
|
@Table({
|
28
|
-
tableName: '
|
29
|
+
tableName: 'sso_User',
|
29
30
|
timestamps: true,
|
30
|
-
createdAt: '
|
31
|
-
updatedAt: '
|
31
|
+
createdAt: 'CreatedAt',
|
32
|
+
updatedAt: 'UpdatedAt',
|
32
33
|
})
|
33
34
|
export default class User extends Model {
|
34
35
|
@Column({
|
35
36
|
primaryKey: true,
|
37
|
+
allowNull: false,
|
36
38
|
type: DataType.INTEGER,
|
37
39
|
})
|
38
|
-
|
40
|
+
UserId: number;
|
39
41
|
|
40
42
|
@Column({
|
43
|
+
allowNull: false,
|
41
44
|
type: DataType.STRING,
|
42
|
-
field: 'email',
|
43
45
|
})
|
44
46
|
Email: string;
|
45
47
|
|
46
48
|
@Column({
|
49
|
+
allowNull: false,
|
47
50
|
type: DataType.STRING,
|
48
|
-
field: 'password',
|
49
51
|
})
|
50
52
|
Password: string;
|
51
53
|
|
52
54
|
@Column({
|
55
|
+
allowNull: false,
|
53
56
|
type: DataType.STRING,
|
54
|
-
field: 'status',
|
55
57
|
})
|
56
58
|
Status: string;
|
57
59
|
|
58
60
|
@Column({
|
59
|
-
|
60
|
-
|
61
|
+
allowNull: false,
|
62
|
+
type: DataType.CHAR(1),
|
61
63
|
})
|
62
|
-
|
64
|
+
DefaultPasswordChangedYN: YN;
|
63
65
|
|
64
66
|
@Column({
|
65
67
|
type: DataType.DATE,
|
66
|
-
field: 'first_login_at',
|
67
68
|
})
|
68
|
-
FirstLoginAt:
|
69
|
+
FirstLoginAt: Date;
|
69
70
|
|
70
|
-
@ForeignKey(() => UserGroup)
|
71
71
|
@Column({
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
type: DataType.DATE,
|
73
|
+
})
|
74
|
+
LastLoginAt: Date;
|
75
|
+
|
76
|
+
@Column({
|
77
|
+
type: DataType.TINYINT,
|
78
|
+
})
|
79
|
+
MFAEnabled: number;
|
80
|
+
|
81
|
+
@Column({
|
82
|
+
type: DataType.TEXT,
|
83
|
+
})
|
84
|
+
MFAConfig: string;
|
85
|
+
|
86
|
+
@Column({
|
87
|
+
type: DataType.STRING,
|
75
88
|
})
|
76
|
-
|
89
|
+
RecoveryEmail: string;
|
90
|
+
|
91
|
+
@Column({
|
92
|
+
allowNull: false,
|
93
|
+
type: DataType.INTEGER,
|
94
|
+
})
|
95
|
+
FailedLoginAttemptCount: number;
|
96
|
+
|
97
|
+
@Column({
|
98
|
+
type: DataType.DATE,
|
99
|
+
})
|
100
|
+
LastFailedLoginAt: Date;
|
101
|
+
|
102
|
+
@Column({
|
103
|
+
type: DataType.DATE,
|
104
|
+
})
|
105
|
+
LastPasswordChangedAt: Date;
|
106
|
+
|
107
|
+
@Column({
|
108
|
+
allowNull: false,
|
109
|
+
type: DataType.CHAR(1),
|
110
|
+
})
|
111
|
+
NeedToChangePasswordYN: YN;
|
112
|
+
|
113
|
+
@ForeignKey(() => User)
|
114
|
+
@Column({
|
115
|
+
type: DataType.INTEGER,
|
116
|
+
})
|
117
|
+
CreatedById: number;
|
77
118
|
|
78
119
|
@CreatedAt
|
79
120
|
CreatedAt: Date;
|
80
121
|
|
122
|
+
@ForeignKey(() => User)
|
123
|
+
@Column({
|
124
|
+
type: DataType.INTEGER,
|
125
|
+
})
|
126
|
+
UpdatedById: number;
|
127
|
+
|
81
128
|
@UpdatedAt
|
82
129
|
UpdatedAt: Date;
|
83
130
|
|
@@ -105,6 +152,9 @@ export default class User extends Model {
|
|
105
152
|
@BelongsToMany(() => SystemPrivilege, () => UserSystemPrivileges)
|
106
153
|
SystemPrivileges: SystemPrivilege[];
|
107
154
|
|
108
|
-
@BelongsTo(() =>
|
109
|
-
|
155
|
+
@BelongsTo(() => User, 'CreatedById')
|
156
|
+
CreatedBy: User;
|
157
|
+
|
158
|
+
@BelongsTo(() => User, 'UpdatedById')
|
159
|
+
UpdatedBy: User;
|
110
160
|
}
|