@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.
- package/README.md +60 -0
- package/dist/auth/auth.controller.d.ts +8 -1
- package/dist/auth/auth.controller.d.ts.map +1 -1
- package/dist/auth/auth.controller.js +7 -7
- package/dist/auth/auth.controller.js.map +1 -1
- package/dist/auth/auth.service.d.ts +10 -1
- package/dist/auth/auth.service.d.ts.map +1 -1
- package/dist/auth/auth.service.js +34 -8
- package/dist/auth/auth.service.js.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts +12 -0
- package/dist/dashboard/dashboard-core/dashboard-core.controller.d.ts.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.controller.js +9 -0
- package/dist/dashboard/dashboard-core/dashboard-core.controller.js.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts +12 -0
- package/dist/dashboard/dashboard-core/dashboard-core.service.d.ts.map +1 -1
- package/dist/dashboard/dashboard-core/dashboard-core.service.js +25 -0
- package/dist/dashboard/dashboard-core/dashboard-core.service.js.map +1 -1
- package/dist/profile/profile.service.js +1 -1
- package/dist/profile/profile.service.js.map +1 -1
- package/dist/role/guards/role.guard.d.ts +1 -0
- package/dist/role/guards/role.guard.d.ts.map +1 -1
- package/dist/role/guards/role.guard.js +18 -0
- package/dist/role/guards/role.guard.js.map +1 -1
- package/dist/session/session.service.js +1 -1
- package/dist/session/session.service.js.map +1 -1
- package/dist/user/dto/reset-password.dto.d.ts +4 -0
- package/dist/user/dto/reset-password.dto.d.ts.map +1 -0
- package/dist/user/dto/reset-password.dto.js +26 -0
- package/dist/user/dto/reset-password.dto.js.map +1 -0
- package/dist/user/user.controller.d.ts +5 -0
- package/dist/user/user.controller.d.ts.map +1 -1
- package/dist/user/user.controller.js +13 -0
- package/dist/user/user.controller.js.map +1 -1
- package/dist/user/user.service.d.ts +6 -0
- package/dist/user/user.service.d.ts.map +1 -1
- package/dist/user/user.service.js +65 -0
- package/dist/user/user.service.js.map +1 -1
- package/hedhog/data/dashboard_component.yaml +74 -12
- package/hedhog/data/dashboard_component_role.yaml +223 -145
- package/hedhog/data/dashboard_item.yaml +42 -22
- package/hedhog/data/dashboard_role.yaml +18 -12
- package/hedhog/data/menu.yaml +6 -0
- package/hedhog/data/route.yaml +65 -1
- package/hedhog/frontend/app/account/components/change-password-form.tsx.ejs +2 -1
- package/hedhog/frontend/app/ai_agent/page.tsx.ejs +17 -17
- package/hedhog/frontend/app/dashboard/[slug]/dashboard-content.tsx.ejs +23 -12
- package/hedhog/frontend/app/dashboard/components/draggable-grid.tsx.ejs +80 -5
- package/hedhog/frontend/app/dashboard/components/widgets/account-security.tsx.ejs +17 -13
- package/hedhog/frontend/app/dashboard/components/widgets/activity-timeline.tsx.ejs +16 -12
- package/hedhog/frontend/app/dashboard/components/widgets/email-notifications.tsx.ejs +27 -16
- package/hedhog/frontend/app/dashboard/components/widgets/login-history-chart.tsx.ejs +13 -9
- package/hedhog/frontend/app/dashboard/components/widgets/menus-card.tsx.ejs +58 -0
- package/hedhog/frontend/app/dashboard/components/widgets/permissions-chart.tsx.ejs +62 -58
- package/hedhog/frontend/app/dashboard/components/widgets/routes-card.tsx.ejs +58 -0
- package/hedhog/frontend/app/dashboard/components/widgets/stat-access-level.tsx.ejs +6 -6
- package/hedhog/frontend/app/dashboard/components/widgets/stat-actions-today.tsx.ejs +6 -6
- package/hedhog/frontend/app/dashboard/components/widgets/stat-consecutive-days.tsx.ejs +6 -6
- package/hedhog/frontend/app/dashboard/components/widgets/stat-online-time.tsx.ejs +6 -6
- package/hedhog/frontend/app/dashboard/components/widgets/user-roles.tsx.ejs +15 -11
- package/hedhog/frontend/app/dashboard/components/widgets/user-sessions.tsx.ejs +18 -15
- package/hedhog/frontend/app/dashboard/dashboard.css.ejs +20 -4
- package/hedhog/frontend/app/dashboard/page.tsx.ejs +29 -14
- package/hedhog/frontend/app/mail/log/page.tsx.ejs +5 -11
- package/hedhog/frontend/app/users/page.tsx.ejs +331 -10
- package/hedhog/frontend/messages/en.json +29 -3
- package/hedhog/frontend/messages/pt.json +29 -3
- package/package.json +4 -4
- package/src/auth/auth.controller.ts +21 -20
- package/src/auth/auth.service.ts +63 -15
- package/src/dashboard/dashboard-core/dashboard-core.controller.ts +5 -0
- package/src/dashboard/dashboard-core/dashboard-core.service.ts +34 -0
- package/src/profile/profile.service.ts +1 -1
- package/src/role/guards/role.guard.ts +36 -7
- package/src/session/session.service.ts +2 -2
- package/src/user/dto/reset-password.dto.ts +11 -0
- package/src/user/user.controller.ts +24 -14
- package/src/user/user.service.ts +84 -0
package/src/user/user.service.ts
CHANGED
|
@@ -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,
|