protected void checkCustomer(Customer customer, GenericResponse response) { if (customer == null) { response.addErrorCode("invalidCustomer"); } else if (StringUtils.isBlank(customer.getEmailAddress())) { response.addErrorCode("emailNotFound"); } else if (customer.isDeactivated()) { response.addErrorCode("inactiveUser"); } }
@Override @Transactional(TransactionUtils.DEFAULT_TRANSACTION_MANAGER) public GenericResponse sendForgotUsernameNotification(String emailAddress) { GenericResponse response = new GenericResponse(); List<Customer> customers = null; if (emailAddress != null) { customers = customerDao.readCustomersByEmail(emailAddress); } if (CollectionUtils.isEmpty(customers)) { response.addErrorCode("notFound"); } else { List<String> activeUsernames = new ArrayList<String>(); for (Customer customer : customers) { if (!customer.isDeactivated()) { activeUsernames.add(customer.getUsername()); } } if (activeUsernames.size() > 0) { HashMap<String, Object> vars = new HashMap<String, Object>(); vars.put("userNames", activeUsernames); sendEmail(emailAddress, getForgotUsernameEmailInfo(), vars); } else { // send inactive username found email. response.addErrorCode("inactiveUser"); } } return response; }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { Customer customer = customerService.readCustomerByUsername(username, false); if (customer == null) { throw new UsernameNotFoundException("The customer was not found"); } boolean isActive = !customer.isDeactivated(); if (Status.class.isAssignableFrom(customer.getClass())) { isActive = isActive && ((Status) customer).isActive(); } List<GrantedAuthority> grantedAuthorities = createGrantedAuthorities(roleService.findCustomerRolesByCustomerId(customer.getId())); return new CustomerUserDetails(customer.getId(), username, customer.getPassword(), isActive, true, !customer.isPasswordChangeRequired(), true, grantedAuthorities); }
public UserDetails createCustomerUserDetails(Customer customer) { List<GrantedAuthority> grantedAuthorities = createGrantedAuthorities(roleService.findCustomerRolesByCustomerId(customer.getId())); CustomerUserDetails userDetails = new CustomerUserDetails(customer.getId(), customer.getUsername(), customer.getPassword(), !customer.isDeactivated(), true, !customer.isPasswordChangeRequired(), true, grantedAuthorities); userDetails.eraseCredentials(); return userDetails; }