@tomei/sso 0.61.0 → 0.61.1
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/__tests__/unit/components/group-privilege/group-privilege.test.d.ts +1 -0
- package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js +71 -0
- package/dist/__tests__/unit/components/group-privilege/group-privilege.test.js.map +1 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.d.ts +0 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js +6 -0
- package/dist/__tests__/unit/components/login-user/login-user.spec.js.map +1 -0
- package/dist/src/components/login-history/login-history.d.ts +23 -0
- package/dist/src/components/login-history/login-history.js +88 -0
- package/dist/src/components/login-history/login-history.js.map +1 -0
- package/dist/src/components/login-user/user.js +3 -2
- package/dist/src/components/login-user/user.js.map +1 -1
- package/dist/src/interfaces/login-history-search-attr.interface.d.ts +8 -0
- package/dist/src/interfaces/login-history-search-attr.interface.js +3 -0
- package/dist/src/interfaces/login-history-search-attr.interface.js.map +1 -0
- package/dist/src/interfaces/login-history.interface.d.ts +11 -0
- package/dist/src/interfaces/login-history.interface.js +3 -0
- package/dist/src/interfaces/login-history.interface.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/api-key/api-key.repository.ts +15 -15
- package/src/components/api-key/api-key.ts +448 -448
- package/src/components/api-key/index.ts +4 -4
- package/src/components/building/building.repository.ts +27 -27
- package/src/components/building/index.ts +2 -2
- package/src/components/group/group.repository.ts +26 -26
- package/src/components/group/group.ts +2284 -2284
- package/src/components/group/index.ts +3 -3
- package/src/components/group-object-privilege/group-object-privilege.repository.ts +25 -25
- package/src/components/group-object-privilege/group-object-privilege.ts +278 -278
- package/src/components/group-object-privilege/index.ts +2 -2
- package/src/components/group-privilege/group-privilege.repository.ts +29 -29
- package/src/components/group-privilege/group-privilege.ts +84 -84
- package/src/components/group-privilege/index.ts +2 -2
- package/src/components/group-reporting-user/group-reporting-user.repository.ts +23 -23
- package/src/components/group-reporting-user/group-reporting-user.ts +506 -506
- package/src/components/group-reporting-user/index.ts +3 -3
- package/src/components/group-system-access/group-system-access.repository.ts +43 -43
- package/src/components/group-system-access/group-system-access.ts +90 -90
- package/src/components/group-system-access/index.ts +2 -2
- package/src/components/index.ts +20 -20
- package/src/components/login-user/index.ts +5 -5
- package/src/components/login-user/interfaces/check-user-info-duplicated.interface.ts +7 -7
- package/src/components/login-user/interfaces/index.ts +1 -1
- package/src/components/login-user/interfaces/system-access.interface.ts +13 -13
- package/src/components/login-user/interfaces/user-info.interface.ts +34 -34
- package/src/components/login-user/login-user.ts +362 -362
- package/src/components/login-user/user.repository.ts +11 -11
- package/src/components/login-user/user.ts +3 -2
- package/src/components/password-hash/index.ts +2 -2
- package/src/components/password-hash/interfaces/index.ts +1 -1
- package/src/components/password-hash/interfaces/password-hash-service.interface.ts +4 -4
- package/src/components/password-hash/password-hash.service.ts +14 -14
- package/src/components/staff/index.ts +2 -2
- package/src/components/staff/staff.repository.ts +27 -27
- package/src/components/system/index.ts +3 -3
- package/src/components/system/system.repository.ts +11 -11
- package/src/components/system/system.ts +456 -456
- package/src/components/system-privilege/index.ts +4 -4
- package/src/components/system-privilege/system-privilege.repository.ts +18 -18
- package/src/components/system-privilege/system-privilege.ts +541 -541
- package/src/components/user-group/index.ts +2 -2
- package/src/components/user-group/user-group.repository.ts +19 -19
- package/src/components/user-group/user-group.ts +764 -764
- package/src/components/user-object-privilege/index.ts +2 -2
- package/src/components/user-object-privilege/user-object-privilege.repository.ts +11 -11
- package/src/components/user-object-privilege/user-object-privilege.ts +79 -79
- package/src/components/user-password-history/index.ts +2 -2
- package/src/components/user-password-history/user-password-history.repository.ts +39 -39
- package/src/components/user-password-history/user-password-history.ts +187 -187
- package/src/components/user-privilege/index.ts +2 -2
- package/src/components/user-privilege/user-privilege.repository.ts +25 -25
- package/src/components/user-privilege/user-privilege.ts +662 -662
- package/src/components/user-reporting-hierarchy/index.ts +2 -2
- package/src/components/user-reporting-hierarchy/user-reporting-hierarchy.repository.ts +30 -30
- package/src/components/user-reporting-hierarchy/user-reporting-hierarchy.ts +505 -505
- package/src/components/user-system-access/index.ts +2 -2
- package/src/components/user-system-access/user-system-access.repository.ts +41 -41
- package/src/database.ts +15 -15
- package/src/enum/api-key.enum.ts +5 -5
- package/src/enum/building-type.enum.ts +6 -6
- package/src/enum/group-type.enum.ts +8 -8
- package/src/enum/index.ts +6 -6
- package/src/enum/login-status.enum.ts +4 -4
- package/src/enum/object-status.enum.ts +4 -4
- package/src/enum/user-status.enum.ts +7 -7
- package/src/enum/yn.enum.ts +4 -4
- package/src/index.ts +8 -8
- package/src/interfaces/api-key-attr.interface.ts +16 -16
- package/src/interfaces/group-object-privilege.interface.ts +14 -14
- package/src/interfaces/group-privilege.interface.ts +10 -10
- package/src/interfaces/group-reporting-user.interface.ts +11 -11
- package/src/interfaces/group-search-attr.interface.ts +9 -9
- package/src/interfaces/group-system-access.interface.ts +10 -10
- package/src/interfaces/group.interface.ts +17 -17
- package/src/interfaces/index.ts +13 -13
- package/src/interfaces/system-login.interface.ts +6 -6
- package/src/interfaces/system-privilege-search.interface.ts +5 -5
- package/src/interfaces/system-privilege.interface.ts +11 -11
- package/src/interfaces/system-search-attr.interface.ts +5 -5
- package/src/interfaces/system.interface.ts +15 -15
- package/src/interfaces/user-group.interface.ts +12 -12
- package/src/interfaces/user-object-privilege.interface.ts +14 -14
- package/src/interfaces/user-password-history.interface.ts +6 -6
- package/src/interfaces/user-privilege.interface.ts +10 -10
- package/src/interfaces/user-reporting-hierarchy.interface.ts +11 -11
- package/src/interfaces/user-session.interface.ts +5 -5
- package/src/interfaces/user-system-access.interface.ts +10 -10
- package/src/models/api-key-entity.ts +101 -101
- package/src/models/building.entity.ts +103 -103
- package/src/models/group-object-privilege.entity.ts +91 -91
- package/src/models/group-privilege.entity.ts +78 -78
- package/src/models/group-reporting-user.entity.ts +95 -95
- package/src/models/group-system-access.entity.ts +81 -81
- package/src/models/group.entity.ts +127 -127
- package/src/models/staff.entity.ts +91 -91
- package/src/models/system-privilege.entity.ts +90 -90
- package/src/models/system.entity.ts +113 -113
- package/src/models/user-group.entity.ts +91 -91
- package/src/models/user-object-privilege.entity.ts +90 -90
- package/src/models/user-password-history.ts +51 -51
- package/src/models/user-privilege.entity.ts +78 -78
- package/src/models/user-reporting-hierarchy.entity.ts +102 -102
- package/src/models/user-system-access.entity.ts +87 -87
- package/src/models/user.entity.ts +193 -193
- package/src/redis-client/__mocks__/jest-initial-setup.ts +2 -2
- package/src/redis-client/__mocks__/redis-mock.ts +28 -28
- package/src/redis-client/index.ts +1 -1
- package/src/redis-client/redis.service.ts +75 -75
- package/src/session/index.ts +2 -2
- package/src/session/interfaces/index.ts +1 -1
- package/src/session/interfaces/session-service.interface.ts +26 -26
- package/src/session/session.service.ts +96 -96
- package/src/types/auth-context.ts +10 -10
- package/src/types/index.ts +1 -1
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './user-object-privilege';
|
2
|
-
export * from './user-object-privilege.repository';
|
1
|
+
export * from './user-object-privilege';
|
2
|
+
export * from './user-object-privilege.repository';
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import UserObjectPrivilegeModel from '../../models/user-object-privilege.entity';
|
2
|
-
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
3
|
-
|
4
|
-
export class UserObjectPrivilegeRepository
|
5
|
-
extends RepositoryBase<UserObjectPrivilegeModel>
|
6
|
-
implements IRepositoryBase<UserObjectPrivilegeModel>
|
7
|
-
{
|
8
|
-
constructor() {
|
9
|
-
super(UserObjectPrivilegeModel);
|
10
|
-
}
|
11
|
-
}
|
1
|
+
import UserObjectPrivilegeModel from '../../models/user-object-privilege.entity';
|
2
|
+
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
3
|
+
|
4
|
+
export class UserObjectPrivilegeRepository
|
5
|
+
extends RepositoryBase<UserObjectPrivilegeModel>
|
6
|
+
implements IRepositoryBase<UserObjectPrivilegeModel>
|
7
|
+
{
|
8
|
+
constructor() {
|
9
|
+
super(UserObjectPrivilegeModel);
|
10
|
+
}
|
11
|
+
}
|
@@ -1,79 +1,79 @@
|
|
1
|
-
import { ClassError, ObjectBase } from '@tomei/general';
|
2
|
-
import { UserObjectPrivilegeRepository } from './user-object-privilege.repository';
|
3
|
-
import { IUserObjectPrivilegeAttr } from '../../interfaces/user-object-privilege.interface';
|
4
|
-
import { ObjectStatus } from '../../enum/object-status.enum';
|
5
|
-
|
6
|
-
export class UserObjectPrivilege extends ObjectBase {
|
7
|
-
TableName = 'sso_UserObjectPrivilege';
|
8
|
-
ObjectName: string;
|
9
|
-
ObjectPrivilegeId: number;
|
10
|
-
UserId: number;
|
11
|
-
SystemPrivilegeId: string;
|
12
|
-
ObjectId: string;
|
13
|
-
ObjectType: string;
|
14
|
-
Status: ObjectStatus;
|
15
|
-
private _CreatedAt: Date;
|
16
|
-
private _UpdatedAt: Date;
|
17
|
-
private _CreatedById: number;
|
18
|
-
private _UpdatedById: number;
|
19
|
-
|
20
|
-
get CreatedAt() {
|
21
|
-
return this._CreatedAt;
|
22
|
-
}
|
23
|
-
|
24
|
-
get UpdatedAt() {
|
25
|
-
return this._UpdatedAt;
|
26
|
-
}
|
27
|
-
|
28
|
-
get CreatedById() {
|
29
|
-
return this._CreatedById;
|
30
|
-
}
|
31
|
-
|
32
|
-
get UpdatedById() {
|
33
|
-
return this._UpdatedById;
|
34
|
-
}
|
35
|
-
|
36
|
-
private static _Repository = new UserObjectPrivilegeRepository();
|
37
|
-
|
38
|
-
private constructor(userObjectPrivilegeAttr?: IUserObjectPrivilegeAttr) {
|
39
|
-
super();
|
40
|
-
if (userObjectPrivilegeAttr) {
|
41
|
-
this.ObjectPrivilegeId = userObjectPrivilegeAttr.ObjectPrivilegeId;
|
42
|
-
this.UserId = userObjectPrivilegeAttr.UserId;
|
43
|
-
this.SystemPrivilegeId = userObjectPrivilegeAttr.SystemPrivilegeId;
|
44
|
-
this.ObjectId = userObjectPrivilegeAttr.ObjectId;
|
45
|
-
this.ObjectType = userObjectPrivilegeAttr.ObjectType;
|
46
|
-
this.Status = userObjectPrivilegeAttr.Status;
|
47
|
-
this._CreatedAt = userObjectPrivilegeAttr.CreatedAt;
|
48
|
-
this._UpdatedAt = userObjectPrivilegeAttr.UpdatedAt;
|
49
|
-
this._CreatedById = userObjectPrivilegeAttr.CreatedById;
|
50
|
-
this._UpdatedById = userObjectPrivilegeAttr.UpdatedById;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
public static async init(dbTransaction?: any, ObjectPrivilegeId?: number) {
|
55
|
-
try {
|
56
|
-
const userObjectPrivilege = new UserObjectPrivilege();
|
57
|
-
if (ObjectPrivilegeId) {
|
58
|
-
const userObjectPrivilegeAttr = await this._Repository.findOne({
|
59
|
-
where: { ObjectPrivilegeId },
|
60
|
-
transaction: dbTransaction,
|
61
|
-
});
|
62
|
-
if (userObjectPrivilegeAttr) {
|
63
|
-
return new UserObjectPrivilege(
|
64
|
-
userObjectPrivilegeAttr.get({ plain: true }),
|
65
|
-
);
|
66
|
-
} else {
|
67
|
-
throw new ClassError(
|
68
|
-
'UserObjectPrivilege',
|
69
|
-
'UserObjectPrivilegeErrMsg00',
|
70
|
-
'UserObjectPrivilege not found',
|
71
|
-
);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
return userObjectPrivilege;
|
75
|
-
} catch (error) {
|
76
|
-
throw error;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}
|
1
|
+
import { ClassError, ObjectBase } from '@tomei/general';
|
2
|
+
import { UserObjectPrivilegeRepository } from './user-object-privilege.repository';
|
3
|
+
import { IUserObjectPrivilegeAttr } from '../../interfaces/user-object-privilege.interface';
|
4
|
+
import { ObjectStatus } from '../../enum/object-status.enum';
|
5
|
+
|
6
|
+
export class UserObjectPrivilege extends ObjectBase {
|
7
|
+
TableName = 'sso_UserObjectPrivilege';
|
8
|
+
ObjectName: string;
|
9
|
+
ObjectPrivilegeId: number;
|
10
|
+
UserId: number;
|
11
|
+
SystemPrivilegeId: string;
|
12
|
+
ObjectId: string;
|
13
|
+
ObjectType: string;
|
14
|
+
Status: ObjectStatus;
|
15
|
+
private _CreatedAt: Date;
|
16
|
+
private _UpdatedAt: Date;
|
17
|
+
private _CreatedById: number;
|
18
|
+
private _UpdatedById: number;
|
19
|
+
|
20
|
+
get CreatedAt() {
|
21
|
+
return this._CreatedAt;
|
22
|
+
}
|
23
|
+
|
24
|
+
get UpdatedAt() {
|
25
|
+
return this._UpdatedAt;
|
26
|
+
}
|
27
|
+
|
28
|
+
get CreatedById() {
|
29
|
+
return this._CreatedById;
|
30
|
+
}
|
31
|
+
|
32
|
+
get UpdatedById() {
|
33
|
+
return this._UpdatedById;
|
34
|
+
}
|
35
|
+
|
36
|
+
private static _Repository = new UserObjectPrivilegeRepository();
|
37
|
+
|
38
|
+
private constructor(userObjectPrivilegeAttr?: IUserObjectPrivilegeAttr) {
|
39
|
+
super();
|
40
|
+
if (userObjectPrivilegeAttr) {
|
41
|
+
this.ObjectPrivilegeId = userObjectPrivilegeAttr.ObjectPrivilegeId;
|
42
|
+
this.UserId = userObjectPrivilegeAttr.UserId;
|
43
|
+
this.SystemPrivilegeId = userObjectPrivilegeAttr.SystemPrivilegeId;
|
44
|
+
this.ObjectId = userObjectPrivilegeAttr.ObjectId;
|
45
|
+
this.ObjectType = userObjectPrivilegeAttr.ObjectType;
|
46
|
+
this.Status = userObjectPrivilegeAttr.Status;
|
47
|
+
this._CreatedAt = userObjectPrivilegeAttr.CreatedAt;
|
48
|
+
this._UpdatedAt = userObjectPrivilegeAttr.UpdatedAt;
|
49
|
+
this._CreatedById = userObjectPrivilegeAttr.CreatedById;
|
50
|
+
this._UpdatedById = userObjectPrivilegeAttr.UpdatedById;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
public static async init(dbTransaction?: any, ObjectPrivilegeId?: number) {
|
55
|
+
try {
|
56
|
+
const userObjectPrivilege = new UserObjectPrivilege();
|
57
|
+
if (ObjectPrivilegeId) {
|
58
|
+
const userObjectPrivilegeAttr = await this._Repository.findOne({
|
59
|
+
where: { ObjectPrivilegeId },
|
60
|
+
transaction: dbTransaction,
|
61
|
+
});
|
62
|
+
if (userObjectPrivilegeAttr) {
|
63
|
+
return new UserObjectPrivilege(
|
64
|
+
userObjectPrivilegeAttr.get({ plain: true }),
|
65
|
+
);
|
66
|
+
} else {
|
67
|
+
throw new ClassError(
|
68
|
+
'UserObjectPrivilege',
|
69
|
+
'UserObjectPrivilegeErrMsg00',
|
70
|
+
'UserObjectPrivilege not found',
|
71
|
+
);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
return userObjectPrivilege;
|
75
|
+
} catch (error) {
|
76
|
+
throw error;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './user-password-history';
|
2
|
-
export * from './user-password-history.repository';
|
1
|
+
export * from './user-password-history';
|
2
|
+
export * from './user-password-history.repository';
|
@@ -1,39 +1,39 @@
|
|
1
|
-
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
2
|
-
import UserPasswordHistoryModel from '../../models/user-password-history';
|
3
|
-
import { Op } from 'sequelize';
|
4
|
-
|
5
|
-
export class UserPasswordHistoryRepository
|
6
|
-
extends RepositoryBase<UserPasswordHistoryModel>
|
7
|
-
implements IRepositoryBase<UserPasswordHistoryModel>
|
8
|
-
{
|
9
|
-
constructor() {
|
10
|
-
super(UserPasswordHistoryModel);
|
11
|
-
}
|
12
|
-
|
13
|
-
async findByPk(id: string, options?: any): Promise<UserPasswordHistoryModel> {
|
14
|
-
return await UserPasswordHistoryModel.findByPk(parseInt(id), options);
|
15
|
-
}
|
16
|
-
|
17
|
-
async destroy(HistoryId: number, dbTransaction: any): Promise<void> {
|
18
|
-
await UserPasswordHistoryModel.destroy({
|
19
|
-
where: {
|
20
|
-
HistoryId: HistoryId,
|
21
|
-
},
|
22
|
-
transaction: dbTransaction,
|
23
|
-
});
|
24
|
-
}
|
25
|
-
|
26
|
-
async destroyMultiple(
|
27
|
-
HistoryIdList: string[],
|
28
|
-
dbTransaction: any,
|
29
|
-
): Promise<void> {
|
30
|
-
await UserPasswordHistoryModel.destroy({
|
31
|
-
where: {
|
32
|
-
HistoryId: {
|
33
|
-
[Op.in]: HistoryIdList,
|
34
|
-
},
|
35
|
-
},
|
36
|
-
transaction: dbTransaction,
|
37
|
-
});
|
38
|
-
}
|
39
|
-
}
|
1
|
+
import { RepositoryBase, IRepositoryBase } from '@tomei/general';
|
2
|
+
import UserPasswordHistoryModel from '../../models/user-password-history';
|
3
|
+
import { Op } from 'sequelize';
|
4
|
+
|
5
|
+
export class UserPasswordHistoryRepository
|
6
|
+
extends RepositoryBase<UserPasswordHistoryModel>
|
7
|
+
implements IRepositoryBase<UserPasswordHistoryModel>
|
8
|
+
{
|
9
|
+
constructor() {
|
10
|
+
super(UserPasswordHistoryModel);
|
11
|
+
}
|
12
|
+
|
13
|
+
async findByPk(id: string, options?: any): Promise<UserPasswordHistoryModel> {
|
14
|
+
return await UserPasswordHistoryModel.findByPk(parseInt(id), options);
|
15
|
+
}
|
16
|
+
|
17
|
+
async destroy(HistoryId: number, dbTransaction: any): Promise<void> {
|
18
|
+
await UserPasswordHistoryModel.destroy({
|
19
|
+
where: {
|
20
|
+
HistoryId: HistoryId,
|
21
|
+
},
|
22
|
+
transaction: dbTransaction,
|
23
|
+
});
|
24
|
+
}
|
25
|
+
|
26
|
+
async destroyMultiple(
|
27
|
+
HistoryIdList: string[],
|
28
|
+
dbTransaction: any,
|
29
|
+
): Promise<void> {
|
30
|
+
await UserPasswordHistoryModel.destroy({
|
31
|
+
where: {
|
32
|
+
HistoryId: {
|
33
|
+
[Op.in]: HistoryIdList,
|
34
|
+
},
|
35
|
+
},
|
36
|
+
transaction: dbTransaction,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
}
|
@@ -1,187 +1,187 @@
|
|
1
|
-
import { ClassError, ObjectBase } from '@tomei/general';
|
2
|
-
import { ComponentConfig } from '@tomei/config';
|
3
|
-
import { IUserPasswordHistoryAttr } from '../../interfaces/user-password-history.interface';
|
4
|
-
import { UserPasswordHistoryRepository } from './user-password-history.repository';
|
5
|
-
import { PasswordHashService } from '../../components/password-hash';
|
6
|
-
|
7
|
-
export class UserPasswordHistory
|
8
|
-
extends ObjectBase
|
9
|
-
implements IUserPasswordHistoryAttr
|
10
|
-
{
|
11
|
-
ObjectId: string;
|
12
|
-
ObjectName: string;
|
13
|
-
ObjectType = 'UserPasswordHistory';
|
14
|
-
TableName = 'sso_UserPasswordHistory';
|
15
|
-
UserId: number;
|
16
|
-
PasswordHash: string;
|
17
|
-
private _CreatedAt: Date;
|
18
|
-
|
19
|
-
private static _Repo = new UserPasswordHistoryRepository();
|
20
|
-
|
21
|
-
get HistoryId(): string {
|
22
|
-
return this.ObjectId;
|
23
|
-
}
|
24
|
-
|
25
|
-
set HistoryId(value: string) {
|
26
|
-
this.ObjectId = value;
|
27
|
-
}
|
28
|
-
|
29
|
-
get CreatedAt(): Date {
|
30
|
-
return this._CreatedAt;
|
31
|
-
}
|
32
|
-
|
33
|
-
private constructor(params?: IUserPasswordHistoryAttr) {
|
34
|
-
super();
|
35
|
-
if (params) {
|
36
|
-
this.ObjectId = params.HistoryId;
|
37
|
-
this.UserId = params.UserId;
|
38
|
-
this.PasswordHash = params.PasswordHash;
|
39
|
-
this._CreatedAt = params.CreatedAt;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
public static async init(
|
44
|
-
historyId?: number,
|
45
|
-
dbTransaction?: any,
|
46
|
-
): Promise<UserPasswordHistory> {
|
47
|
-
try {
|
48
|
-
if (historyId) {
|
49
|
-
const data = await UserPasswordHistory._Repo.findByPk(
|
50
|
-
historyId.toString(),
|
51
|
-
dbTransaction,
|
52
|
-
);
|
53
|
-
if (!data) {
|
54
|
-
throw new ClassError(
|
55
|
-
'UserPasswordHistory',
|
56
|
-
'UserPasswordHistoryErrMsg01',
|
57
|
-
'UserPasswordHistory not found',
|
58
|
-
'init',
|
59
|
-
400,
|
60
|
-
);
|
61
|
-
}
|
62
|
-
|
63
|
-
return new UserPasswordHistory(data.get({ plain: true }));
|
64
|
-
}
|
65
|
-
return new UserPasswordHistory();
|
66
|
-
} catch (error) {
|
67
|
-
throw error;
|
68
|
-
}
|
69
|
-
}
|
70
|
-
|
71
|
-
public static async validate(
|
72
|
-
dbTransaction: any,
|
73
|
-
UserId: number,
|
74
|
-
Password: string,
|
75
|
-
passwordHashService: PasswordHashService,
|
76
|
-
): Promise<void> {
|
77
|
-
// This method used to check if password entered is valid by checking previous password history
|
78
|
-
try {
|
79
|
-
// Part 1-2: Retrieve password history policy by using component config, call ComponentConfig. by passing:
|
80
|
-
// - ComponentName: "@tomei/sso"
|
81
|
-
// - ConfigKey: "passwordHistory"
|
82
|
-
// If no password history set, use default value 3
|
83
|
-
|
84
|
-
const passwordHistoryPolicy =
|
85
|
-
ComponentConfig.getComponentConfigValue(
|
86
|
-
'@tomei/sso',
|
87
|
-
'passwordHistory',
|
88
|
-
) || 3;
|
89
|
-
|
90
|
-
// Part 3-4: Retrieve records from the table by using class._repo findAll() by passing:
|
91
|
-
// where: { UserId: params.UserId }
|
92
|
-
// order: [['CreatedAt', 'DESC']]
|
93
|
-
// limit: passwordHistory count above.
|
94
|
-
// If no record found, return null.
|
95
|
-
|
96
|
-
let passwordHistory = await UserPasswordHistory._Repo.findAll({
|
97
|
-
where: { UserId: UserId },
|
98
|
-
order: [['CreatedAt', 'DESC']],
|
99
|
-
limit: passwordHistoryPolicy,
|
100
|
-
transaction: dbTransaction,
|
101
|
-
});
|
102
|
-
|
103
|
-
if (passwordHistory?.length < 1) {
|
104
|
-
return null;
|
105
|
-
} else {
|
106
|
-
// Part 5: If record found, map each record to compare params.Password and record.PasswordHash using the params.passwordHashService. If match, stop the mapping, and return ClassError:
|
107
|
-
// ClassName: "UserPasswordHistory"
|
108
|
-
// MethodName: "validate"
|
109
|
-
// MessageCode: "UserPasswordHistory01"
|
110
|
-
// Message: You cannot reuse your last ${passwordHistory} passwords. Please choose a new and unique password.
|
111
|
-
for (let index = 0; index < passwordHistory.length; index++) {
|
112
|
-
const isPasswordSame = await passwordHashService.verify(
|
113
|
-
Password,
|
114
|
-
passwordHistory[index].PasswordHash,
|
115
|
-
);
|
116
|
-
|
117
|
-
if (isPasswordSame) {
|
118
|
-
throw new ClassError(
|
119
|
-
'UserPasswordHistory',
|
120
|
-
'UserPasswordHistory01',
|
121
|
-
`You cannot reuse your last ${passwordHistoryPolicy} passwords. Please choose a new and unique password.`,
|
122
|
-
'validate',
|
123
|
-
403,
|
124
|
-
);
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
} catch (error) {
|
129
|
-
throw error;
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
public static async create(
|
134
|
-
dbTransaction: any,
|
135
|
-
UserId: number,
|
136
|
-
PasswordHash: string,
|
137
|
-
): Promise<void> {
|
138
|
-
// This method used to check if password entered is valid by checking previous password history
|
139
|
-
try {
|
140
|
-
// Part 1-2: Retrieve password history policy by using component config, call ComponentConfig. by passing:
|
141
|
-
// - ComponentName: "@tomei/sso"
|
142
|
-
// - ConfigKey: "passwordHistory"
|
143
|
-
// If no password history set, use default value 3
|
144
|
-
|
145
|
-
const passwordHistoryPolicy =
|
146
|
-
ComponentConfig.getComponentConfigValue(
|
147
|
-
'@tomei/sso',
|
148
|
-
'passwordHistory',
|
149
|
-
) || 3;
|
150
|
-
|
151
|
-
// Part 3: Insert new password history by calling class _repo create() method.
|
152
|
-
const userPasswordHistory = new UserPasswordHistory();
|
153
|
-
let passwordHistory = await UserPasswordHistory._Repo.create(
|
154
|
-
{
|
155
|
-
HistoryId: userPasswordHistory.createId(),
|
156
|
-
UserId: UserId,
|
157
|
-
PasswordHash: PasswordHash,
|
158
|
-
},
|
159
|
-
{
|
160
|
-
transaction: dbTransaction,
|
161
|
-
},
|
162
|
-
);
|
163
|
-
|
164
|
-
// Part 3: When inserted successfully, retrieve all the password history for the user to check
|
165
|
-
// how many previous password records. If records more than the passwordHistory count from
|
166
|
-
// config. Remove the oldest record.
|
167
|
-
if (passwordHistory) {
|
168
|
-
let passwordHistoryList = await UserPasswordHistory._Repo.findAll({
|
169
|
-
where: { UserId: UserId },
|
170
|
-
order: [['CreatedAt', 'DESC']],
|
171
|
-
transaction: dbTransaction,
|
172
|
-
});
|
173
|
-
|
174
|
-
if (passwordHistoryList.length > passwordHistoryPolicy) {
|
175
|
-
let deleteList = passwordHistoryList.slice(passwordHistoryPolicy);
|
176
|
-
let historyIdList = deleteList.map((record) => record.HistoryId);
|
177
|
-
await UserPasswordHistory._Repo.destroyMultiple(
|
178
|
-
historyIdList,
|
179
|
-
dbTransaction,
|
180
|
-
);
|
181
|
-
}
|
182
|
-
}
|
183
|
-
} catch (error) {
|
184
|
-
throw error;
|
185
|
-
}
|
186
|
-
}
|
187
|
-
}
|
1
|
+
import { ClassError, ObjectBase } from '@tomei/general';
|
2
|
+
import { ComponentConfig } from '@tomei/config';
|
3
|
+
import { IUserPasswordHistoryAttr } from '../../interfaces/user-password-history.interface';
|
4
|
+
import { UserPasswordHistoryRepository } from './user-password-history.repository';
|
5
|
+
import { PasswordHashService } from '../../components/password-hash';
|
6
|
+
|
7
|
+
export class UserPasswordHistory
|
8
|
+
extends ObjectBase
|
9
|
+
implements IUserPasswordHistoryAttr
|
10
|
+
{
|
11
|
+
ObjectId: string;
|
12
|
+
ObjectName: string;
|
13
|
+
ObjectType = 'UserPasswordHistory';
|
14
|
+
TableName = 'sso_UserPasswordHistory';
|
15
|
+
UserId: number;
|
16
|
+
PasswordHash: string;
|
17
|
+
private _CreatedAt: Date;
|
18
|
+
|
19
|
+
private static _Repo = new UserPasswordHistoryRepository();
|
20
|
+
|
21
|
+
get HistoryId(): string {
|
22
|
+
return this.ObjectId;
|
23
|
+
}
|
24
|
+
|
25
|
+
set HistoryId(value: string) {
|
26
|
+
this.ObjectId = value;
|
27
|
+
}
|
28
|
+
|
29
|
+
get CreatedAt(): Date {
|
30
|
+
return this._CreatedAt;
|
31
|
+
}
|
32
|
+
|
33
|
+
private constructor(params?: IUserPasswordHistoryAttr) {
|
34
|
+
super();
|
35
|
+
if (params) {
|
36
|
+
this.ObjectId = params.HistoryId;
|
37
|
+
this.UserId = params.UserId;
|
38
|
+
this.PasswordHash = params.PasswordHash;
|
39
|
+
this._CreatedAt = params.CreatedAt;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
public static async init(
|
44
|
+
historyId?: number,
|
45
|
+
dbTransaction?: any,
|
46
|
+
): Promise<UserPasswordHistory> {
|
47
|
+
try {
|
48
|
+
if (historyId) {
|
49
|
+
const data = await UserPasswordHistory._Repo.findByPk(
|
50
|
+
historyId.toString(),
|
51
|
+
dbTransaction,
|
52
|
+
);
|
53
|
+
if (!data) {
|
54
|
+
throw new ClassError(
|
55
|
+
'UserPasswordHistory',
|
56
|
+
'UserPasswordHistoryErrMsg01',
|
57
|
+
'UserPasswordHistory not found',
|
58
|
+
'init',
|
59
|
+
400,
|
60
|
+
);
|
61
|
+
}
|
62
|
+
|
63
|
+
return new UserPasswordHistory(data.get({ plain: true }));
|
64
|
+
}
|
65
|
+
return new UserPasswordHistory();
|
66
|
+
} catch (error) {
|
67
|
+
throw error;
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
public static async validate(
|
72
|
+
dbTransaction: any,
|
73
|
+
UserId: number,
|
74
|
+
Password: string,
|
75
|
+
passwordHashService: PasswordHashService,
|
76
|
+
): Promise<void> {
|
77
|
+
// This method used to check if password entered is valid by checking previous password history
|
78
|
+
try {
|
79
|
+
// Part 1-2: Retrieve password history policy by using component config, call ComponentConfig. by passing:
|
80
|
+
// - ComponentName: "@tomei/sso"
|
81
|
+
// - ConfigKey: "passwordHistory"
|
82
|
+
// If no password history set, use default value 3
|
83
|
+
|
84
|
+
const passwordHistoryPolicy =
|
85
|
+
ComponentConfig.getComponentConfigValue(
|
86
|
+
'@tomei/sso',
|
87
|
+
'passwordHistory',
|
88
|
+
) || 3;
|
89
|
+
|
90
|
+
// Part 3-4: Retrieve records from the table by using class._repo findAll() by passing:
|
91
|
+
// where: { UserId: params.UserId }
|
92
|
+
// order: [['CreatedAt', 'DESC']]
|
93
|
+
// limit: passwordHistory count above.
|
94
|
+
// If no record found, return null.
|
95
|
+
|
96
|
+
let passwordHistory = await UserPasswordHistory._Repo.findAll({
|
97
|
+
where: { UserId: UserId },
|
98
|
+
order: [['CreatedAt', 'DESC']],
|
99
|
+
limit: passwordHistoryPolicy,
|
100
|
+
transaction: dbTransaction,
|
101
|
+
});
|
102
|
+
|
103
|
+
if (passwordHistory?.length < 1) {
|
104
|
+
return null;
|
105
|
+
} else {
|
106
|
+
// Part 5: If record found, map each record to compare params.Password and record.PasswordHash using the params.passwordHashService. If match, stop the mapping, and return ClassError:
|
107
|
+
// ClassName: "UserPasswordHistory"
|
108
|
+
// MethodName: "validate"
|
109
|
+
// MessageCode: "UserPasswordHistory01"
|
110
|
+
// Message: You cannot reuse your last ${passwordHistory} passwords. Please choose a new and unique password.
|
111
|
+
for (let index = 0; index < passwordHistory.length; index++) {
|
112
|
+
const isPasswordSame = await passwordHashService.verify(
|
113
|
+
Password,
|
114
|
+
passwordHistory[index].PasswordHash,
|
115
|
+
);
|
116
|
+
|
117
|
+
if (isPasswordSame) {
|
118
|
+
throw new ClassError(
|
119
|
+
'UserPasswordHistory',
|
120
|
+
'UserPasswordHistory01',
|
121
|
+
`You cannot reuse your last ${passwordHistoryPolicy} passwords. Please choose a new and unique password.`,
|
122
|
+
'validate',
|
123
|
+
403,
|
124
|
+
);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
} catch (error) {
|
129
|
+
throw error;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
public static async create(
|
134
|
+
dbTransaction: any,
|
135
|
+
UserId: number,
|
136
|
+
PasswordHash: string,
|
137
|
+
): Promise<void> {
|
138
|
+
// This method used to check if password entered is valid by checking previous password history
|
139
|
+
try {
|
140
|
+
// Part 1-2: Retrieve password history policy by using component config, call ComponentConfig. by passing:
|
141
|
+
// - ComponentName: "@tomei/sso"
|
142
|
+
// - ConfigKey: "passwordHistory"
|
143
|
+
// If no password history set, use default value 3
|
144
|
+
|
145
|
+
const passwordHistoryPolicy =
|
146
|
+
ComponentConfig.getComponentConfigValue(
|
147
|
+
'@tomei/sso',
|
148
|
+
'passwordHistory',
|
149
|
+
) || 3;
|
150
|
+
|
151
|
+
// Part 3: Insert new password history by calling class _repo create() method.
|
152
|
+
const userPasswordHistory = new UserPasswordHistory();
|
153
|
+
let passwordHistory = await UserPasswordHistory._Repo.create(
|
154
|
+
{
|
155
|
+
HistoryId: userPasswordHistory.createId(),
|
156
|
+
UserId: UserId,
|
157
|
+
PasswordHash: PasswordHash,
|
158
|
+
},
|
159
|
+
{
|
160
|
+
transaction: dbTransaction,
|
161
|
+
},
|
162
|
+
);
|
163
|
+
|
164
|
+
// Part 3: When inserted successfully, retrieve all the password history for the user to check
|
165
|
+
// how many previous password records. If records more than the passwordHistory count from
|
166
|
+
// config. Remove the oldest record.
|
167
|
+
if (passwordHistory) {
|
168
|
+
let passwordHistoryList = await UserPasswordHistory._Repo.findAll({
|
169
|
+
where: { UserId: UserId },
|
170
|
+
order: [['CreatedAt', 'DESC']],
|
171
|
+
transaction: dbTransaction,
|
172
|
+
});
|
173
|
+
|
174
|
+
if (passwordHistoryList.length > passwordHistoryPolicy) {
|
175
|
+
let deleteList = passwordHistoryList.slice(passwordHistoryPolicy);
|
176
|
+
let historyIdList = deleteList.map((record) => record.HistoryId);
|
177
|
+
await UserPasswordHistory._Repo.destroyMultiple(
|
178
|
+
historyIdList,
|
179
|
+
dbTransaction,
|
180
|
+
);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
} catch (error) {
|
184
|
+
throw error;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from './user-privilege.repository';
|
2
|
-
export * from './user-privilege';
|
1
|
+
export * from './user-privilege.repository';
|
2
|
+
export * from './user-privilege';
|