@hed-hog/core 0.0.276 → 0.0.279

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 (77) hide show
  1. package/README.md +60 -0
  2. package/dist/auth/auth.controller.d.ts +8 -1
  3. package/dist/auth/auth.controller.d.ts.map +1 -1
  4. package/dist/auth/auth.controller.js +7 -7
  5. package/dist/auth/auth.controller.js.map +1 -1
  6. package/dist/auth/auth.service.d.ts +10 -1
  7. package/dist/auth/auth.service.d.ts.map +1 -1
  8. package/dist/auth/auth.service.js +34 -8
  9. package/dist/auth/auth.service.js.map +1 -1
  10. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +12 -0
  11. package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
  12. package/dist/dashboard/dashboard-core/dashboard-core.controller.js +9 -0
  13. package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
  14. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +12 -0
  15. package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
  16. package/dist/dashboard/dashboard-core/dashboard-core.service.js +25 -0
  17. package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
  18. package/dist/profile/profile.service.js +1 -1
  19. package/dist/profile/profile.service.js.map +1 -1
  20. package/dist/role/guards/role.guard.d.ts +1 -0
  21. package/dist/role/guards/role.guard.d.ts.map +1 -1
  22. package/dist/role/guards/role.guard.js +18 -0
  23. package/dist/role/guards/role.guard.js.map +1 -1
  24. package/dist/session/session.service.js +1 -1
  25. package/dist/session/session.service.js.map +1 -1
  26. package/dist/user/dto/reset-password.dto.d.ts +4 -0
  27. package/dist/user/dto/reset-password.dto.d.ts.map +1 -0
  28. package/dist/user/dto/reset-password.dto.js +26 -0
  29. package/dist/user/dto/reset-password.dto.js.map +1 -0
  30. package/dist/user/user.controller.d.ts +5 -0
  31. package/dist/user/user.controller.d.ts.map +1 -1
  32. package/dist/user/user.controller.js +13 -0
  33. package/dist/user/user.controller.js.map +1 -1
  34. package/dist/user/user.service.d.ts +6 -0
  35. package/dist/user/user.service.d.ts.map +1 -1
  36. package/dist/user/user.service.js +65 -0
  37. package/dist/user/user.service.js.map +1 -1
  38. package/hedhog/data/dashboard_component.yaml +74 -12
  39. package/hedhog/data/dashboard_component_role.yaml +223 -145
  40. package/hedhog/data/dashboard_item.yaml +42 -22
  41. package/hedhog/data/dashboard_role.yaml +18 -12
  42. package/hedhog/data/menu.yaml +6 -0
  43. package/hedhog/data/route.yaml +65 -1
  44. package/hedhog/frontend/app/account/components/change-password-form.tsx.ejs +2 -1
  45. package/hedhog/frontend/app/ai_agent/page.tsx.ejs +17 -17
  46. package/hedhog/frontend/app/dashboard/[slug]/dashboard-content.tsx.ejs +23 -12
  47. package/hedhog/frontend/app/dashboard/components/draggable-grid.tsx.ejs +80 -5
  48. package/hedhog/frontend/app/dashboard/components/widgets/account-security.tsx.ejs +17 -13
  49. package/hedhog/frontend/app/dashboard/components/widgets/activity-timeline.tsx.ejs +16 -12
  50. package/hedhog/frontend/app/dashboard/components/widgets/email-notifications.tsx.ejs +27 -16
  51. package/hedhog/frontend/app/dashboard/components/widgets/login-history-chart.tsx.ejs +13 -9
  52. package/hedhog/frontend/app/dashboard/components/widgets/menus-card.tsx.ejs +58 -0
  53. package/hedhog/frontend/app/dashboard/components/widgets/permissions-chart.tsx.ejs +62 -58
  54. package/hedhog/frontend/app/dashboard/components/widgets/routes-card.tsx.ejs +58 -0
  55. package/hedhog/frontend/app/dashboard/components/widgets/stat-access-level.tsx.ejs +6 -6
  56. package/hedhog/frontend/app/dashboard/components/widgets/stat-actions-today.tsx.ejs +6 -6
  57. package/hedhog/frontend/app/dashboard/components/widgets/stat-consecutive-days.tsx.ejs +6 -6
  58. package/hedhog/frontend/app/dashboard/components/widgets/stat-online-time.tsx.ejs +6 -6
  59. package/hedhog/frontend/app/dashboard/components/widgets/user-roles.tsx.ejs +15 -11
  60. package/hedhog/frontend/app/dashboard/components/widgets/user-sessions.tsx.ejs +18 -15
  61. package/hedhog/frontend/app/dashboard/dashboard.css.ejs +20 -4
  62. package/hedhog/frontend/app/dashboard/page.tsx.ejs +29 -14
  63. package/hedhog/frontend/app/mail/log/page.tsx.ejs +5 -11
  64. package/hedhog/frontend/app/users/page.tsx.ejs +331 -10
  65. package/hedhog/frontend/messages/en.json +29 -3
  66. package/hedhog/frontend/messages/pt.json +29 -3
  67. package/package.json +4 -4
  68. package/src/auth/auth.controller.ts +21 -20
  69. package/src/auth/auth.service.ts +63 -15
  70. package/src/dashboard/dashboard-core/dashboard-core.controller.ts +5 -0
  71. package/src/dashboard/dashboard-core/dashboard-core.service.ts +34 -0
  72. package/src/profile/profile.service.ts +1 -1
  73. package/src/role/guards/role.guard.ts +36 -7
  74. package/src/session/session.service.ts +2 -2
  75. package/src/user/dto/reset-password.dto.ts +11 -0
  76. package/src/user/user.controller.ts +24 -14
  77. package/src/user/user.service.ts +84 -0
