@solidxai/core 0.1.4 → 0.1.5-beta.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.
- package/.claude/settings.local.json +8 -0
- package/dist/constants/error-messages.d.ts +1 -0
- package/dist/constants/error-messages.d.ts.map +1 -1
- package/dist/constants/error-messages.js +1 -0
- package/dist/constants/error-messages.js.map +1 -1
- package/dist/constants.d.ts +3 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +12 -12
- package/dist/constants.js.map +1 -1
- package/dist/controllers/otp-authentication.controller.d.ts +1 -4
- package/dist/controllers/otp-authentication.controller.d.ts.map +1 -1
- package/dist/controllers/otp-authentication.controller.js +1 -1
- package/dist/controllers/role-metadata.controller.d.ts +1 -0
- package/dist/controllers/role-metadata.controller.d.ts.map +1 -1
- package/dist/controllers/role-metadata.controller.js +15 -0
- package/dist/controllers/role-metadata.controller.js.map +1 -1
- package/dist/dtos/create-email-template.dto.d.ts.map +1 -1
- package/dist/dtos/create-email-template.dto.js.map +1 -1
- package/dist/dtos/create-list-of-values.dto.d.ts.map +1 -1
- package/dist/dtos/create-list-of-values.dto.js.map +1 -1
- package/dist/dtos/create-menu-item-metadata.dto.d.ts.map +1 -1
- package/dist/dtos/create-menu-item-metadata.dto.js.map +1 -1
- package/dist/dtos/create-role-metadata.dto.d.ts.map +1 -1
- package/dist/dtos/create-role-metadata.dto.js.map +1 -1
- package/dist/dtos/create-scheduled-job.dto.d.ts.map +1 -1
- package/dist/dtos/create-scheduled-job.dto.js.map +1 -1
- package/dist/dtos/create-security-rule.dto.d.ts.map +1 -1
- package/dist/dtos/create-security-rule.dto.js.map +1 -1
- package/dist/dtos/create-sms-template.dto.d.ts.map +1 -1
- package/dist/dtos/create-sms-template.dto.js.map +1 -1
- package/dist/dtos/create-view-metadata.dto.d.ts.map +1 -1
- package/dist/dtos/create-view-metadata.dto.js.map +1 -1
- package/dist/dtos/otp-sign-in.dto.d.ts +1 -1
- package/dist/dtos/otp-sign-in.dto.d.ts.map +1 -1
- package/dist/dtos/otp-sign-in.dto.js +2 -2
- package/dist/dtos/otp-sign-in.dto.js.map +1 -1
- package/dist/dtos/otp-sign-up.dto.d.ts +2 -2
- package/dist/dtos/otp-sign-up.dto.d.ts.map +1 -1
- package/dist/dtos/otp-sign-up.dto.js +2 -2
- package/dist/dtos/otp-sign-up.dto.js.map +1 -1
- package/dist/dtos/resolve-s3-url.dto.d.ts +2 -5
- package/dist/dtos/resolve-s3-url.dto.d.ts.map +1 -1
- package/dist/dtos/resolve-s3-url.dto.js +1 -13
- package/dist/dtos/resolve-s3-url.dto.js.map +1 -1
- package/dist/dtos/sign-up.dto.d.ts.map +1 -1
- package/dist/dtos/sign-up.dto.js.map +1 -1
- package/dist/dtos/update-email-template.dto.d.ts.map +1 -1
- package/dist/dtos/update-email-template.dto.js.map +1 -1
- package/dist/dtos/update-list-of-values.dto.d.ts.map +1 -1
- package/dist/dtos/update-list-of-values.dto.js.map +1 -1
- package/dist/dtos/update-menu-item-metadata.dto.d.ts.map +1 -1
- package/dist/dtos/update-menu-item-metadata.dto.js.map +1 -1
- package/dist/dtos/update-scheduled-job.dto.d.ts.map +1 -1
- package/dist/dtos/update-scheduled-job.dto.js.map +1 -1
- package/dist/dtos/update-security-rule.dto.d.ts.map +1 -1
- package/dist/dtos/update-security-rule.dto.js.map +1 -1
- package/dist/dtos/update-sms-template.dto.d.ts.map +1 -1
- package/dist/dtos/update-sms-template.dto.js.map +1 -1
- package/dist/dtos/update-view-metadata.dto.d.ts.map +1 -1
- package/dist/dtos/update-view-metadata.dto.js.map +1 -1
- package/dist/entities/user.entity.d.ts +1 -0
- package/dist/entities/user.entity.d.ts.map +1 -1
- package/dist/entities/user.entity.js +6 -1
- package/dist/entities/user.entity.js.map +1 -1
- package/dist/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.d.ts +2 -0
- package/dist/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.d.ts.map +1 -1
- package/dist/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.js +33 -23
- package/dist/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.js.map +1 -1
- package/dist/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.d.ts +3 -0
- package/dist/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.d.ts.map +1 -1
- package/dist/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.js +36 -23
- package/dist/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.js.map +1 -1
- package/dist/helpers/security.helper.js +1 -0
- package/dist/helpers/security.helper.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/repository/solid-base.repository.d.ts +10 -1
- package/dist/repository/solid-base.repository.d.ts.map +1 -1
- package/dist/repository/solid-base.repository.js +109 -0
- package/dist/repository/solid-base.repository.js.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.d.ts +2 -0
- package/dist/seeders/module-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/module-metadata-seeder.service.js +141 -71
- package/dist/seeders/module-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/permission-metadata-seeder.service.d.ts +1 -1
- package/dist/seeders/permission-metadata-seeder.service.d.ts.map +1 -1
- package/dist/seeders/permission-metadata-seeder.service.js +1 -1
- package/dist/seeders/permission-metadata-seeder.service.js.map +1 -1
- package/dist/seeders/seed-data/solid-core-metadata.json +12 -25
- package/dist/services/authentication.service.d.ts +22 -8
- package/dist/services/authentication.service.d.ts.map +1 -1
- package/dist/services/authentication.service.js +228 -214
- package/dist/services/authentication.service.js.map +1 -1
- package/dist/services/crud-helper.service.d.ts +4 -0
- package/dist/services/crud-helper.service.d.ts.map +1 -1
- package/dist/services/crud-helper.service.js +66 -32
- package/dist/services/crud-helper.service.js.map +1 -1
- package/dist/services/crud.service.d.ts.map +1 -1
- package/dist/services/crud.service.js +7 -4
- package/dist/services/crud.service.js.map +1 -1
- package/dist/services/field-metadata.service.d.ts.map +1 -1
- package/dist/services/field-metadata.service.js.map +1 -1
- package/dist/services/file/disk-file.service.d.ts +0 -2
- package/dist/services/file/disk-file.service.d.ts.map +1 -1
- package/dist/services/file/disk-file.service.js +7 -16
- package/dist/services/file/disk-file.service.js.map +1 -1
- package/dist/services/file/index.d.ts +1 -0
- package/dist/services/file/index.d.ts.map +1 -1
- package/dist/services/file/index.js +1 -0
- package/dist/services/file/index.js.map +1 -1
- package/dist/services/file/storage-path-builder.d.ts +17 -0
- package/dist/services/file/storage-path-builder.d.ts.map +1 -0
- package/dist/{seeders/sms-template-seeder.service.js → services/file/storage-path-builder.js} +45 -35
- package/dist/services/file/storage-path-builder.js.map +1 -0
- package/dist/services/media.service.d.ts +1 -1
- package/dist/services/media.service.d.ts.map +1 -1
- package/dist/services/media.service.js +45 -6
- package/dist/services/media.service.js.map +1 -1
- package/dist/services/mediaStorageProviders/file-s3-storage-provider.js.map +1 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.d.ts.map +1 -1
- package/dist/services/mediaStorageProviders/file-storage-provider.js +46 -7
- package/dist/services/mediaStorageProviders/file-storage-provider.js.map +1 -1
- package/dist/services/module-metadata.service.d.ts +4 -6
- package/dist/services/module-metadata.service.d.ts.map +1 -1
- package/dist/services/module-metadata.service.js +16 -14
- package/dist/services/module-metadata.service.js.map +1 -1
- package/dist/services/setting.service.d.ts +3 -2
- package/dist/services/setting.service.d.ts.map +1 -1
- package/dist/services/setting.service.js +7 -4
- package/dist/services/setting.service.js.map +1 -1
- package/dist/services/settings/default-settings-provider.service.d.ts +24 -2
- package/dist/services/settings/default-settings-provider.service.d.ts.map +1 -1
- package/dist/services/settings/default-settings-provider.service.js +8 -6
- package/dist/services/settings/default-settings-provider.service.js.map +1 -1
- package/dist/solid-core.module.d.ts +3 -1
- package/dist/solid-core.module.d.ts.map +1 -1
- package/dist/solid-core.module.js +45 -9
- package/dist/solid-core.module.js.map +1 -1
- package/dist/testing/adapters/ui/playwright-adapter.d.ts.map +1 -1
- package/dist/testing/adapters/ui/playwright-adapter.js +35 -2
- package/dist/testing/adapters/ui/playwright-adapter.js.map +1 -1
- package/package.json +8 -2
- package/src/constants/error-messages.ts +1 -0
- package/src/constants.ts +3 -3
- package/src/controllers/role-metadata.controller.ts +26 -18
- package/src/dtos/create-email-template.dto.ts +7 -0
- package/src/dtos/create-list-of-values.dto.ts +7 -0
- package/src/dtos/create-menu-item-metadata.dto.ts +12 -1
- package/src/dtos/create-role-metadata.dto.ts +9 -0
- package/src/dtos/create-scheduled-job.dto.ts +14 -0
- package/src/dtos/create-security-rule.dto.ts +6 -0
- package/src/dtos/create-sms-template.dto.ts +6 -0
- package/src/dtos/create-view-metadata.dto.ts +11 -0
- package/src/dtos/otp-sign-in.dto.ts +3 -3
- package/src/dtos/otp-sign-up.dto.ts +3 -3
- package/src/dtos/resolve-s3-url.dto.ts +2 -12
- package/src/dtos/sign-up.dto.ts +0 -2
- package/src/dtos/update-email-template.dto.ts +6 -0
- package/src/dtos/update-list-of-values.dto.ts +8 -0
- package/src/dtos/update-menu-item-metadata.dto.ts +12 -0
- package/src/dtos/update-scheduled-job.dto.ts +15 -0
- package/src/dtos/update-security-rule.dto.ts +7 -0
- package/src/dtos/update-sms-template.dto.ts +32 -32
- package/src/dtos/update-view-metadata.dto.ts +12 -0
- package/src/entities/user.entity.ts +3 -0
- package/src/helpers/field-crud-managers/ManyToManyRelationFieldCrudManager.ts +43 -32
- package/src/helpers/field-crud-managers/OneToManyRelationFieldCrudManager.ts +45 -33
- package/src/helpers/security.helper.ts +1 -1
- package/src/index.ts +0 -4
- package/src/repository/solid-base.repository.ts +172 -1
- package/src/seeders/module-metadata-seeder.service.ts +188 -126
- package/src/seeders/permission-metadata-seeder.service.ts +1 -4
- package/src/seeders/seed-data/solid-core-metadata.json +12 -25
- package/src/services/authentication.service.ts +268 -266
- package/src/services/crud-helper.service.ts +79 -36
- package/src/services/crud.service.ts +9 -4
- package/src/services/field-metadata.service.ts +0 -71
- package/src/services/file/disk-file.service.ts +8 -18
- package/src/services/file/index.ts +1 -0
- package/src/services/file/storage-path-builder.ts +56 -0
- package/src/services/media.service.ts +13 -7
- package/src/services/mediaStorageProviders/file-s3-storage-provider.ts +1 -1
- package/src/services/mediaStorageProviders/file-storage-provider.ts +13 -8
- package/src/services/module-metadata.service.ts +18 -15
- package/src/services/setting.service.ts +5 -3
- package/src/services/settings/default-settings-provider.service.ts +5 -3
- package/src/solid-core.module.ts +16 -12
- package/src/testing/adapters/ui/playwright-adapter.ts +1 -1
- package/dist/passport-strategies/local.strategy.d.ts +0 -15
- package/dist/passport-strategies/local.strategy.d.ts.map +0 -1
- package/dist/passport-strategies/local.strategy.js +0 -44
- package/dist/passport-strategies/local.strategy.js.map +0 -1
- package/dist/seeders/email-template-seeder.service.d.ts +0 -10
- package/dist/seeders/email-template-seeder.service.d.ts.map +0 -1
- package/dist/seeders/email-template-seeder.service.js +0 -84
- package/dist/seeders/email-template-seeder.service.js.map +0 -1
- package/dist/seeders/sms-template-seeder.service.d.ts +0 -10
- package/dist/seeders/sms-template-seeder.service.d.ts.map +0 -1
- package/dist/seeders/sms-template-seeder.service.js.map +0 -1
- package/dist/seeders/user-seeder.service.d.ts +0 -10
- package/dist/seeders/user-seeder.service.d.ts.map +0 -1
- package/dist/seeders/user-seeder.service.js +0 -44
- package/dist/seeders/user-seeder.service.js.map +0 -1
- package/src/passport-strategies/local.strategy.ts +0 -28
- package/src/seeders/email-template-seeder.service.ts +0 -49
- package/src/seeders/sms-template-seeder.service.ts +0 -50
- package/src/seeders/user-seeder.service.ts +0 -33
|
@@ -93,23 +93,21 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
93
93
|
relations: { roles: true }
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
|
-
async
|
|
97
|
-
const user = await this.resolveUser(signInDto.username, signInDto.email);
|
|
98
|
-
if (!user) {
|
|
99
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_CREDENTIALS);
|
|
100
|
-
}
|
|
96
|
+
async validateUserForPasswordLogin(user, password) {
|
|
101
97
|
if (!user.active) {
|
|
102
98
|
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_ACTIVE);
|
|
103
99
|
}
|
|
104
|
-
|
|
100
|
+
this.checkAccountBlocked(user);
|
|
101
|
+
const isEqual = await this.hashingService.compare(password, user.password, user.passwordSchemeVersion);
|
|
105
102
|
if (!isEqual) {
|
|
103
|
+
await this.incrementFailedAttempts(user);
|
|
106
104
|
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_CREDENTIALS);
|
|
107
105
|
}
|
|
106
|
+
}
|
|
107
|
+
async rehashPasswordIfRequired(user, password) {
|
|
108
108
|
if (this.hashingService.needsRehash(user.password, user.passwordSchemeVersion)) {
|
|
109
|
-
|
|
110
|
-
return rehashedUser;
|
|
109
|
+
await this.updatePasswordDetails(user, password);
|
|
111
110
|
}
|
|
112
|
-
return user;
|
|
113
111
|
}
|
|
114
112
|
async signUp(signUpDto, activeUser = null) {
|
|
115
113
|
try {
|
|
@@ -258,56 +256,61 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
258
256
|
}
|
|
259
257
|
}
|
|
260
258
|
async otpInitiateRegistration(signUpDto) {
|
|
259
|
+
const isPasswordlessRegistrationEnabled = await this.isPasswordlessRegistrationEnabled();
|
|
260
|
+
if (!isPasswordlessRegistrationEnabled) {
|
|
261
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
262
|
+
}
|
|
263
|
+
const validationSource = this.resolvePasswordlessValidationSource();
|
|
264
|
+
this.validateOtpRegistrationInput(signUpDto, validationSource);
|
|
265
|
+
const existingUser = await this.findExistingRegistrationUser(signUpDto);
|
|
266
|
+
if ((0, class_validator_1.isNotEmpty)(existingUser) && existingUser.active) {
|
|
267
|
+
throw new common_1.ConflictException(error_messages_1.ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
268
|
+
}
|
|
261
269
|
try {
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
265
|
-
}
|
|
266
|
-
if ((0, class_validator_1.isEmpty)(signUpDto.mobile) && (0, class_validator_1.isEmpty)(signUpDto.email)) {
|
|
267
|
-
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.REGISTRATION_REQUIRES_CONTACT);
|
|
268
|
-
}
|
|
269
|
-
if (signUpDto.validationSources.includes(constants_1.TransactionalRegistrationValidationSource.EMAIL) && (0, class_validator_1.isEmpty)(signUpDto.email)) {
|
|
270
|
-
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.EMAIL_REQUIRED_FOR_VALIDATION);
|
|
271
|
-
}
|
|
272
|
-
if (signUpDto.validationSources.includes(constants_1.TransactionalRegistrationValidationSource.MOBILE) && (0, class_validator_1.isEmpty)(signUpDto.mobile)) {
|
|
273
|
-
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.MOBILE_REQUIRED_FOR_VALIDATION);
|
|
274
|
-
}
|
|
275
|
-
const existingUser = await this.userRepository.findOne({
|
|
276
|
-
where: [
|
|
277
|
-
{ email: signUpDto.email, },
|
|
278
|
-
{ mobile: signUpDto.mobile, },
|
|
279
|
-
{ username: signUpDto.username, }
|
|
280
|
-
]
|
|
281
|
-
});
|
|
282
|
-
if ((0, class_validator_1.isNotEmpty)(existingUser) && existingUser.active) {
|
|
283
|
-
throw new common_1.ConflictException(error_messages_1.ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
284
|
-
}
|
|
285
|
-
let passwordlessRegistrationValidateWhat = this.settingService.getConfigValue('passwordlessRegistrationValidateWhat');
|
|
286
|
-
if (!Array.isArray(passwordlessRegistrationValidateWhat)) {
|
|
287
|
-
passwordlessRegistrationValidateWhat = [passwordlessRegistrationValidateWhat];
|
|
288
|
-
}
|
|
289
|
-
const finalRegistrationVerificationSources = this.calculateVerificationSources(passwordlessRegistrationValidateWhat, signUpDto);
|
|
290
|
-
let user = existingUser;
|
|
291
|
-
if ((0, class_validator_1.isEmpty)(user)) {
|
|
292
|
-
user = this.createUser(signUpDto);
|
|
293
|
-
await this.populateVerificationTokens(finalRegistrationVerificationSources, user);
|
|
294
|
-
await this.userRepository.save(user);
|
|
295
|
-
await this.userService.addRoleToUser(user.username, this.settingService.getConfigValue('defaultRole'));
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
await this.populateVerificationTokens(finalRegistrationVerificationSources, user);
|
|
299
|
-
await this.userRepository.save(user);
|
|
300
|
-
}
|
|
301
|
-
await this.notifyUserOnOtpInitiateRegistration(user, finalRegistrationVerificationSources);
|
|
302
|
-
return { message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_REGISTRATION };
|
|
270
|
+
const user = await this.upsertUserWithRegistrationVerificationTokens(existingUser, signUpDto, validationSource);
|
|
271
|
+
await this.notifyUserOnOtpInitiateRegistration(user, validationSource);
|
|
303
272
|
}
|
|
304
273
|
catch (err) {
|
|
305
|
-
|
|
306
|
-
if (err.code === pgUniqueViolationErrorCode) {
|
|
274
|
+
if (err.code === '23505') {
|
|
307
275
|
throw new common_1.ConflictException(error_messages_1.ERROR_MESSAGES.USER_ALREADY_EXISTS);
|
|
308
276
|
}
|
|
309
277
|
throw err;
|
|
310
278
|
}
|
|
279
|
+
return { message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_REGISTRATION };
|
|
280
|
+
}
|
|
281
|
+
validateOtpRegistrationInput(signUpDto, validationSource) {
|
|
282
|
+
if (validationSource === constants_1.PasswordlessRegistrationValidateWhatSources.EMAIL && (0, class_validator_1.isEmpty)(signUpDto.email)) {
|
|
283
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.EMAIL_REQUIRED_FOR_VALIDATION);
|
|
284
|
+
}
|
|
285
|
+
if (validationSource === constants_1.PasswordlessRegistrationValidateWhatSources.MOBILE && (0, class_validator_1.isEmpty)(signUpDto.mobile)) {
|
|
286
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.MOBILE_REQUIRED_FOR_VALIDATION);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async findExistingRegistrationUser(signUpDto) {
|
|
290
|
+
return this.userRepository.findOne({
|
|
291
|
+
where: [
|
|
292
|
+
{ email: signUpDto.email },
|
|
293
|
+
{ mobile: signUpDto.mobile },
|
|
294
|
+
{ username: signUpDto.username },
|
|
295
|
+
]
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
resolvePasswordlessValidationSource() {
|
|
299
|
+
return this.settingService.getConfigValue('passwordlessRegistrationValidateWhat');
|
|
300
|
+
}
|
|
301
|
+
async upsertUserWithRegistrationVerificationTokens(existingUser, signUpDto, validationSource) {
|
|
302
|
+
let user = existingUser;
|
|
303
|
+
if ((0, class_validator_1.isEmpty)(user)) {
|
|
304
|
+
user = this.createUser(signUpDto);
|
|
305
|
+
await this.assignRegistrationOtp(validationSource, user);
|
|
306
|
+
await this.userRepository.save(user);
|
|
307
|
+
await this.userService.addRoleToUser(user.username, this.settingService.getConfigValue('defaultRole'));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
await this.assignRegistrationOtp(validationSource, user);
|
|
311
|
+
await this.userRepository.save(user);
|
|
312
|
+
}
|
|
313
|
+
return user;
|
|
311
314
|
}
|
|
312
315
|
createUser(signUpDto) {
|
|
313
316
|
const user = new user_entity_1.User();
|
|
@@ -318,44 +321,36 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
318
321
|
user.lastLoginProvider = LoginProvider.OTP;
|
|
319
322
|
return user;
|
|
320
323
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (configuredRegistrationValidationSources.includes(constants_1.RegistrationValidationSource.TRANSACTIONAL)) {
|
|
324
|
-
finalRegistrationValidationSources.push(...signUpDto.validationSources);
|
|
325
|
-
}
|
|
326
|
-
return finalRegistrationValidationSources;
|
|
327
|
-
}
|
|
328
|
-
async populateVerificationTokens(finalRegistrationValidationSources, user) {
|
|
329
|
-
if (finalRegistrationValidationSources.length === 0) {
|
|
324
|
+
async assignRegistrationOtp(passwordlessRegistrationValidateWhat, user) {
|
|
325
|
+
if (!passwordlessRegistrationValidateWhat) {
|
|
330
326
|
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.VALIDATION_SOURCE_REQUIRED);
|
|
331
327
|
}
|
|
332
|
-
|
|
328
|
+
const autoLoginUserOnRegistration = this.settingService.getConfigValue('autoLoginUserOnRegistration');
|
|
329
|
+
if (passwordlessRegistrationValidateWhat === constants_1.PasswordlessRegistrationValidateWhatSources.EMAIL) {
|
|
333
330
|
const { token, expiresAt } = await this.otp();
|
|
334
331
|
user.emailVerificationTokenOnRegistration = token;
|
|
335
332
|
user.emailVerificationTokenOnRegistrationExpiresAt = expiresAt;
|
|
336
|
-
const autoLoginUserOnRegistration = this.settingService.getConfigValue('autoLoginUserOnRegistration');
|
|
337
333
|
if (autoLoginUserOnRegistration) {
|
|
338
334
|
user.emailVerificationTokenOnLogin = token;
|
|
339
335
|
user.emailVerificationTokenOnLoginExpiresAt = expiresAt;
|
|
340
336
|
}
|
|
341
337
|
}
|
|
342
|
-
if (
|
|
338
|
+
if (passwordlessRegistrationValidateWhat === constants_1.PasswordlessRegistrationValidateWhatSources.MOBILE) {
|
|
343
339
|
const { token, expiresAt } = await this.otp();
|
|
344
340
|
user.mobileVerificationTokenOnRegistration = token;
|
|
345
341
|
user.mobileVerificationTokenOnRegistrationExpiresAt = expiresAt;
|
|
346
|
-
const autoLoginUserOnRegistration = this.settingService.getConfigValue('autoLoginUserOnRegistration');
|
|
347
342
|
if (autoLoginUserOnRegistration) {
|
|
348
343
|
user.mobileVerificationTokenOnLogin = token;
|
|
349
344
|
user.mobileVerificationTokenOnLoginExpiresAt = expiresAt;
|
|
350
345
|
}
|
|
351
346
|
}
|
|
352
347
|
}
|
|
353
|
-
async notifyUserOnOtpInitiateRegistration(user,
|
|
348
|
+
async notifyUserOnOtpInitiateRegistration(user, registrationValidationSource) {
|
|
354
349
|
const companyLogo = await this.getCompanyLogo();
|
|
355
350
|
const dummyOtp = this.settingService.getConfigValue('dummyOtp');
|
|
356
351
|
if (dummyOtp)
|
|
357
352
|
return;
|
|
358
|
-
if (
|
|
353
|
+
if (registrationValidationSource === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
359
354
|
const mailService = this.mailServiceFactory.getMailService();
|
|
360
355
|
mailService.sendEmailUsingTemplate(user.email, 'otp-on-register', {
|
|
361
356
|
solidAppName: this.settingService.getConfigValue('appTitle'),
|
|
@@ -366,7 +361,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
366
361
|
companyLogoUrl: companyLogo
|
|
367
362
|
}, this.settingService.getConfigValue('shouldQueueEmails'), null, null, 'user', user.id);
|
|
368
363
|
}
|
|
369
|
-
if (
|
|
364
|
+
if (registrationValidationSource === constants_1.PasswordlessLoginValidateWhatSources.MOBILE) {
|
|
370
365
|
const smsService = this.smsFactory.getSmsService();
|
|
371
366
|
smsService.sendSMSUsingTemplate(user.mobile, 'otp-on-register', {
|
|
372
367
|
solidAppName: this.settingService.getConfigValue('appTitle'),
|
|
@@ -383,67 +378,65 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
383
378
|
if (!isPasswordlessRegistrationEnabled) {
|
|
384
379
|
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
385
380
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
381
|
+
const { type, identifier, otp } = confirmSignUpDto;
|
|
382
|
+
if (type !== constants_1.PasswordlessRegistrationValidateWhatSources.EMAIL &&
|
|
383
|
+
type !== constants_1.PasswordlessRegistrationValidateWhatSources.MOBILE) {
|
|
384
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
385
|
+
}
|
|
386
|
+
const user = await this.findUserByRegistrationIdentifier(type, identifier);
|
|
387
|
+
this.validateRegistrationOtp(user, otp, type);
|
|
388
|
+
this.clearRegistrationOtp(user, type);
|
|
389
|
+
user.active = this.settingService.getConfigValue('activateUserOnRegistration') &&
|
|
390
|
+
await this.areAllPasswordlessRegistrationValidationSourcesVerified(user);
|
|
391
|
+
const savedUser = await this.userRepository.save(user);
|
|
392
|
+
this.triggerRegistrationEvent(savedUser);
|
|
393
|
+
return { active: savedUser.active, message: `User registration verified for ${type}` };
|
|
394
|
+
}
|
|
395
|
+
async findUserByRegistrationIdentifier(type, identifier) {
|
|
396
|
+
const where = type === constants_1.PasswordlessRegistrationValidateWhatSources.EMAIL
|
|
397
|
+
? { email: identifier }
|
|
398
|
+
: { mobile: identifier };
|
|
399
|
+
const user = await this.userRepository.findOne({ where });
|
|
400
|
+
if (!user) {
|
|
401
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
402
|
+
}
|
|
403
|
+
return user;
|
|
404
|
+
}
|
|
405
|
+
validateRegistrationOtp(user, otp, type) {
|
|
406
|
+
const isEmail = type === constants_1.PasswordlessRegistrationValidateWhatSources.EMAIL;
|
|
407
|
+
const token = isEmail ? user.emailVerificationTokenOnRegistration : user.mobileVerificationTokenOnRegistration;
|
|
408
|
+
const expiresAt = isEmail ? user.emailVerificationTokenOnRegistrationExpiresAt : user.mobileVerificationTokenOnRegistrationExpiresAt;
|
|
409
|
+
if (token !== otp) {
|
|
410
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
411
|
+
}
|
|
412
|
+
if (expiresAt < new Date()) {
|
|
413
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.OTP_EXPIRED);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
clearRegistrationOtp(user, type) {
|
|
417
|
+
if (type === constants_1.PasswordlessRegistrationValidateWhatSources.EMAIL) {
|
|
401
418
|
user.emailVerifiedOnRegistrationAt = new Date();
|
|
402
419
|
user.emailVerificationTokenOnRegistration = null;
|
|
403
420
|
user.emailVerificationTokenOnRegistrationExpiresAt = null;
|
|
404
|
-
user.active = this.settingService.getConfigValue('activateUserOnRegistration') && await this.areRegistrationValidationSourcesVerified(user);
|
|
405
|
-
const savedUser = await this.userRepository.save(user);
|
|
406
|
-
this.triggerRegistrationEvent(savedUser);
|
|
407
|
-
return { active: savedUser.active, message: `User registration verified for ${confirmSignUpDto.type}` };
|
|
408
421
|
}
|
|
409
|
-
else
|
|
410
|
-
const user = await this.userRepository.findOne({
|
|
411
|
-
where: {
|
|
412
|
-
mobile: confirmSignUpDto.identifier,
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
if (!user) {
|
|
416
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
417
|
-
}
|
|
418
|
-
if (user.mobileVerificationTokenOnRegistration !== confirmSignUpDto.otp) {
|
|
419
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
420
|
-
}
|
|
421
|
-
if (user.mobileVerificationTokenOnRegistrationExpiresAt < new Date()) {
|
|
422
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
423
|
-
}
|
|
422
|
+
else {
|
|
424
423
|
user.mobileVerifiedOnRegistrationAt = new Date();
|
|
425
424
|
user.mobileVerificationTokenOnRegistration = null;
|
|
426
425
|
user.mobileVerificationTokenOnRegistrationExpiresAt = null;
|
|
427
|
-
user.active = this.settingService.getConfigValue('activateUserOnRegistration') && await this.areRegistrationValidationSourcesVerified(user);
|
|
428
|
-
const savedUser = await this.userRepository.save(user);
|
|
429
|
-
this.triggerRegistrationEvent(savedUser);
|
|
430
|
-
return { active: savedUser.active, message: `User registration verified for ${confirmSignUpDto.type}` };
|
|
431
426
|
}
|
|
432
|
-
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
433
427
|
}
|
|
434
428
|
triggerRegistrationEvent(savedUser) {
|
|
435
429
|
const event = new interfaces_1.EventDetails(interfaces_1.EventType.USER_REGISTERED, savedUser);
|
|
436
430
|
this.eventEmitter.emit(interfaces_1.EventType.USER_REGISTERED, event);
|
|
437
431
|
}
|
|
438
|
-
async
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
if (registrationValidationSources.includes(constants_1.RegistrationValidationSource.EMAIL)) {
|
|
432
|
+
async areAllPasswordlessRegistrationValidationSourcesVerified(user) {
|
|
433
|
+
const registrationValidationSource = this.resolvePasswordlessValidationSource();
|
|
434
|
+
if (registrationValidationSource === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
442
435
|
if (!user.emailVerifiedOnRegistrationAt) {
|
|
443
436
|
return false;
|
|
444
437
|
}
|
|
445
438
|
}
|
|
446
|
-
if (
|
|
439
|
+
if (registrationValidationSource === constants_1.PasswordlessLoginValidateWhatSources.MOBILE) {
|
|
447
440
|
if (!user.mobileVerifiedOnRegistrationAt) {
|
|
448
441
|
return false;
|
|
449
442
|
}
|
|
@@ -461,7 +454,13 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
461
454
|
};
|
|
462
455
|
}
|
|
463
456
|
async signIn(signInDto) {
|
|
464
|
-
const user = await this.
|
|
457
|
+
const user = await this.resolveUser(signInDto.username, signInDto.email);
|
|
458
|
+
if (!user) {
|
|
459
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_CREDENTIALS);
|
|
460
|
+
}
|
|
461
|
+
await this.validateUserForPasswordLogin(user, signInDto.password);
|
|
462
|
+
await this.rehashPasswordIfRequired(user, signInDto.password);
|
|
463
|
+
await this.resetFailedAttempts(user);
|
|
465
464
|
const tokens = await this.generateTokens(user);
|
|
466
465
|
await this.userActivityHistoryService.logEvent('login', user);
|
|
467
466
|
return {
|
|
@@ -501,63 +500,67 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
501
500
|
if (!isPasswordlessRegistrationEnabled) {
|
|
502
501
|
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
503
502
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
throw new common_1.
|
|
503
|
+
const type = this.resolveLoginType(signInDto);
|
|
504
|
+
const user = await this.findUserForLogin(type, signInDto.identifier);
|
|
505
|
+
await this.assignLoginOtp(user, type);
|
|
506
|
+
this.notifyUserOnOtpInititateLogin(user, type);
|
|
507
|
+
return this.buildLoginOtpResponse(user, type);
|
|
508
|
+
}
|
|
509
|
+
resolveLoginType(signInDto) {
|
|
510
|
+
const setting = this.settingService.getConfigValue('passwordlessLoginValidateWhat');
|
|
511
|
+
if (setting === constants_1.PasswordlessLoginValidateWhatSources.SELECTABLE) {
|
|
512
|
+
if (signInDto.type !== constants_1.PasswordlessLoginValidateWhatSources.EMAIL &&
|
|
513
|
+
signInDto.type !== constants_1.PasswordlessLoginValidateWhatSources.MOBILE) {
|
|
514
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
516
515
|
}
|
|
517
|
-
|
|
516
|
+
return signInDto.type;
|
|
517
|
+
}
|
|
518
|
+
if (setting === constants_1.PasswordlessLoginValidateWhatSources.EMAIL ||
|
|
519
|
+
setting === constants_1.PasswordlessLoginValidateWhatSources.MOBILE) {
|
|
520
|
+
return setting;
|
|
521
|
+
}
|
|
522
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
523
|
+
}
|
|
524
|
+
async findUserForLogin(type, identifier, options = {}) {
|
|
525
|
+
const typeWhere = type === constants_1.PasswordlessLoginValidateWhatSources.EMAIL
|
|
526
|
+
? { email: identifier }
|
|
527
|
+
: { mobile: identifier };
|
|
528
|
+
const user = await this.userRepository.findOne({
|
|
529
|
+
where: [{ username: identifier }, typeWhere],
|
|
530
|
+
...(options.withRoles ? { relations: { roles: true } } : {}),
|
|
531
|
+
});
|
|
532
|
+
if (!user) {
|
|
533
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
534
|
+
}
|
|
535
|
+
if (!user.active) {
|
|
536
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
537
|
+
}
|
|
538
|
+
return user;
|
|
539
|
+
}
|
|
540
|
+
async assignLoginOtp(user, type) {
|
|
541
|
+
const { token, expiresAt } = await this.otp();
|
|
542
|
+
if (type === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
518
543
|
user.emailVerificationTokenOnLogin = token;
|
|
519
544
|
user.emailVerificationTokenOnLoginExpiresAt = expiresAt;
|
|
520
|
-
await this.userRepository.save(user);
|
|
521
|
-
this.notifyUserOnOtpInititateLogin(user, constants_1.RegistrationValidationSource.EMAIL);
|
|
522
|
-
return {
|
|
523
|
-
message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_LOGIN,
|
|
524
|
-
user: {
|
|
525
|
-
email: this.maskEmail(user.email)
|
|
526
|
-
}
|
|
527
|
-
};
|
|
528
545
|
}
|
|
529
|
-
else
|
|
530
|
-
const user = await this.userRepository.findOne({
|
|
531
|
-
where: [
|
|
532
|
-
{ username: signInDto.identifier },
|
|
533
|
-
{ mobile: signInDto.identifier },
|
|
534
|
-
]
|
|
535
|
-
});
|
|
536
|
-
if (!user) {
|
|
537
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
538
|
-
}
|
|
539
|
-
const { token, expiresAt } = await this.otp();
|
|
546
|
+
else {
|
|
540
547
|
user.mobileVerificationTokenOnLogin = token;
|
|
541
548
|
user.mobileVerificationTokenOnLoginExpiresAt = expiresAt;
|
|
542
|
-
await this.userRepository.save(user);
|
|
543
|
-
this.notifyUserOnOtpInititateLogin(user, constants_1.RegistrationValidationSource.MOBILE);
|
|
544
|
-
return {
|
|
545
|
-
message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_LOGIN,
|
|
546
|
-
user: {
|
|
547
|
-
mobile: this.maskMobile(user.mobile)
|
|
548
|
-
}
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
else {
|
|
552
|
-
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
553
549
|
}
|
|
550
|
+
await this.userRepository.save(user);
|
|
551
|
+
}
|
|
552
|
+
buildLoginOtpResponse(user, type) {
|
|
553
|
+
const maskedIdentifier = type === constants_1.PasswordlessLoginValidateWhatSources.EMAIL
|
|
554
|
+
? { email: this.maskEmail(user.email) }
|
|
555
|
+
: { mobile: this.maskMobile(user.mobile) };
|
|
556
|
+
return { message: success_messages_1.SUCCESS_MESSAGES.OTP_SENT_SUCCESS_LOGIN, user: maskedIdentifier };
|
|
554
557
|
}
|
|
555
558
|
async notifyUserOnOtpInititateLogin(user, loginType) {
|
|
556
559
|
const companyLogo = await this.getCompanyLogo();
|
|
557
560
|
const dummyOtp = this.settingService.getConfigValue('dummyOtp');
|
|
558
561
|
if (dummyOtp)
|
|
559
562
|
return;
|
|
560
|
-
if (loginType === constants_1.
|
|
563
|
+
if (loginType === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
561
564
|
const mailService = this.mailServiceFactory.getMailService();
|
|
562
565
|
mailService.sendEmailUsingTemplate(user.email, 'otp-on-login', {
|
|
563
566
|
solidAppName: this.settingService.getConfigValue('appTitle'),
|
|
@@ -568,7 +571,7 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
568
571
|
companyLogoUrl: companyLogo
|
|
569
572
|
}, this.settingService.getConfigValue('shouldQueueEmails'), null, null, 'user', user.id);
|
|
570
573
|
}
|
|
571
|
-
if (loginType === constants_1.
|
|
574
|
+
if (loginType === constants_1.PasswordlessLoginValidateWhatSources.MOBILE) {
|
|
572
575
|
const smsService = this.smsFactory.getSmsService();
|
|
573
576
|
smsService.sendSMSUsingTemplate(user.mobile, 'otp-on-login', {
|
|
574
577
|
solidAppName: this.settingService.getConfigValue('appTitle'),
|
|
@@ -585,69 +588,53 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
585
588
|
if (!isPasswordlessRegistrationEnabled) {
|
|
586
589
|
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.PASSWORDLESS_REGISTRATION_DISABLED);
|
|
587
590
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
591
|
+
const { type, identifier, otp } = confirmSignInDto;
|
|
592
|
+
if (type !== constants_1.PasswordlessLoginValidateWhatSources.EMAIL &&
|
|
593
|
+
type !== constants_1.PasswordlessLoginValidateWhatSources.MOBILE) {
|
|
594
|
+
throw new common_1.BadRequestException(error_messages_1.ERROR_MESSAGES.INVALID_VERIFICATION_TYPE);
|
|
595
|
+
}
|
|
596
|
+
const user = await this.findUserForLogin(type, identifier, { withRoles: true });
|
|
597
|
+
this.checkAccountBlocked(user);
|
|
598
|
+
try {
|
|
599
|
+
this.validateLoginOtp(user, otp, type);
|
|
600
|
+
}
|
|
601
|
+
catch (e) {
|
|
602
|
+
await this.incrementFailedAttempts(user);
|
|
603
|
+
throw e;
|
|
604
|
+
}
|
|
605
|
+
this.clearLoginOtp(user, type);
|
|
606
|
+
user.failedLoginAttempts = 0;
|
|
607
|
+
await this.userRepository.save(user);
|
|
608
|
+
return this.buildLoginTokenResponse(user);
|
|
609
|
+
}
|
|
610
|
+
validateLoginOtp(user, otp, type) {
|
|
611
|
+
const isEmail = type === constants_1.PasswordlessLoginValidateWhatSources.EMAIL;
|
|
612
|
+
const token = isEmail ? user.emailVerificationTokenOnLogin : user.mobileVerificationTokenOnLogin;
|
|
613
|
+
const expiresAt = isEmail ? user.emailVerificationTokenOnLoginExpiresAt : user.mobileVerificationTokenOnLoginExpiresAt;
|
|
614
|
+
if (token !== otp) {
|
|
615
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
616
|
+
}
|
|
617
|
+
if (expiresAt < new Date()) {
|
|
618
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.OTP_EXPIRED);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
clearLoginOtp(user, type) {
|
|
622
|
+
if (type === constants_1.PasswordlessLoginValidateWhatSources.EMAIL) {
|
|
610
623
|
user.emailVerifiedOnLoginAt = new Date();
|
|
611
624
|
user.emailVerificationTokenOnLogin = null;
|
|
612
625
|
user.emailVerificationTokenOnLoginExpiresAt = null;
|
|
613
|
-
await this.userRepository.save(user);
|
|
614
|
-
const { accessToken, refreshToken } = await this.generateTokens(user);
|
|
615
|
-
const { id, username, email, mobile, lastLoginProvider } = user;
|
|
616
|
-
const roles = user.roles.map((role) => role.name);
|
|
617
|
-
return { accessToken, refreshToken, user: { id, username, email, mobile, lastLoginProvider, roles } };
|
|
618
626
|
}
|
|
619
|
-
else
|
|
620
|
-
const user = await this.userRepository.findOne({
|
|
621
|
-
where: [
|
|
622
|
-
{ username: confirmSignInDto.identifier },
|
|
623
|
-
{ mobile: confirmSignInDto.identifier },
|
|
624
|
-
],
|
|
625
|
-
relations: {
|
|
626
|
-
roles: true
|
|
627
|
-
}
|
|
628
|
-
});
|
|
629
|
-
if (!user) {
|
|
630
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_ACTIVE);
|
|
631
|
-
}
|
|
632
|
-
if (!user.active) {
|
|
633
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_INACTIVE);
|
|
634
|
-
}
|
|
635
|
-
if (user.mobileVerificationTokenOnLogin !== confirmSignInDto.otp) {
|
|
636
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
637
|
-
}
|
|
638
|
-
if (user.mobileVerificationTokenOnLoginExpiresAt < new Date()) {
|
|
639
|
-
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.INVALID_OTP);
|
|
640
|
-
}
|
|
627
|
+
else {
|
|
641
628
|
user.mobileVerifiedOnLoginAt = new Date();
|
|
642
629
|
user.mobileVerificationTokenOnLogin = null;
|
|
643
630
|
user.mobileVerificationTokenOnLoginExpiresAt = null;
|
|
644
|
-
await this.userRepository.save(user);
|
|
645
|
-
const { accessToken, refreshToken } = await this.generateTokens(user);
|
|
646
|
-
const { id, username, email, mobile, lastLoginProvider } = user;
|
|
647
|
-
const roles = user.roles.map((role) => role.name);
|
|
648
|
-
return { accessToken, refreshToken, user: { id, username, email, mobile, lastLoginProvider, roles } };
|
|
649
631
|
}
|
|
650
|
-
|
|
632
|
+
}
|
|
633
|
+
async buildLoginTokenResponse(user) {
|
|
634
|
+
const { accessToken, refreshToken } = await this.generateTokens(user);
|
|
635
|
+
const { id, username, email, mobile, lastLoginProvider } = user;
|
|
636
|
+
const roles = user.roles.map((role) => role.name);
|
|
637
|
+
return { accessToken, refreshToken, user: { id, username, email, mobile, lastLoginProvider, roles } };
|
|
651
638
|
}
|
|
652
639
|
async changePassword(changePasswordDto, activeUser) {
|
|
653
640
|
const user = await this.userRepository.findOne({
|
|
@@ -911,7 +898,18 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
911
898
|
roles: true
|
|
912
899
|
}
|
|
913
900
|
});
|
|
914
|
-
|
|
901
|
+
if (!user) {
|
|
902
|
+
throw new common_1.UnauthorizedException(error_messages_1.ERROR_MESSAGES.USER_NOT_FOUND);
|
|
903
|
+
}
|
|
904
|
+
this.checkAccountBlocked(user);
|
|
905
|
+
try {
|
|
906
|
+
await this.validateUserUsingGoogle(user);
|
|
907
|
+
}
|
|
908
|
+
catch (e) {
|
|
909
|
+
await this.incrementFailedAttempts(user);
|
|
910
|
+
throw e;
|
|
911
|
+
}
|
|
912
|
+
await this.resetFailedAttempts(user);
|
|
915
913
|
const tokens = await this.generateTokens(user);
|
|
916
914
|
return {
|
|
917
915
|
user: {
|
|
@@ -927,6 +925,22 @@ let AuthenticationService = AuthenticationService_1 = class AuthenticationServic
|
|
|
927
925
|
async isPasswordlessRegistrationEnabled() {
|
|
928
926
|
return this.settingService.getConfigValue('passwordLessAuth');
|
|
929
927
|
}
|
|
928
|
+
checkAccountBlocked(user) {
|
|
929
|
+
const maxFailedAttempts = this.settingService.getConfigValue('maxFailedLoginAttempts');
|
|
930
|
+
if (maxFailedAttempts > 0 && user.failedLoginAttempts >= maxFailedAttempts) {
|
|
931
|
+
throw new common_1.ForbiddenException(error_messages_1.ERROR_MESSAGES.ACCOUNT_BLOCKED);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
async incrementFailedAttempts(user) {
|
|
935
|
+
user.failedLoginAttempts += 1;
|
|
936
|
+
await this.userRepository.save(user);
|
|
937
|
+
}
|
|
938
|
+
async resetFailedAttempts(user) {
|
|
939
|
+
if (user.failedLoginAttempts === 0)
|
|
940
|
+
return;
|
|
941
|
+
user.failedLoginAttempts = 0;
|
|
942
|
+
await this.userRepository.save(user);
|
|
943
|
+
}
|
|
930
944
|
async logout(refreshToken) {
|
|
931
945
|
try {
|
|
932
946
|
const payload = this.jwtService.decode(refreshToken);
|