Search in sources :

Example 1 with RegisterCustomerForm

use of org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerValidator method validate.

public void validate(Object obj, Errors errors, boolean useEmailForUsername) {
    RegisterCustomerForm form = (RegisterCustomerForm) obj;
    Customer customerFromDb = customerService.readCustomerByUsername(form.getCustomer().getUsername());
    if (customerFromDb != null && customerFromDb.isRegistered()) {
        if (useEmailForUsername) {
            errors.rejectValue("customer.emailAddress", "emailAddress.used", null, null);
        } else {
            errors.rejectValue("customer.username", "username.used", null, null);
        }
    }
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordConfirm", "passwordConfirm.required");
    errors.pushNestedPath("customer");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
    errors.popNestedPath();
    if (!errors.hasErrors()) {
        if (!form.getPassword().matches(getValidatePasswordExpression())) {
            errors.rejectValue("password", "password.invalid", null, null);
        }
        if (!form.getPassword().equals(form.getPasswordConfirm())) {
            errors.rejectValue("password", "passwordConfirm.invalid", null, null);
        }
        if (!GenericValidator.isEmail(form.getCustomer().getEmailAddress())) {
            errors.rejectValue("customer.emailAddress", "emailAddress.invalid", null, null);
        }
    }
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm)

Example 2 with RegisterCustomerForm

use of org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerDataProvider method createCustomer.

@DataProvider(name = "setupCustomerControllerData")
public static Object[][] createCustomer() {
    Customer customer = new CustomerImpl();
    customer.setEmailAddress("testCase@test.com");
    customer.setFirstName("TestFirstName");
    customer.setLastName("TestLastName");
    customer.setUsername("TestCase");
    ChallengeQuestion question = new ChallengeQuestionImpl();
    question.setId(1L);
    customer.setChallengeQuestion(question);
    customer.setChallengeAnswer("Challenge CandidateItemOfferAnswer");
    RegisterCustomerForm registerCustomer = new RegisterCustomerForm();
    registerCustomer.setCustomer(customer);
    registerCustomer.setPassword("TestPassword");
    registerCustomer.setPasswordConfirm("TestPassword");
    return new Object[][] { new Object[] { registerCustomer } };
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) ChallengeQuestionImpl(org.broadleafcommerce.profile.core.domain.ChallengeQuestionImpl) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm) CustomerImpl(org.broadleafcommerce.profile.core.domain.CustomerImpl) ChallengeQuestion(org.broadleafcommerce.profile.core.domain.ChallengeQuestion) DataProvider(org.testng.annotations.DataProvider)

Example 3 with RegisterCustomerForm

use of org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm in project BroadleafCommerce by BroadleafCommerce.

the class RegistrationServiceImpl method initCustomerRegistrationForm.

@Override
public RegisterCustomerForm initCustomerRegistrationForm() {
    Customer customer = CustomerState.getCustomer();
    if (customer == null || !customer.isAnonymous()) {
        customer = customerService.createCustomerFromId(null);
    }
    RegisterCustomerForm customerRegistrationForm = new RegisterCustomerForm();
    customerRegistrationForm.setCustomer(customer);
    return customerRegistrationForm;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm)

Example 4 with RegisterCustomerForm

use of org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm in project BroadleafCommerce by BroadleafCommerce.

the class RegisterCustomerController method initCustomerRegistrationForm.

@ModelAttribute("registerCustomerForm")
public RegisterCustomerForm initCustomerRegistrationForm() {
    RegisterCustomerForm customerRegistrationForm = new RegisterCustomerForm();
    Customer customer = customerService.createNewCustomer();
    customerRegistrationForm.setCustomer(customer);
    return customerRegistrationForm;
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) RegisterCustomerForm(org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)4 RegisterCustomerForm (org.broadleafcommerce.profile.web.core.form.RegisterCustomerForm)4 ChallengeQuestion (org.broadleafcommerce.profile.core.domain.ChallengeQuestion)1 ChallengeQuestionImpl (org.broadleafcommerce.profile.core.domain.ChallengeQuestionImpl)1 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)1 ModelAttribute (org.springframework.web.bind.annotation.ModelAttribute)1 DataProvider (org.testng.annotations.DataProvider)1