When is the validation evaluated? It would seem that there would be exception thrown with the validation errors before it started to try and authenticate the current user/password. But it seems this is not the case.
Service Class:
[Authenticate]
public object Post(UpdatePassword request)
{
var userAuthRepo = base.TryResolve<IAuthRepository>();
var currentUserAuth = (UserAuth)userAuthRepo.GetUserAuth(UserSession, null);
IUserAuth verifyUserAuth;
if(userAuthRepo.TryAuthenticate(UserSession.Email, request.CurrentPassword, out verifyUserAuth)) {
userAuthRepo.UpdateUserAuth(currentUserAuth, currentUserAuth, request.NewPassword);
}
else
{
throw new ArgumentException("Current Password is invalid");
}
return new HttpResult(HttpStatusCode.OK);
}
Validator:
public class UpdatePasswordValidator: AbstractValidator<UpdatePassword>
{
public UpdatePasswordValidator()
{
RuleSet(ApplyTo.Post, () => {
RuleFor(p => p.CurrentPassword).NotEmpty().WithMessage("Current Password is required");
RuleFor(p => p.NewPassword).Length(8, 50).WithMessage("New Password must be at least 8 characters");
RuleFor(p => p.NewPassword).Equal(p => p.ConfirmPassword).WithMessage("Passwords do not match");
RuleFor(p => p.NewPassword).Matches("[a-z]").WithMessage("New Password must contain at least 1 lower case character");
RuleFor(p => p.NewPassword).Matches("[A-Z]").WithMessage("New Password must contain at least 1 upper case character");
RuleFor(p => p.NewPassword).Matches("[0-9]").WithMessage("New Password must contain at least 1 number");
});
}
}