@tomei/sso 0.27.0 → 0.28.3
Sign up to get free protection for your applications and to get access to all the features.
- package/__tests__/unit/components/system-privilege/system-privilege.spec.ts +0 -3
- package/coverage/clover.xml +1452 -1452
- package/coverage/coverage-final.json +47 -47
- package/coverage/lcov-report/base.css +224 -224
- package/coverage/lcov-report/block-navigation.js +87 -87
- package/coverage/lcov-report/components/group/group.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group/group.ts.html +327 -327
- package/coverage/lcov-report/components/group/index.html +130 -130
- package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.ts.html +321 -321
- package/coverage/lcov-report/components/group-object-privilege/index.html +130 -130
- package/coverage/lcov-report/components/group-privilege/group-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-privilege/group-privilege.ts.html +303 -303
- package/coverage/lcov-report/components/group-privilege/index.html +130 -130
- package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.ts.html +327 -327
- package/coverage/lcov-report/components/group-reporting-user/index.html +130 -130
- package/coverage/lcov-report/components/group-system-access/group-system-access.repository.ts.html +117 -117
- package/coverage/lcov-report/components/group-system-access/group-system-access.ts.html +309 -309
- package/coverage/lcov-report/components/group-system-access/index.html +130 -130
- package/coverage/lcov-report/components/login-history/index.html +115 -115
- package/coverage/lcov-report/components/login-history/login-history.repository.ts.html +117 -117
- package/coverage/lcov-report/components/login-user/index.html +130 -130
- package/coverage/lcov-report/components/login-user/login-user.ts.html +5007 -5007
- package/coverage/lcov-report/components/login-user/user.repository.ts.html +117 -117
- package/coverage/lcov-report/components/password-hash/index.html +115 -115
- package/coverage/lcov-report/components/password-hash/password-hash.service.ts.html +126 -126
- package/coverage/lcov-report/components/system/index.html +130 -130
- package/coverage/lcov-report/components/system/system.repository.ts.html +117 -117
- package/coverage/lcov-report/components/system/system.ts.html +909 -909
- package/coverage/lcov-report/components/system-privilege/index.html +130 -130
- package/coverage/lcov-report/components/system-privilege/system-privilege.repository.ts.html +120 -120
- package/coverage/lcov-report/components/system-privilege/system-privilege.ts.html +390 -390
- package/coverage/lcov-report/components/user-group/index.html +130 -130
- package/coverage/lcov-report/components/user-group/user-group.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-group/user-group.ts.html +354 -354
- package/coverage/lcov-report/components/user-object-privilege/index.html +130 -130
- package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.ts.html +312 -312
- package/coverage/lcov-report/components/user-privilege/index.html +130 -130
- package/coverage/lcov-report/components/user-privilege/user-privilege.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-privilege/user-privilege.ts.html +306 -306
- package/coverage/lcov-report/components/user-system-access/index.html +130 -130
- package/coverage/lcov-report/components/user-system-access/user-system-access.repository.ts.html +117 -117
- package/coverage/lcov-report/components/user-system-access/user-system-access.ts.html +312 -312
- package/coverage/lcov-report/enum/group-type.enum.ts.html +108 -108
- package/coverage/lcov-report/enum/index.html +160 -160
- package/coverage/lcov-report/enum/index.ts.html +93 -93
- package/coverage/lcov-report/enum/user-status.enum.ts.html +105 -105
- package/coverage/lcov-report/enum/yn.enum.ts.html +96 -96
- package/coverage/lcov-report/index.html +370 -370
- package/coverage/lcov-report/models/group-object-privilege.entity.ts.html +333 -333
- package/coverage/lcov-report/models/group-privilege.entity.ts.html +315 -315
- package/coverage/lcov-report/models/group-reporting-user.entity.ts.html +339 -339
- package/coverage/lcov-report/models/group-system-access.entity.ts.html +324 -324
- package/coverage/lcov-report/models/group.entity.ts.html +435 -435
- package/coverage/lcov-report/models/index.html +310 -310
- package/coverage/lcov-report/models/login-history.entity.ts.html +252 -252
- package/coverage/lcov-report/models/staff.entity.ts.html +411 -411
- package/coverage/lcov-report/models/system-privilege.entity.ts.html +354 -354
- package/coverage/lcov-report/models/system.entity.ts.html +423 -423
- package/coverage/lcov-report/models/user-group.entity.ts.html +354 -354
- package/coverage/lcov-report/models/user-object-privilege.entity.ts.html +330 -330
- package/coverage/lcov-report/models/user-privilege.entity.ts.html +315 -315
- package/coverage/lcov-report/models/user-system-access.entity.ts.html +315 -315
- package/coverage/lcov-report/models/user.entity.ts.html +522 -522
- package/coverage/lcov-report/prettify.css +1 -1
- package/coverage/lcov-report/prettify.js +2 -2
- package/coverage/lcov-report/redis-client/index.html +115 -115
- package/coverage/lcov-report/redis-client/redis.service.ts.html +240 -240
- package/coverage/lcov-report/session/index.html +115 -115
- package/coverage/lcov-report/session/session.service.ts.html +246 -246
- package/coverage/lcov-report/sorter.js +196 -196
- package/coverage/lcov.info +2490 -2490
- package/coverage/test-report.xml +128 -128
- package/dist/__tests__/unit/components/system-privilege/system-privilege.spec.js +0 -3
- package/dist/__tests__/unit/components/system-privilege/system-privilege.spec.js.map +1 -1
- package/dist/src/components/login-user/interfaces/check-user-info-duplicated.interface.d.ts +1 -0
- package/dist/src/components/login-user/interfaces/user-info.interface.d.ts +1 -0
- package/dist/src/components/login-user/login-user.d.ts +4 -2
- package/dist/src/components/login-user/login-user.js +33 -7
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/system-privilege/system-privilege.d.ts +0 -2
- package/dist/src/components/system-privilege/system-privilege.js +0 -8
- package/dist/src/components/system-privilege/system-privilege.js.map +1 -1
- package/dist/src/enum/index.d.ts +1 -0
- package/dist/src/enum/index.js +1 -0
- package/dist/src/enum/index.js.map +1 -1
- package/dist/src/enum/login-status.enum.d.ts +4 -0
- package/dist/src/enum/login-status.enum.js +9 -0
- package/dist/src/enum/login-status.enum.js.map +1 -0
- package/dist/src/interfaces/system-privilege.interface.d.ts +0 -1
- package/dist/src/models/login-history.entity.d.ts +2 -0
- package/dist/src/models/login-history.entity.js +8 -0
- package/dist/src/models/login-history.entity.js.map +1 -1
- package/dist/src/models/system-privilege.entity.d.ts +0 -1
- package/dist/src/models/system-privilege.entity.js +1 -9
- package/dist/src/models/system-privilege.entity.js.map +1 -1
- package/dist/src/models/user.entity.d.ts +1 -0
- package/dist/src/models/user.entity.js +7 -0
- package/dist/src/models/user.entity.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/migrations/20240314080602-create-user-table.js +4 -0
- package/migrations/20240314080605-create-login-history-table.js +4 -0
- package/migrations/20240527064926-create-system-privilege-table.js +1 -5
- package/migrations/20240528023018-user-system-access-table.js +75 -75
- package/migrations/20240528032229-user-privilege-table.js +75 -75
- package/migrations/20240528063003-create-group-privilege-table.js +75 -75
- package/migrations/20240528063107-create-user-object-privilege-table.js +83 -83
- package/package.json +1 -1
- package/src/components/login-user/interfaces/check-user-info-duplicated.interface.ts +1 -0
- package/src/components/login-user/interfaces/user-info.interface.ts +1 -0
- package/src/components/login-user/login-user.ts +39 -8
- package/src/components/system-privilege/system-privilege.ts +0 -10
- package/src/enum/index.ts +1 -0
- package/src/enum/login-status.enum.ts +4 -0
- package/src/interfaces/system-privilege.interface.ts +0 -1
- package/src/models/login-history.entity.ts +7 -0
- package/src/models/system-privilege.entity.ts +1 -8
- package/src/models/user.entity.ts +6 -0
@@ -11,7 +11,6 @@ import { ISystemLogin } from '../../../src/interfaces/system-login.interface';
|
|
11
11
|
import Staff from '../../models/staff.entity';
|
12
12
|
import SystemPrivilege from '../../models/system-privilege.entity';
|
13
13
|
import LoginHistory from '../../models/login-history.entity';
|
14
|
-
import UserGroup from '../../models/user-group.entity';
|
15
14
|
import { YN } from '../../enum/yn.enum';
|
16
15
|
import { UserStatus } from '../../enum';
|
17
16
|
import { ApplicationConfig, ComponentConfig } from '@tomei/config';
|
@@ -31,10 +30,12 @@ import { UserObjectPrivilegeRepository } from '../user-object-privilege/user-obj
|
|
31
30
|
import GroupPrivilegeModel from '../../models/group-privilege.entity';
|
32
31
|
import { GroupObjectPrivilegeRepository } from '../group-object-privilege/group-object-privilege.repository';
|
33
32
|
import * as speakeasy from 'speakeasy';
|
33
|
+
import { LoginStatusEnum } from '../../enum/login-status.enum';
|
34
34
|
|
35
35
|
export class LoginUser extends LoginUserBase {
|
36
36
|
ObjectId: string;
|
37
37
|
Email: string;
|
38
|
+
private _UserName: string;
|
38
39
|
private _Password: string;
|
39
40
|
private _Status: UserStatus;
|
40
41
|
private _DefaultPasswordChangedYN: YN;
|
@@ -102,6 +103,14 @@ export class LoginUser extends LoginUserBase {
|
|
102
103
|
this._Status = value;
|
103
104
|
}
|
104
105
|
|
106
|
+
get UserName(): string {
|
107
|
+
return this._UserName;
|
108
|
+
}
|
109
|
+
|
110
|
+
set UserName(value: string) {
|
111
|
+
this._UserName = value;
|
112
|
+
}
|
113
|
+
|
105
114
|
get DefaultPasswordChangedYN(): YN {
|
106
115
|
return this._DefaultPasswordChangedYN;
|
107
116
|
}
|
@@ -244,6 +253,7 @@ export class LoginUser extends LoginUserBase {
|
|
244
253
|
// set all the class properties
|
245
254
|
if (userInfo) {
|
246
255
|
this.UserId = userInfo.UserId;
|
256
|
+
this.UserName = userInfo.FullName;
|
247
257
|
this.FullName = userInfo.FullName;
|
248
258
|
this.IDNo = userInfo.IDNo;
|
249
259
|
this.Email = userInfo.Email;
|
@@ -295,6 +305,7 @@ export class LoginUser extends LoginUserBase {
|
|
295
305
|
if (user) {
|
296
306
|
const userAttr: IUserAttr = {
|
297
307
|
UserId: user.UserId,
|
308
|
+
UserName: user.UserName,
|
298
309
|
FullName: user.Staff.FullName,
|
299
310
|
IDNo: user.Staff.IdNo,
|
300
311
|
ContactNo: user.Staff.Mobile,
|
@@ -356,6 +367,7 @@ export class LoginUser extends LoginUserBase {
|
|
356
367
|
if (user) {
|
357
368
|
const userAttr: IUserAttr = {
|
358
369
|
UserId: user.UserId,
|
370
|
+
UserName: user.UserName,
|
359
371
|
FullName: user.Staff.FullName,
|
360
372
|
IDNo: user.Staff.IdNo,
|
361
373
|
ContactNo: user.Staff.Mobile,
|
@@ -491,6 +503,7 @@ export class LoginUser extends LoginUserBase {
|
|
491
503
|
await LoginUser._Repository.update(
|
492
504
|
{
|
493
505
|
FullName: this.FullName,
|
506
|
+
UserName: this.UserName,
|
494
507
|
IDNo: this.IDNo,
|
495
508
|
Email: this.Email,
|
496
509
|
ContactNo: this.ContactNo,
|
@@ -554,6 +567,7 @@ export class LoginUser extends LoginUserBase {
|
|
554
567
|
SystemCode: system.SystemCode,
|
555
568
|
OriginIp: ipAddress,
|
556
569
|
CreatedAt: new Date(),
|
570
|
+
LoginStatus: LoginStatusEnum.SUCCESS,
|
557
571
|
dbTransaction,
|
558
572
|
});
|
559
573
|
|
@@ -569,6 +583,14 @@ export class LoginUser extends LoginUserBase {
|
|
569
583
|
|
570
584
|
return `${this.UserId}:${sessionId}`;
|
571
585
|
} catch (error) {
|
586
|
+
await LoginUser._LoginHistoryRepository.create({
|
587
|
+
UserId: this.UserId,
|
588
|
+
SystemCode: systemCode,
|
589
|
+
OriginIp: ipAddress,
|
590
|
+
LoginStatus: LoginStatusEnum.FAILURE,
|
591
|
+
CreatedAt: new Date(),
|
592
|
+
dbTransaction,
|
593
|
+
});
|
572
594
|
throw error;
|
573
595
|
}
|
574
596
|
}
|
@@ -814,12 +836,12 @@ export class LoginUser extends LoginUserBase {
|
|
814
836
|
// Add privileges from the group to the privileges array
|
815
837
|
const groupPrivileges: string[] = [];
|
816
838
|
for (const groupPrivilege of group.GroupPrivileges) {
|
817
|
-
groupPrivileges.push(groupPrivilege.Privilege.
|
839
|
+
groupPrivileges.push(groupPrivilege.Privilege.PrivilegeCode);
|
818
840
|
}
|
819
841
|
|
820
842
|
const ops: string[] = [];
|
821
843
|
for (const objectPrivilege of objectPrivileges) {
|
822
|
-
ops.push(objectPrivilege.Privilege.
|
844
|
+
ops.push(objectPrivilege.Privilege.PrivilegeCode);
|
823
845
|
}
|
824
846
|
|
825
847
|
privileges = [...privileges, ...groupPrivileges, ...ops];
|
@@ -860,7 +882,9 @@ export class LoginUser extends LoginUserBase {
|
|
860
882
|
transaction: dbTransaction,
|
861
883
|
});
|
862
884
|
|
863
|
-
const privileges: string[] = userPrivileges.map(
|
885
|
+
const privileges: string[] = userPrivileges.map(
|
886
|
+
(u) => u.Privilege.PrivilegeCode,
|
887
|
+
);
|
864
888
|
return privileges;
|
865
889
|
} catch (error) {
|
866
890
|
throw error;
|
@@ -888,7 +912,7 @@ export class LoginUser extends LoginUserBase {
|
|
888
912
|
});
|
889
913
|
|
890
914
|
const privilegesCodes: string[] = userObjectPrivileges.map(
|
891
|
-
(u) => u.Privilege.
|
915
|
+
(u) => u.Privilege.PrivilegeCode,
|
892
916
|
);
|
893
917
|
return privilegesCodes;
|
894
918
|
} catch (error) {
|
@@ -985,7 +1009,7 @@ export class LoginUser extends LoginUserBase {
|
|
985
1009
|
try {
|
986
1010
|
//Part 1: Prepare Query Params
|
987
1011
|
//Params is all optional but at least one is required.
|
988
|
-
const { Email, IdType, IdNo, ContactNo } = query;
|
1012
|
+
const { Email, UserName, IdType, IdNo, ContactNo } = query;
|
989
1013
|
//Prepare the Params to be used as OR operation in SQL query.
|
990
1014
|
const where = {
|
991
1015
|
[Op.or]: {},
|
@@ -993,6 +1017,10 @@ export class LoginUser extends LoginUserBase {
|
|
993
1017
|
if (Email) {
|
994
1018
|
where[Op.or]['Email'] = Email;
|
995
1019
|
}
|
1020
|
+
|
1021
|
+
if (UserName) {
|
1022
|
+
where[Op.or]['UserName'] = UserName;
|
1023
|
+
}
|
996
1024
|
//If Params.IdNo is not null, then Params.IdType is required and vice versa.
|
997
1025
|
if (IdType && IdNo) {
|
998
1026
|
where[Op.or]['IdType'] = IdType;
|
@@ -1269,16 +1297,17 @@ export class LoginUser extends LoginUserBase {
|
|
1269
1297
|
|
1270
1298
|
//Part 2: Validation
|
1271
1299
|
//Make sure Params.user.Email got values. If not, throw new ClassError
|
1272
|
-
if (!user.Email) {
|
1300
|
+
if (!user.Email && !user.UserName) {
|
1273
1301
|
throw new ClassError(
|
1274
1302
|
'LoginUser',
|
1275
1303
|
'LoginUserErrMsg0X',
|
1276
|
-
'Email is required',
|
1304
|
+
'Email and Username is required',
|
1277
1305
|
);
|
1278
1306
|
}
|
1279
1307
|
//Check if user info exists, call LoginUser.CheckUserInfoDuplicated method
|
1280
1308
|
await LoginUser.checkUserInfoDuplicated(dbTransaction, {
|
1281
1309
|
Email: user.Email,
|
1310
|
+
UserName: user.UserName,
|
1282
1311
|
IdType: user.IDType,
|
1283
1312
|
IdNo: user.IDNo,
|
1284
1313
|
ContactNo: user.ContactNo,
|
@@ -1290,6 +1319,7 @@ export class LoginUser extends LoginUserBase {
|
|
1290
1319
|
//Part 4: Insert User Record
|
1291
1320
|
//Set userToBeCreated to the instantiation of new LoginUser (using private constructor)
|
1292
1321
|
const userInfo: IUserAttr = {
|
1322
|
+
UserName: user.UserName,
|
1293
1323
|
FullName: user.FullName,
|
1294
1324
|
IDNo: user.IDNo,
|
1295
1325
|
Email: user.Email,
|
@@ -1316,6 +1346,7 @@ export class LoginUser extends LoginUserBase {
|
|
1316
1346
|
const newUser = await LoginUser._Repository.create(
|
1317
1347
|
{
|
1318
1348
|
Email: userInfo.Email,
|
1349
|
+
UserName: userInfo.UserName,
|
1319
1350
|
Password: userInfo.Password,
|
1320
1351
|
Status: userInfo.Status,
|
1321
1352
|
DefaultPasswordChangedYN: userInfo.DefaultPasswordChangedYN,
|
@@ -24,14 +24,6 @@ export class SystemPrivilege extends ObjectBase {
|
|
24
24
|
this.ObjectId = value;
|
25
25
|
}
|
26
26
|
|
27
|
-
set Name(value: string) {
|
28
|
-
this.ObjectName = value;
|
29
|
-
}
|
30
|
-
|
31
|
-
get Name() {
|
32
|
-
return this.ObjectName;
|
33
|
-
}
|
34
|
-
|
35
27
|
get CreatedAt() {
|
36
28
|
return this._CreatedAt;
|
37
29
|
}
|
@@ -56,7 +48,6 @@ export class SystemPrivilege extends ObjectBase {
|
|
56
48
|
if (systemPrivilegeAttr) {
|
57
49
|
this.ObjectId = systemPrivilegeAttr.PrivilegeCode;
|
58
50
|
this.SystemCode = systemPrivilegeAttr.SystemCode;
|
59
|
-
this.ObjectName = systemPrivilegeAttr.Name;
|
60
51
|
this.Description = systemPrivilegeAttr.Description;
|
61
52
|
this.Status = systemPrivilegeAttr.Status;
|
62
53
|
this._CreatedById = systemPrivilegeAttr.CreatedById;
|
@@ -79,7 +70,6 @@ export class SystemPrivilege extends ObjectBase {
|
|
79
70
|
if (systemPrivilegeAttr) {
|
80
71
|
systemPrivilege.ObjectId = systemPrivilegeAttr.PrivilegeCode;
|
81
72
|
systemPrivilege.SystemCode = systemPrivilegeAttr.SystemCode;
|
82
|
-
systemPrivilege.ObjectName = systemPrivilegeAttr.Name;
|
83
73
|
systemPrivilege.Description = systemPrivilegeAttr.Description;
|
84
74
|
systemPrivilege.Status = systemPrivilegeAttr.Status;
|
85
75
|
systemPrivilege._CreatedById = systemPrivilegeAttr.CreatedById;
|
package/src/enum/index.ts
CHANGED
@@ -9,6 +9,7 @@ import {
|
|
9
9
|
} from 'sequelize-typescript';
|
10
10
|
import User from './user.entity';
|
11
11
|
import SystemModel from './system.entity';
|
12
|
+
import { LoginStatusEnum } from '../enum/login-status.enum';
|
12
13
|
|
13
14
|
@Table({
|
14
15
|
tableName: 'sso_LoginHistory',
|
@@ -39,6 +40,12 @@ export default class LoginHistory extends Model {
|
|
39
40
|
})
|
40
41
|
SystemCode: number;
|
41
42
|
|
43
|
+
@Column({
|
44
|
+
allowNull: true,
|
45
|
+
type: DataType.STRING(191),
|
46
|
+
})
|
47
|
+
LoginStatus: LoginStatusEnum;
|
48
|
+
|
42
49
|
@Column({
|
43
50
|
allowNull: true,
|
44
51
|
type: DataType.STRING(191),
|
@@ -23,7 +23,7 @@ export default class SystemPrivilegeModel extends Model {
|
|
23
23
|
@Column({
|
24
24
|
primaryKey: true,
|
25
25
|
allowNull: false,
|
26
|
-
type: DataType.STRING(
|
26
|
+
type: DataType.STRING(50),
|
27
27
|
field: 'PrivilegeCode',
|
28
28
|
})
|
29
29
|
PrivilegeCode: string;
|
@@ -36,13 +36,6 @@ export default class SystemPrivilegeModel extends Model {
|
|
36
36
|
})
|
37
37
|
SystemCode: string;
|
38
38
|
|
39
|
-
@Column({
|
40
|
-
allowNull: false,
|
41
|
-
type: DataType.STRING(200),
|
42
|
-
field: 'Name',
|
43
|
-
})
|
44
|
-
Name: string;
|
45
|
-
|
46
39
|
@Column({
|
47
40
|
allowNull: true,
|
48
41
|
type: DataType.STRING(3000),
|