Clean validator in AccountController

This commit is contained in:
Alice Gaudon 2021-02-23 17:45:32 +01:00
parent caae753d74
commit ec0dc30709

View File

@ -91,11 +91,11 @@ export default class AccountController extends Controller {
} }
protected async postChangePassword(req: Request, res: Response): Promise<void> { protected async postChangePassword(req: Request, res: Response): Promise<void> {
const validationMap = { await Validator.validate({
'new_password': new Validator().defined(), 'new_password': new Validator().defined(),
'new_password_confirmation': new Validator().sameAs('new_password', req.body.new_password), 'new_password_confirmation': new Validator().sameAs('new_password', req.body.new_password),
}; }, req.body);
await Validator.validate(validationMap, req.body);
const user = req.as(RequireAuthMiddleware).getUser(); const user = req.as(RequireAuthMiddleware).getUser();
const passwordComponent = user.as(UserPasswordComponent); const passwordComponent = user.as(UserPasswordComponent);
if (passwordComponent.hasPassword() && !await passwordComponent.verifyPassword(req.body.current_password)) { if (passwordComponent.hasPassword() && !await passwordComponent.verifyPassword(req.body.current_password)) {