I have a login form:
public static class LoginForm {
@Constraints.Required
public String email;
@Constraints.Required
public String password;
}
And I need to validate if user exist or is validated. So my validate function is:
public List<ValidationError> validate() {
List<ValidationError> errors = new ArrayList<ValidationError>();
User user = User.findByEmail(email);
if (user == null || !Hash.checkPassword(password, user.passwordHash)) {
errors.add(new ValidationError("email", "Invalid email"));
return errors;
} else if (!user.validated) {
errors.add(new ValidationError("email", "Not validated email"));
return errors;
}
return null;
}
But how to make these errors global?
Ok I found out solution. I have to pass to concstuctor of ValidationError first argument as empty string. So whole code looks like: