@tomei/sso 0.60.4-staging.1 → 0.61.0

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.
Files changed (248) hide show
  1. package/.commitlintrc.json +22 -22
  2. package/.gitlab-ci.yml +16 -16
  3. package/.husky/commit-msg +15 -9
  4. package/.husky/pre-commit +7 -7
  5. package/.prettierrc +4 -4
  6. package/Jenkinsfile +57 -57
  7. package/README.md +23 -23
  8. package/__tests__/unit/components/group/group.spec.ts +79 -79
  9. package/__tests__/unit/components/group-object-privilege/group-object-privilege.spec.ts +88 -88
  10. package/__tests__/unit/components/group-privilege/group-privilege.spec.ts +68 -68
  11. package/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts +66 -66
  12. package/__tests__/unit/components/group-system-access/group-system-access.spec.ts +83 -83
  13. package/__tests__/unit/components/login-user/l.spec.ts +746 -746
  14. package/__tests__/unit/components/login-user/login.spec.ts +1164 -1164
  15. package/__tests__/unit/components/password-hash/password-hash.service.spec.ts +31 -31
  16. package/__tests__/unit/components/system/system.spec.ts +254 -254
  17. package/__tests__/unit/components/system-privilege/system-privilege.spec.ts +83 -83
  18. package/__tests__/unit/components/user-group/user-group.spec.ts +86 -86
  19. package/__tests__/unit/components/user-object-privilege/user-object-privilege.spec.ts +78 -78
  20. package/__tests__/unit/components/user-privilege/user-privilege.spec.ts +72 -72
  21. package/__tests__/unit/components/user-system-access/user-system-access.spec.ts +89 -89
  22. package/__tests__/unit/redis-client/redis.service.spec.ts +23 -23
  23. package/__tests__/unit/session/session.service.spec.ts +47 -47
  24. package/__tests__/unit/system-privilege/system-privilage.spec.ts +91 -91
  25. package/coverage/clover.xml +1452 -1452
  26. package/coverage/coverage-final.json +47 -47
  27. package/coverage/lcov-report/base.css +224 -224
  28. package/coverage/lcov-report/block-navigation.js +87 -87
  29. package/coverage/lcov-report/components/group/group.repository.ts.html +117 -117
  30. package/coverage/lcov-report/components/group/group.ts.html +327 -327
  31. package/coverage/lcov-report/components/group/index.html +130 -130
  32. package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.repository.ts.html +117 -117
  33. package/coverage/lcov-report/components/group-object-privilege/group-object-privilege.ts.html +321 -321
  34. package/coverage/lcov-report/components/group-object-privilege/index.html +130 -130
  35. package/coverage/lcov-report/components/group-privilege/group-privilege.repository.ts.html +117 -117
  36. package/coverage/lcov-report/components/group-privilege/group-privilege.ts.html +303 -303
  37. package/coverage/lcov-report/components/group-privilege/index.html +130 -130
  38. package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.repository.ts.html +117 -117
  39. package/coverage/lcov-report/components/group-reporting-user/group-reporting-user.ts.html +327 -327
  40. package/coverage/lcov-report/components/group-reporting-user/index.html +130 -130
  41. package/coverage/lcov-report/components/group-system-access/group-system-access.repository.ts.html +117 -117
  42. package/coverage/lcov-report/components/group-system-access/group-system-access.ts.html +309 -309
  43. package/coverage/lcov-report/components/group-system-access/index.html +130 -130
  44. package/coverage/lcov-report/components/login-history/index.html +115 -115
  45. package/coverage/lcov-report/components/login-history/login-history.repository.ts.html +117 -117
  46. package/coverage/lcov-report/components/login-user/index.html +130 -130
  47. package/coverage/lcov-report/components/login-user/login-user.ts.html +5007 -5007
  48. package/coverage/lcov-report/components/login-user/user.repository.ts.html +117 -117
  49. package/coverage/lcov-report/components/password-hash/index.html +115 -115
  50. package/coverage/lcov-report/components/password-hash/password-hash.service.ts.html +126 -126
  51. package/coverage/lcov-report/components/system/index.html +130 -130
  52. package/coverage/lcov-report/components/system/system.repository.ts.html +117 -117
  53. package/coverage/lcov-report/components/system/system.ts.html +909 -909
  54. package/coverage/lcov-report/components/system-privilege/index.html +130 -130
  55. package/coverage/lcov-report/components/system-privilege/system-privilege.repository.ts.html +120 -120
  56. package/coverage/lcov-report/components/system-privilege/system-privilege.ts.html +390 -390
  57. package/coverage/lcov-report/components/user-group/index.html +130 -130
  58. package/coverage/lcov-report/components/user-group/user-group.repository.ts.html +117 -117
  59. package/coverage/lcov-report/components/user-group/user-group.ts.html +354 -354
  60. package/coverage/lcov-report/components/user-object-privilege/index.html +130 -130
  61. package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.repository.ts.html +117 -117
  62. package/coverage/lcov-report/components/user-object-privilege/user-object-privilege.ts.html +312 -312
  63. package/coverage/lcov-report/components/user-privilege/index.html +130 -130
  64. package/coverage/lcov-report/components/user-privilege/user-privilege.repository.ts.html +117 -117
  65. package/coverage/lcov-report/components/user-privilege/user-privilege.ts.html +306 -306
  66. package/coverage/lcov-report/components/user-system-access/index.html +130 -130
  67. package/coverage/lcov-report/components/user-system-access/user-system-access.repository.ts.html +117 -117
  68. package/coverage/lcov-report/components/user-system-access/user-system-access.ts.html +312 -312
  69. package/coverage/lcov-report/enum/group-type.enum.ts.html +108 -108
  70. package/coverage/lcov-report/enum/index.html +160 -160
  71. package/coverage/lcov-report/enum/index.ts.html +93 -93
  72. package/coverage/lcov-report/enum/user-status.enum.ts.html +105 -105
  73. package/coverage/lcov-report/enum/yn.enum.ts.html +96 -96
  74. package/coverage/lcov-report/index.html +370 -370
  75. package/coverage/lcov-report/models/group-object-privilege.entity.ts.html +333 -333
  76. package/coverage/lcov-report/models/group-privilege.entity.ts.html +315 -315
  77. package/coverage/lcov-report/models/group-reporting-user.entity.ts.html +339 -339
  78. package/coverage/lcov-report/models/group-system-access.entity.ts.html +324 -324
  79. package/coverage/lcov-report/models/group.entity.ts.html +435 -435
  80. package/coverage/lcov-report/models/index.html +310 -310
  81. package/coverage/lcov-report/models/login-history.entity.ts.html +252 -252
  82. package/coverage/lcov-report/models/staff.entity.ts.html +411 -411
  83. package/coverage/lcov-report/models/system-privilege.entity.ts.html +354 -354
  84. package/coverage/lcov-report/models/system.entity.ts.html +423 -423
  85. package/coverage/lcov-report/models/user-group.entity.ts.html +354 -354
  86. package/coverage/lcov-report/models/user-object-privilege.entity.ts.html +330 -330
  87. package/coverage/lcov-report/models/user-privilege.entity.ts.html +315 -315
  88. package/coverage/lcov-report/models/user-system-access.entity.ts.html +315 -315
  89. package/coverage/lcov-report/models/user.entity.ts.html +522 -522
  90. package/coverage/lcov-report/prettify.css +1 -1
  91. package/coverage/lcov-report/prettify.js +2 -2
  92. package/coverage/lcov-report/redis-client/index.html +115 -115
  93. package/coverage/lcov-report/redis-client/redis.service.ts.html +240 -240
  94. package/coverage/lcov-report/session/index.html +115 -115
  95. package/coverage/lcov-report/session/session.service.ts.html +246 -246
  96. package/coverage/lcov-report/sorter.js +196 -196
  97. package/coverage/lcov.info +2490 -2490
  98. package/coverage/test-report.xml +128 -128
  99. package/create-sso-user.sql +39 -39
  100. package/dist/src/components/login-user/user.js +9 -1
  101. package/dist/src/components/login-user/user.js.map +1 -1
  102. package/dist/tsconfig.tsbuildinfo +1 -1
  103. package/eslint.config.mjs +58 -58
  104. package/jest.config.js +14 -14
  105. package/migrations/20240314080602-create-user-table.js +124 -124
  106. package/migrations/20240314080603-create-user-group-table.js +85 -85
  107. package/migrations/20240314080604-create-user-user-group-table.js +55 -55
  108. package/migrations/20240314080605-create-login-history-table.js +53 -53
  109. package/migrations/20240527064925-create-system-table.js +78 -78
  110. package/migrations/20240527064926-create-system-privilege-table.js +71 -71
  111. package/migrations/20240527065342-create-group-table.js +93 -93
  112. package/migrations/20240527065633-create-group-reporting-user-table.js +76 -76
  113. package/migrations/20240528011551-create-group-system-access-table.js +72 -72
  114. package/migrations/20240528023018-user-system-access-table.js +75 -75
  115. package/migrations/20240528032229-user-privilege-table.js +76 -76
  116. package/migrations/20240528063003-create-group-privilege-table.js +76 -76
  117. package/migrations/20240528063051-create-group-object-privilege-table.js +84 -84
  118. package/migrations/20240528063107-create-user-object-privilege-table.js +84 -84
  119. package/migrations/20240528063108-create-api-key-table.js +85 -85
  120. package/migrations/20241104104802-create-building-table.js +95 -95
  121. package/migrations/20250108091132-add-area-manager-user-id-to-building-table.js +14 -14
  122. package/migrations/20250108091133-add-passcode-to-user-table.js +36 -36
  123. package/migrations/20250210115636-create-user-reporting-hierarchy.js +76 -76
  124. package/migrations/20250326043818-crate-user-password-history.js +42 -42
  125. package/package.json +90 -90
  126. package/sampledotenv +7 -7
  127. package/sonar-project.properties +22 -22
  128. package/src/components/api-key/api-key.repository.ts +15 -15
  129. package/src/components/api-key/api-key.ts +448 -448
  130. package/src/components/api-key/index.ts +4 -4
  131. package/src/components/building/building.repository.ts +27 -27
  132. package/src/components/building/index.ts +2 -2
  133. package/src/components/group/group.repository.ts +26 -26
  134. package/src/components/group/group.ts +2284 -2284
  135. package/src/components/group/index.ts +3 -3
  136. package/src/components/group-object-privilege/group-object-privilege.repository.ts +25 -25
  137. package/src/components/group-object-privilege/group-object-privilege.ts +278 -278
  138. package/src/components/group-object-privilege/index.ts +2 -2
  139. package/src/components/group-privilege/group-privilege.repository.ts +29 -29
  140. package/src/components/group-privilege/group-privilege.ts +84 -84
  141. package/src/components/group-privilege/index.ts +2 -2
  142. package/src/components/group-reporting-user/group-reporting-user.repository.ts +23 -23
  143. package/src/components/group-reporting-user/group-reporting-user.ts +506 -506
  144. package/src/components/group-reporting-user/index.ts +3 -3
  145. package/src/components/group-system-access/group-system-access.repository.ts +43 -43
  146. package/src/components/group-system-access/group-system-access.ts +90 -90
  147. package/src/components/group-system-access/index.ts +2 -2
  148. package/src/components/index.ts +20 -20
  149. package/src/components/login-history/index.ts +1 -1
  150. package/src/components/login-history/login-history.repository.ts +11 -11
  151. package/src/components/login-user/index.ts +5 -5
  152. package/src/components/login-user/interfaces/check-user-info-duplicated.interface.ts +7 -7
  153. package/src/components/login-user/interfaces/index.ts +1 -1
  154. package/src/components/login-user/interfaces/system-access.interface.ts +13 -13
  155. package/src/components/login-user/interfaces/user-info.interface.ts +34 -34
  156. package/src/components/login-user/login-user.ts +362 -362
  157. package/src/components/login-user/user.repository.ts +11 -11
  158. package/src/components/login-user/user.ts +3142 -3134
  159. package/src/components/password-hash/index.ts +2 -2
  160. package/src/components/password-hash/interfaces/index.ts +1 -1
  161. package/src/components/password-hash/interfaces/password-hash-service.interface.ts +4 -4
  162. package/src/components/password-hash/password-hash.service.ts +14 -14
  163. package/src/components/staff/index.ts +2 -2
  164. package/src/components/staff/staff.repository.ts +27 -27
  165. package/src/components/system/index.ts +3 -3
  166. package/src/components/system/system.repository.ts +11 -11
  167. package/src/components/system/system.ts +456 -456
  168. package/src/components/system-privilege/index.ts +4 -4
  169. package/src/components/system-privilege/system-privilege.repository.ts +18 -18
  170. package/src/components/system-privilege/system-privilege.ts +541 -541
  171. package/src/components/user-group/index.ts +2 -2
  172. package/src/components/user-group/user-group.repository.ts +19 -19
  173. package/src/components/user-group/user-group.ts +764 -764
  174. package/src/components/user-object-privilege/index.ts +2 -2
  175. package/src/components/user-object-privilege/user-object-privilege.repository.ts +11 -11
  176. package/src/components/user-object-privilege/user-object-privilege.ts +79 -79
  177. package/src/components/user-password-history/index.ts +2 -2
  178. package/src/components/user-password-history/user-password-history.repository.ts +39 -39
  179. package/src/components/user-password-history/user-password-history.ts +187 -187
  180. package/src/components/user-privilege/index.ts +2 -2
  181. package/src/components/user-privilege/user-privilege.repository.ts +25 -25
  182. package/src/components/user-privilege/user-privilege.ts +662 -662
  183. package/src/components/user-reporting-hierarchy/index.ts +2 -2
  184. package/src/components/user-reporting-hierarchy/user-reporting-hierarchy.repository.ts +30 -30
  185. package/src/components/user-reporting-hierarchy/user-reporting-hierarchy.ts +505 -505
  186. package/src/components/user-system-access/index.ts +2 -2
  187. package/src/components/user-system-access/user-system-access.repository.ts +41 -41
  188. package/src/components/user-system-access/user-system-access.ts +717 -717
  189. package/src/database.ts +15 -15
  190. package/src/enum/api-key.enum.ts +5 -5
  191. package/src/enum/building-type.enum.ts +6 -6
  192. package/src/enum/group-type.enum.ts +8 -8
  193. package/src/enum/index.ts +6 -6
  194. package/src/enum/login-status.enum.ts +4 -4
  195. package/src/enum/object-status.enum.ts +4 -4
  196. package/src/enum/user-status.enum.ts +7 -7
  197. package/src/enum/yn.enum.ts +4 -4
  198. package/src/index.ts +8 -8
  199. package/src/interfaces/api-key-attr.interface.ts +16 -16
  200. package/src/interfaces/group-object-privilege.interface.ts +14 -14
  201. package/src/interfaces/group-privilege.interface.ts +10 -10
  202. package/src/interfaces/group-reporting-user.interface.ts +11 -11
  203. package/src/interfaces/group-search-attr.interface.ts +9 -9
  204. package/src/interfaces/group-system-access.interface.ts +10 -10
  205. package/src/interfaces/group.interface.ts +17 -17
  206. package/src/interfaces/index.ts +13 -13
  207. package/src/interfaces/system-login.interface.ts +6 -6
  208. package/src/interfaces/system-privilege-search.interface.ts +5 -5
  209. package/src/interfaces/system-privilege.interface.ts +11 -11
  210. package/src/interfaces/system-search-attr.interface.ts +5 -5
  211. package/src/interfaces/system.interface.ts +15 -15
  212. package/src/interfaces/user-group.interface.ts +12 -12
  213. package/src/interfaces/user-object-privilege.interface.ts +14 -14
  214. package/src/interfaces/user-password-history.interface.ts +6 -6
  215. package/src/interfaces/user-privilege.interface.ts +10 -10
  216. package/src/interfaces/user-reporting-hierarchy.interface.ts +11 -11
  217. package/src/interfaces/user-session.interface.ts +5 -5
  218. package/src/interfaces/user-system-access.interface.ts +10 -10
  219. package/src/models/api-key-entity.ts +101 -101
  220. package/src/models/building.entity.ts +103 -103
  221. package/src/models/group-object-privilege.entity.ts +91 -91
  222. package/src/models/group-privilege.entity.ts +78 -78
  223. package/src/models/group-reporting-user.entity.ts +95 -95
  224. package/src/models/group-system-access.entity.ts +81 -81
  225. package/src/models/group.entity.ts +127 -127
  226. package/src/models/login-history.entity.ts +63 -63
  227. package/src/models/staff.entity.ts +91 -91
  228. package/src/models/system-privilege.entity.ts +90 -90
  229. package/src/models/system.entity.ts +113 -113
  230. package/src/models/user-group.entity.ts +91 -91
  231. package/src/models/user-object-privilege.entity.ts +90 -90
  232. package/src/models/user-password-history.ts +51 -51
  233. package/src/models/user-privilege.entity.ts +78 -78
  234. package/src/models/user-reporting-hierarchy.entity.ts +102 -102
  235. package/src/models/user-system-access.entity.ts +87 -87
  236. package/src/models/user.entity.ts +193 -193
  237. package/src/redis-client/__mocks__/jest-initial-setup.ts +2 -2
  238. package/src/redis-client/__mocks__/redis-mock.ts +28 -28
  239. package/src/redis-client/index.ts +1 -1
  240. package/src/redis-client/redis.service.ts +75 -75
  241. package/src/session/index.ts +2 -2
  242. package/src/session/interfaces/index.ts +1 -1
  243. package/src/session/interfaces/session-service.interface.ts +26 -26
  244. package/src/session/session.service.ts +96 -96
  245. package/src/types/auth-context.ts +10 -10
  246. package/src/types/index.ts +1 -1
  247. package/tsconfig.build.json +5 -5
  248. package/tsconfig.json +23 -23
@@ -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';