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);
}
}
}
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 } };
}
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;
}
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;
}
Aggregations