public void updateUser(String username, AppUser userShell) { AppUser userEntity = getUserByUsername(username); String oldEmailAddress = userEntity.getEmailAddress(); String oldPassword = userEntity.getPassword(); copyProperties(userShell, userEntity); String newEmailAddress = userEntity.getEmailAddress(); String newPassword = userEntity.getPassword(); if (changed(oldPassword, newPassword)) { validatePassword(newPassword); hashPassword(userEntity); } validateEntity(userEntity); if (changed(oldEmailAddress, newEmailAddress)) { checkEmailAddressIsNotRegistered(newEmailAddress); updateCurrentPrincipal(userEntity, newEmailAddress); } userDao.merge(userEntity); }
private String getEmailValidationKey(AppUser user) { String randomString = RandomStringUtils.randomAlphanumeric(EMAIL_VALIDATION_KEY_LENGTH); String hashedUsername = DigestUtils.md2Hex(user.getEmailAddress()); return randomString + hashedUsername; }
private void copyProperties(AppUser userShell, AppUser userEntity) { userEntity.setFirstName(userShell.getFirstName()); userEntity.setLastName(userShell.getLastName()); userEntity.setEmailAddress(userShell.getEmailAddress()); if (passwordChanged(userShell)) { userEntity.setPassword(userShell.getPassword()); } }
public void createUser(AppUser user) { checkEmailAddressIsNotRegistered(user.getEmailAddress()); validatePassword(user.getPassword()); hashPassword(user); setUserProperties(user); validateEntity(user); userDao.persist(user); validationEmailSender.send(user); }