//create account/
final Account account = this.createDefaultAccount();
//create directory account.
createDirectoryAccount(account);
//create first user account.
final UserAccount userAccount = new UserAccount();
userAccount.setUsername(singUpBean.getUsername());
//generate password.
final String password = singUpBean.getPassword() == null ? EnMePasswordUtils
.createRandomPassword(EnMePasswordUtils.DEFAULT_LENGTH_PASSWORD)
: singUpBean.getPassword();
userAccount.setPassword(encodingPassword(password));
singUpBean.setPassword(password);
//invite code
final String inviteCode = UUID.randomUUID().toString();
userAccount.setEnjoyDate(Calendar.getInstance().getTime()); //current date
userAccount.setAccount(account);
userAccount.setUserStatus(Boolean.TRUE);
userAccount.setSharedProfile(Boolean.TRUE);
userAccount.setUserEmail(singUpBean.getEmail());
userAccount.setCompleteName(singUpBean.getFullName());
userAccount.setInviteCode(inviteCode); //thinking, maybe create invite code table.
getAccountDao().saveOrUpdate(userAccount);
//create global account directory
if (log.isDebugEnabled()) {
log.debug("singupUser created user account");
}
//default permissions.
final Set<Permission> permissions = new HashSet<Permission>();
permissions.add(getPermissionByName(EnMePermission.ENCUESTAME_USER));
permissions.add(getPermissionByName(EnMePermission.ENCUESTAME_OWNER));
permissions.add(getPermissionByName(EnMePermission.ENCUESTAME_PUBLISHER));
permissions.add(getPermissionByName(EnMePermission.ENCUESTAME_EDITOR));
this.assingPermission(userAccount, permissions);
if (!disableEmail) { //test proposes.
//send new password
if (EnMePlaceHolderConfigurer.getBooleanProperty("application.email.enabled")) {
//send confirmation account request
try {
getMailService().sendConfirmYourAccountEmail(singUpBean, inviteCode);
} catch (Exception e) {
// ENCUESTAME-602 ????
e.printStackTrace();
}
}
}
if (log.isDebugEnabled()) {
log.debug("new user "+userAccount.getUsername());
log.debug("Get Authoritie Name:{ "+SecurityContextHolder.getContext().getAuthentication().getName());
}
// create a welcome notification
createNotification(NotificationEnum.WELCOME_SIGNUP,