final String firstName = userPojo.getFirstName();
final String lastName = userPojo.getLastName();
final String gender = userPojo.getGender();
final String locale = userPojo.getLocale();
final String username = userPojo.getUsername();
Customer customer = customerService.getCustomerByLoginOrEmail(email);
if(customer == null){
// CREATE A NEW CUSTOMER
customer = new Customer();
customer = setCommonCustomerInformation(request, customer);
customer.setLogin(email);
customer.setPassword(securityUtil.generatePassword());
customer.setEmail(email);
customer.setFirstname(firstName);
customer.setLastname(lastName);
if(StringUtils.isNotEmpty(gender)){
customer.setGender(gender);
}
customer.setNetworkOrigin(CustomerNetworkOrigin.FACEBOOK);
CustomerAttribute attribute = new CustomerAttribute();
AttributeDefinition attributeDefinition = attributeService.getAttributeDefinitionByCode(CustomerAttribute.CUSTOMER_ATTRIBUTE_SCREENAME);
attribute.setAttributeDefinition(attributeDefinition);
String screenName = username;
if(StringUtils.isEmpty(screenName)){
if(StringUtils.isNotEmpty(lastName)){
if(StringUtils.isNotEmpty(lastName)){
screenName = lastName;
if(screenName.length() > 1){
screenName = screenName.substring(0, 1);
}
if(!screenName.endsWith(".")){
screenName = screenName + ". ";
}
}
}
screenName = screenName + firstName;
}
attribute.setShortStringValue(screenName);
customer.getAttributes().add(attribute);
if(StringUtils.isNotEmpty(locale)){
customer.setDefaultLocale(locale);
}
customerService.saveOrUpdateCustomer(customer);
}
// Redirect to the edit page
if(StringUtils.isNotEmpty(customer.getEmail())){
// Login the new customer
securityUtil.authenticationCustomer(request, customer);
// Update the customer session