@@ -13,6 +13,7 @@ import { DeleteDTO } from '../dto/delete.dto';
13
13
  import { FileService } from '../file/file.service';
14
14
  import { SecurityService } from '../security/security.service';
15
15
  import { CreateWithEmailAndPasswordDTO } from './dto/create-with-email-and-password.dto';
16
+ import { ResetPasswordDTO } from './dto/reset-password.dto';
16
17
  import { UpdateDTO } from './dto/update.dto';
17
18
 
18
19
  // Constants
@@ -28,6 +29,14 @@ const DEFAULT_ROLE_SLUG = 'user';
28
29
  const DEFAULT_LOCALE = 'en';
29
30
  const DAYS_IN_MS = 24 * 60 * 60 * 1000;
30
31
  const NEW_USERS_PERIOD_DAYS = 7;
32
+ const RANDOM_PASSWORD_LENGTH = 16;
33
+
34
+ const PASSWORD_CHARSETS = {
35
+ lowercase: 'abcdefghijkmnopqrstuvwxyz',
36
+ uppercase: 'ABCDEFGHJKLMNPQRSTUVWXYZ',
37
+ numbers: '23456789',
38
+ symbols: '@#$%&*!?-_+',
39
+ } as const;
31
40
 
32
41
  const USER_SORT_FIELDS = [
33
42
  'id',
@@ -197,6 +206,46 @@ export class UserService {
197
206
  });
198
207
  }
199
208
 
209
+ async resetPassword(
210
+ locale: string,
211
+ userId: number,
212
+ { password }: ResetPasswordDTO,
213
+ ) {
214
+ await this.validateUserExists(locale, userId);
215
+
216
+ const nextPassword = password || this.generateRandomPassword();
217
+ const passwordHash = await this.security.hashArgon2(nextPassword);
218
+
219
+ const updateResult = await this.prismaService.user_credential.updateMany({
220
+ where: {
221
+ user_id: userId,
222
+ type: CREDENTIAL_TYPE.PASSWORD,
223
+ },
224
+ data: {
225
+ hash: passwordHash,
226
+ requires_reset: true,
227
+ },
228
+ });
229
+
230
+ if (updateResult.count === 0) {
231
+ await this.prismaService.user_credential.create({
232
+ data: {
233
+ user_id: userId,
234
+ type: CREDENTIAL_TYPE.PASSWORD,
235
+ hash: passwordHash,
236
+ requires_reset: true,
237
+ },
238
+ });
239
+ }
240
+
241
+ await this.registerUserActivity(userId, 'resetPassword');
242
+
243
+ return {
244
+ password: nextPassword,
245
+ requiresReset: true,
246
+ };
247
+ }
248
+
200
249
  async delete(locale: string, { ids }: DeleteDTO) {
201
250
  this.validateDeleteIds(locale, ids);
202
251
 
@@ -424,6 +473,41 @@ export class UserService {
424
473
  return role;
425
474
  }
426
475
 
476
+ private generateRandomPassword(length = RANDOM_PASSWORD_LENGTH) {
477
+ const cryptoObj = globalThis.crypto;
478
+ const groups = [
479
+ PASSWORD_CHARSETS.lowercase,
480
+ PASSWORD_CHARSETS.uppercase,
481
+ PASSWORD_CHARSETS.numbers,
482
+ PASSWORD_CHARSETS.symbols,
483
+ ];
484
+
485
+ const allChars = groups.join('');
486
+ const values = new Uint32Array(length + groups.length);
487
+ cryptoObj.getRandomValues(values);
488
+
489
+ const passwordChars: string[] = [];
490
+
491
+ groups.forEach((group, index) => {
492
+ const randomIndex = values[index] % group.length;
493
+ passwordChars.push(group[randomIndex]);
494
+ });
495
+
496
+ for (let i = groups.length; i < values.length; i++) {
497
+ const randomIndex = values[i] % allChars.length;
498
+ passwordChars.push(allChars[randomIndex]);
499
+ }
500
+
501
+ for (let i = passwordChars.length - 1; i > 0; i--) {
502
+ const randomIndex = values[i] % (i + 1);
503
+ const temp = passwordChars[i];
504
+ passwordChars[i] = passwordChars[randomIndex];
505
+ passwordChars[randomIndex] = temp;
506
+ }
507
+
508
+ return passwordChars.slice(0, length).join('');
509
+ }
510
+
427
511
  private getUserIncludeClause() {
428
512
  return {
429
513
  user_account: true,