@loomcore/api 0.0.27 → 0.0.28
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ObjectId } from 'mongodb';
|
|
2
2
|
import moment from 'moment';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
|
-
import { EmptyUserContext, UserSpec, getSystemUserContext } from '@loomcore/common/models';
|
|
4
|
+
import { EmptyUserContext, passwordValidator, UserSpec, getSystemUserContext } from '@loomcore/common/models';
|
|
5
5
|
import { entityUtils } from '@loomcore/common/utils';
|
|
6
6
|
import { BadRequestError, ServerError } from '../errors/index.js';
|
|
7
7
|
import { JwtService, EmailService } from './index.js';
|
|
@@ -93,7 +93,8 @@ export class AuthService extends GenericApiService {
|
|
|
93
93
|
return result;
|
|
94
94
|
}
|
|
95
95
|
async changePassword(userContext, queryObject, password) {
|
|
96
|
-
const
|
|
96
|
+
const hashedPassword = await passwordUtils.hashPassword(password);
|
|
97
|
+
const updates = { password: hashedPassword, _lastPasswordChange: moment().utc().toDate() };
|
|
97
98
|
const updatedUsers = await super.update(userContext, queryObject, updates);
|
|
98
99
|
const result = {
|
|
99
100
|
acknowledged: true,
|
|
@@ -180,6 +181,8 @@ export class AuthService extends GenericApiService {
|
|
|
180
181
|
if (retrievedPasswordResetToken.token !== passwordResetToken || retrievedPasswordResetToken.expiresOn < Date.now()) {
|
|
181
182
|
throw new BadRequestError('Invalid password reset token');
|
|
182
183
|
}
|
|
184
|
+
const validationErrors = entityUtils.validate(passwordValidator, { password: password });
|
|
185
|
+
entityUtils.handleValidationResult(validationErrors, 'AuthService.resetPassword');
|
|
183
186
|
const result = await this.changePassword(EmptyUserContext, { email: lowerCaseEmail }, password);
|
|
184
187
|
console.log(`password changed using forgot-password for email: ${lowerCaseEmail}`);
|
|
185
188
|
await this.passwordResetTokenService.deleteById(EmptyUserContext, retrievedPasswordResetToken._id.toString());
|