use of com.liferay.portal.model.Contact in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateIncompleteUser.
/**
* Updates a user account that was automatically created when a guest user
* participated in an action (e.g. posting a comment) and only provided his
* name and email address.
*
* @param creatorUserId the primary key of the creator
* @param companyId the primary key of the user's company
* @param autoPassword whether a password should be automatically generated
* for the user
* @param password1 the user's password
* @param password2 the user's password confirmation
* @param autoScreenName whether a screen name should be automatically
* generated for the user
* @param screenName the user's screen name
* @param emailAddress the user's email address
* @param facebookId the user's facebook ID
* @param openId the user's OpenID
* @param locale the user's locale
* @param firstName the user's first name
* @param middleName the user's middle name
* @param lastName the user's last name
* @param prefixId the user's name prefix ID
* @param suffixId the user's name suffix ID
* @param male whether the user is male
* @param birthdayMonth the user's birthday month (0-based, meaning 0 for
* January)
* @param birthdayDay the user's birthday day
* @param birthdayYear the user's birthday year
* @param jobTitle the user's job title
* @param updateUserInformation whether to update the user's information
* @param sendEmail whether to send the user an email notification about
* their new account
* @param serviceContext the service context to be applied (optionally
* <code>null</code>). Can set expando bridge attributes for the
* user.
* @return the user
* @throws PortalException if the user's information was invalid
* @throws SystemException if a system exception occurred
*/
@Override
public User updateIncompleteUser(long creatorUserId, long companyId, boolean autoPassword, String password1, String password2, boolean autoScreenName, String screenName, String emailAddress, long facebookId, String openId, Locale locale, String firstName, String middleName, String lastName, int prefixId, int suffixId, boolean male, int birthdayMonth, int birthdayDay, int birthdayYear, String jobTitle, boolean updateUserInformation, boolean sendEmail, ServiceContext serviceContext) throws PortalException, SystemException {
User user = getUserByEmailAddress(companyId, emailAddress);
if (user.getStatus() != WorkflowConstants.STATUS_INCOMPLETE) {
throw new PortalException("Invalid user status");
}
User defaultUser = getDefaultUser(companyId);
if (facebookId > 0) {
autoPassword = false;
if ((password1 == null) || (password2 == null)) {
password1 = PwdGenerator.getPassword();
password2 = password1;
}
sendEmail = false;
}
if (updateUserInformation) {
autoScreenName = false;
if (PrefsPropsUtil.getBoolean(companyId, PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE)) {
autoScreenName = true;
}
validate(companyId, user.getUserId(), autoPassword, password1, password2, autoScreenName, screenName, emailAddress, openId, firstName, middleName, lastName, null);
if (!autoPassword) {
if (Validator.isNull(password1) || Validator.isNull(password2)) {
throw new UserPasswordException(UserPasswordException.PASSWORD_INVALID);
}
}
if (autoScreenName) {
ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();
try {
screenName = screenNameGenerator.generate(companyId, user.getUserId(), emailAddress);
} catch (Exception e) {
throw new SystemException(e);
}
}
FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();
String fullName = fullNameGenerator.getFullName(firstName, middleName, lastName);
String greeting = LanguageUtil.format(locale, "welcome-x", " " + fullName, false);
if (Validator.isNotNull(password1)) {
user.setPassword(PasswordEncryptorUtil.encrypt(password1));
user.setPasswordUnencrypted(password1);
}
user.setPasswordEncrypted(true);
PasswordPolicy passwordPolicy = defaultUser.getPasswordPolicy();
if ((passwordPolicy != null) && passwordPolicy.isChangeable() && passwordPolicy.isChangeRequired()) {
user.setPasswordReset(true);
} else {
user.setPasswordReset(false);
}
user.setScreenName(screenName);
user.setFacebookId(facebookId);
user.setOpenId(openId);
user.setLanguageId(locale.toString());
user.setTimeZoneId(defaultUser.getTimeZoneId());
user.setGreeting(greeting);
user.setFirstName(firstName);
user.setMiddleName(middleName);
user.setLastName(lastName);
user.setJobTitle(jobTitle);
user.setExpandoBridgeAttributes(serviceContext);
Date birthday = getBirthday(birthdayMonth, birthdayDay, birthdayYear);
Contact contact = user.getContact();
contact.setFirstName(firstName);
contact.setMiddleName(middleName);
contact.setLastName(lastName);
contact.setPrefixId(prefixId);
contact.setSuffixId(suffixId);
contact.setMale(male);
contact.setBirthday(birthday);
contact.setJobTitle(jobTitle);
contactPersistence.update(contact, serviceContext);
// Indexer
Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(User.class);
indexer.reindex(user);
}
user.setStatus(WorkflowConstants.STATUS_DRAFT);
userPersistence.update(user, serviceContext);
// Workflow
long workflowUserId = creatorUserId;
if (workflowUserId == user.getUserId()) {
workflowUserId = defaultUser.getUserId();
}
ServiceContext workflowServiceContext = serviceContext;
if (workflowServiceContext == null) {
workflowServiceContext = new ServiceContext();
}
workflowServiceContext.setAttribute("autoPassword", autoPassword);
workflowServiceContext.setAttribute("passwordUnencrypted", password1);
workflowServiceContext.setAttribute("sendEmail", sendEmail);
WorkflowHandlerRegistryUtil.startWorkflowInstance(companyId, workflowUserId, User.class.getName(), user.getUserId(), user, workflowServiceContext);
return getUserByEmailAddress(companyId, emailAddress);
}
use of com.liferay.portal.model.Contact in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateEmailAddress.
/**
* Updates the user's email address.
*
* @param userId the primary key of the user
* @param password the user's password
* @param emailAddress1 the user's new email address
* @param emailAddress2 the user's new email address confirmation
* @return the user
* @throws PortalException if a user with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public User updateEmailAddress(long userId, String password, String emailAddress1, String emailAddress2) throws PortalException, SystemException {
emailAddress1 = StringUtil.toLowerCase(emailAddress1.trim());
emailAddress2 = StringUtil.toLowerCase(emailAddress2.trim());
User user = userPersistence.findByPrimaryKey(userId);
validateEmailAddress(user, emailAddress1, emailAddress2);
setEmailAddress(user, password, user.getFirstName(), user.getMiddleName(), user.getLastName(), emailAddress1);
userPersistence.update(user);
Contact contact = user.getContact();
contact.setEmailAddress(user.getEmailAddress());
contactPersistence.update(contact);
return user;
}
use of com.liferay.portal.model.Contact in project liferay-ide by liferay.
the class UserLocalServiceImpl method updateJobTitle.
/**
* Updates the user's job title.
*
* @param userId the primary key of the user
* @param jobTitle the user's job title
* @return the user
* @throws PortalException if a user with the primary key could not be found
* or if a contact could not be found matching the user's contact ID
* @throws SystemException if a system exception occurred
*/
@Override
public User updateJobTitle(long userId, String jobTitle) throws PortalException, SystemException {
User user = userPersistence.findByPrimaryKey(userId);
user.setJobTitle(jobTitle);
userPersistence.update(user);
Contact contact = contactPersistence.findByPrimaryKey(user.getContactId());
contact.setJobTitle(jobTitle);
contactPersistence.update(contact);
return user;
}
Aggregations