Search in sources :

Example 6 with ValidationContext

use of org.summerb.validation.ValidationContext in project summerb by skarpushin.

the class UsersServiceFacadeImpl method validateRegistration.

protected void validateRegistration(Registration registration) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    validateDisplayName(registration.getDisplayName(), ctx);
    validatePassword(registration.getPassword(), ctx);
    ctx.validateEmailFormat(registration.getEmail(), User.FN_EMAIL);
    ctx.throwIfHasErrors();
}
Also used : ValidationContext(org.summerb.validation.ValidationContext)

Example 7 with ValidationContext

use of org.summerb.validation.ValidationContext in project summerb by skarpushin.

the class UsersServiceFacadeImpl method validatePasswordReset.

protected void validatePasswordReset(PasswordReset resetPasswordRequest) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    validatePassword(resetPasswordRequest.getPassword(), ctx);
    if (!resetPasswordRequest.getPassword().equals(resetPasswordRequest.getNewPasswordAgain())) {
        ctx.add(new PasswordsDontMatchValidationError());
    }
    ctx.throwIfHasErrors();
}
Also used : PasswordsDontMatchValidationError(org.summerb.webappboilerplate.security.ve.PasswordsDontMatchValidationError) ValidationContext(org.summerb.validation.ValidationContext)

Example 8 with ValidationContext

use of org.summerb.validation.ValidationContext in project summerb by skarpushin.

the class UsersServiceFacadeImpl method validateUserIsEligableForPasswordReset.

protected void validateUserIsEligableForPasswordReset(String email) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    if (!ctx.validateEmailFormat(email, User.FN_EMAIL)) {
        throw new FieldValidationException(ctx.getErrors());
    }
    // now see if this user exists
    UserStatus userStatus = getUserStatusByEmail(email);
    if (userStatus == UserStatus.NotExists || userStatus == UserStatus.Provisioned) {
        throw new FieldValidationException(new RegistrationRequiredValidationError());
    }
    // Sanity check
    if (userStatus != UserStatus.NormalUser && userStatus != UserStatus.AwaitingActivation) {
        throw new RuntimeException("Password Reset scenario is not supported for user whose status is: " + userStatus);
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) RegistrationRequiredValidationError(org.summerb.webappboilerplate.security.ve.RegistrationRequiredValidationError) UserStatus(org.summerb.webappboilerplate.security.dto.UserStatus) ValidationContext(org.summerb.validation.ValidationContext)

Example 9 with ValidationContext

use of org.summerb.validation.ValidationContext in project summerb by skarpushin.

the class EasyCrudValidationStrategyAbstract method validateForCreate.

@Override
public void validateForCreate(TDto dto) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    doValidateForCreate(dto, ctx);
    if (ctx.getHasErrors()) {
        throw new FieldValidationException(ctx.getErrors());
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) ValidationContext(org.summerb.validation.ValidationContext)

Example 10 with ValidationContext

use of org.summerb.validation.ValidationContext in project summerb by skarpushin.

the class EasyCrudValidationStrategyAbstract method validateForUpdate.

@Override
public void validateForUpdate(TDto existingVersion, TDto newVersion) throws FieldValidationException {
    ValidationContext ctx = new ValidationContext();
    doValidateForUpdate(existingVersion, newVersion, ctx);
    if (ctx.getHasErrors()) {
        throw new FieldValidationException(ctx.getErrors());
    }
}
Also used : FieldValidationException(org.summerb.validation.FieldValidationException) ValidationContext(org.summerb.validation.ValidationContext)

Aggregations

ValidationContext (org.summerb.validation.ValidationContext)14 FieldValidationException (org.summerb.validation.FieldValidationException)4 Test (org.junit.Test)3 StringTemplateCompiler (org.summerb.stringtemplate.api.StringTemplateCompiler)3 StringTemplateCompilerlImpl (org.summerb.stringtemplate.impl.StringTemplateCompilerlImpl)3 User (org.summerb.users.api.dto.User)2 PSQLException (org.postgresql.util.PSQLException)1 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)1 UserNotFoundException (org.summerb.users.api.exceptions.UserNotFoundException)1 DuplicateRecordValidationError (org.summerb.validation.errors.DuplicateRecordValidationError)1 UserStatus (org.summerb.webappboilerplate.security.dto.UserStatus)1 PasswordsDontMatchValidationError (org.summerb.webappboilerplate.security.ve.PasswordsDontMatchValidationError)1 RegistrationRequiredValidationError (org.summerb.webappboilerplate.security.ve.RegistrationRequiredValidationError)1