@tomei/sso 0.60.4-dev.8 → 0.60.4-dev.9
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/package.json
CHANGED
@@ -3391,4 +3391,126 @@ export class User extends UserBase {
|
|
3391
3391
|
throw error;
|
3392
3392
|
}
|
3393
3393
|
}
|
3394
|
+
|
3395
|
+
public async reset2FA(loginUser: LoginUser, dbTransaction: any) {
|
3396
|
+
try {
|
3397
|
+
// 1. Check if MFABypassYN is already disabled
|
3398
|
+
if (this.MFAEnabled === 0) {
|
3399
|
+
throw new ClassError(
|
3400
|
+
'User',
|
3401
|
+
'UserErrMsg0X',
|
3402
|
+
'User not yet setup 2FA.',
|
3403
|
+
'reset2FA',
|
3404
|
+
);
|
3405
|
+
}
|
3406
|
+
|
3407
|
+
// 2. Check if user has MANAGE_MFA privilege
|
3408
|
+
const systemCode =
|
3409
|
+
ApplicationConfig.getComponentConfigValue('system-code');
|
3410
|
+
const isPrivileged = await loginUser.checkPrivileges(
|
3411
|
+
systemCode,
|
3412
|
+
'MANAGE_MFA',
|
3413
|
+
);
|
3414
|
+
if (!isPrivileged) {
|
3415
|
+
throw new ClassError(
|
3416
|
+
'LoginUser',
|
3417
|
+
'LoginUserErrMsg0X',
|
3418
|
+
'You do not have permission to reset 2FA.',
|
3419
|
+
);
|
3420
|
+
}
|
3421
|
+
|
3422
|
+
const entityValueBefore: IUserAttr = {
|
3423
|
+
UserId: this.UserId,
|
3424
|
+
UserName: this.UserName,
|
3425
|
+
FullName: this.FullName,
|
3426
|
+
IDNo: this.IDNo,
|
3427
|
+
IDType: this.IDType,
|
3428
|
+
ContactNo: this.ContactNo,
|
3429
|
+
Email: this.Email,
|
3430
|
+
Password: this.Password,
|
3431
|
+
Status: this.Status,
|
3432
|
+
DefaultPasswordChangedYN: this.DefaultPasswordChangedYN,
|
3433
|
+
FirstLoginAt: this.FirstLoginAt,
|
3434
|
+
LastLoginAt: this.LastLoginAt,
|
3435
|
+
MFAEnabled: this.MFAEnabled,
|
3436
|
+
MFAConfig: this.MFAConfig,
|
3437
|
+
MFABypassYN: this.MFABypassYN,
|
3438
|
+
RecoveryEmail: this.RecoveryEmail,
|
3439
|
+
FailedLoginAttemptCount: this.FailedLoginAttemptCount,
|
3440
|
+
LastFailedLoginAt: this.LastFailedLoginAt,
|
3441
|
+
LastPasswordChangedAt: this.LastPasswordChangedAt,
|
3442
|
+
NeedToChangePasswordYN: this.NeedToChangePasswordYN,
|
3443
|
+
CreatedById: this.CreatedById,
|
3444
|
+
CreatedAt: this.CreatedAt,
|
3445
|
+
UpdatedById: this.UpdatedById,
|
3446
|
+
UpdatedAt: this.UpdatedAt,
|
3447
|
+
PasscodeHash: this.PasscodeHash,
|
3448
|
+
PasscodeUpdatedAt: this.PasscodeUpdatedAt,
|
3449
|
+
};
|
3450
|
+
|
3451
|
+
// 3. Update user record
|
3452
|
+
this.MFAEnabled = 0;
|
3453
|
+
this.MFABypassYN = YN.No;
|
3454
|
+
this.UpdatedAt = new Date();
|
3455
|
+
this.UpdatedById = loginUser.UserId;
|
3456
|
+
|
3457
|
+
await User._Repository.update(
|
3458
|
+
{
|
3459
|
+
MFAEnabled: this.MFAEnabled,
|
3460
|
+
MFABypassYN: this.MFABypassYN,
|
3461
|
+
UpdatedAt: this.UpdatedAt,
|
3462
|
+
UpdatedById: this.UpdatedById,
|
3463
|
+
},
|
3464
|
+
{
|
3465
|
+
where: {
|
3466
|
+
UserId: this.UserId,
|
3467
|
+
},
|
3468
|
+
transaction: dbTransaction,
|
3469
|
+
},
|
3470
|
+
);
|
3471
|
+
|
3472
|
+
const entityValueAfter: IUserAttr = {
|
3473
|
+
UserId: this.UserId,
|
3474
|
+
UserName: this.UserName,
|
3475
|
+
FullName: this.FullName,
|
3476
|
+
IDNo: this.IDNo,
|
3477
|
+
IDType: this.IDType,
|
3478
|
+
ContactNo: this.ContactNo,
|
3479
|
+
Email: this.Email,
|
3480
|
+
Password: this.Password,
|
3481
|
+
Status: this.Status,
|
3482
|
+
DefaultPasswordChangedYN: this.DefaultPasswordChangedYN,
|
3483
|
+
FirstLoginAt: this.FirstLoginAt,
|
3484
|
+
LastLoginAt: this.LastLoginAt,
|
3485
|
+
MFAEnabled: this.MFAEnabled,
|
3486
|
+
MFAConfig: this.MFAConfig,
|
3487
|
+
MFABypassYN: this.MFABypassYN,
|
3488
|
+
RecoveryEmail: this.RecoveryEmail,
|
3489
|
+
FailedLoginAttemptCount: this.FailedLoginAttemptCount,
|
3490
|
+
LastFailedLoginAt: this.LastFailedLoginAt,
|
3491
|
+
LastPasswordChangedAt: this.LastPasswordChangedAt,
|
3492
|
+
NeedToChangePasswordYN: this.NeedToChangePasswordYN,
|
3493
|
+
CreatedById: this.CreatedById,
|
3494
|
+
CreatedAt: this.CreatedAt,
|
3495
|
+
UpdatedById: this.UpdatedById,
|
3496
|
+
UpdatedAt: this.UpdatedAt,
|
3497
|
+
PasscodeHash: this.PasscodeHash,
|
3498
|
+
PasscodeUpdatedAt: this.PasscodeUpdatedAt,
|
3499
|
+
};
|
3500
|
+
|
3501
|
+
// Record update activity using Activity class create method.
|
3502
|
+
const activity = new Activity();
|
3503
|
+
activity.ActivityId = activity.createId();
|
3504
|
+
activity.Action = ActionEnum.UPDATE;
|
3505
|
+
activity.Description = `Reset 2FA for User ${this.Email}`;
|
3506
|
+
activity.EntityType = this.ObjectType;
|
3507
|
+
activity.EntityId = this.UserId.toString();
|
3508
|
+
activity.EntityValueBefore = JSON.stringify(entityValueBefore);
|
3509
|
+
activity.EntityValueAfter = JSON.stringify(entityValueAfter);
|
3510
|
+
|
3511
|
+
await activity.create(loginUser.ObjectId, dbTransaction);
|
3512
|
+
} catch (error) {
|
3513
|
+
throw error;
|
3514
|
+
}
|
3515
|
+
}
|
3394
3516
|
}
|