use of com.liferay.portal.model.Ticket in project liferay-ide by liferay.
the class UserLocalServiceImpl method sendEmailAddressVerification.
/**
* Sends an email address verification to the user.
*
* @param user the verification email recipient
* @param emailAddress the recipient's email address
* @param serviceContext the service context to be applied. Must set the
* portal URL, main path, primary key of the layout, remote address,
* remote host, and agent for the user.
* @throws PortalException if a portal exception occurred
* @throws SystemException if a system exception occurred
*/
@Override
public void sendEmailAddressVerification(User user, String emailAddress, ServiceContext serviceContext) throws PortalException, SystemException {
if (user.isEmailAddressVerified() && StringUtil.equalsIgnoreCase(emailAddress, user.getEmailAddress())) {
return;
}
Ticket ticket = ticketLocalService.addTicket(user.getCompanyId(), User.class.getName(), user.getUserId(), TicketConstants.TYPE_EMAIL_ADDRESS, emailAddress, null, serviceContext);
String verifyEmailAddressURL = serviceContext.getPortalURL() + serviceContext.getPathMain() + "/portal/verify_email_address?ticketKey=" + ticket.getKey();
long plid = serviceContext.getPlid();
if (plid > 0) {
Layout layout = layoutLocalService.fetchLayout(plid);
if (layout != null) {
Group group = layout.getGroup();
if (!layout.isPrivateLayout() && !group.isUser()) {
verifyEmailAddressURL += "&p_l_id=" + serviceContext.getPlid();
}
}
}
String fromName = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
String fromAddress = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
String toName = user.getFullName();
String toAddress = emailAddress;
String subject = PrefsPropsUtil.getContent(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_VERIFICATION_SUBJECT);
String body = PrefsPropsUtil.getContent(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_VERIFICATION_BODY);
SubscriptionSender subscriptionSender = new SubscriptionSender();
subscriptionSender.setBody(body);
subscriptionSender.setCompanyId(user.getCompanyId());
subscriptionSender.setContextAttributes("[$EMAIL_VERIFICATION_CODE$]", ticket.getKey(), "[$EMAIL_VERIFICATION_URL$]", verifyEmailAddressURL, "[$REMOTE_ADDRESS$]", serviceContext.getRemoteAddr(), "[$REMOTE_HOST$]", serviceContext.getRemoteHost(), "[$USER_ID$]", user.getUserId(), "[$USER_SCREENNAME$]", user.getScreenName());
subscriptionSender.setFrom(fromAddress, fromName);
subscriptionSender.setHtmlFormat(true);
subscriptionSender.setMailId("user", user.getUserId(), System.currentTimeMillis(), PwdGenerator.getPassword());
subscriptionSender.setServiceContext(serviceContext);
subscriptionSender.setSubject(subject);
subscriptionSender.setUserId(user.getUserId());
subscriptionSender.addRuntimeSubscribers(toAddress, toName);
subscriptionSender.flushNotificationsAsync();
}
use of com.liferay.portal.model.Ticket in project liferay-ide by liferay.
the class UserLocalServiceImpl method sendPassword.
/**
* Sends the password email to the user with the email address. The content
* of this email can be specified in <code>portal.properties</code> with the
* <code>admin.email.password</code> keys.
*
* @param companyId the primary key of the user's company
* @param emailAddress the user's email address
* @param fromName the name of the individual that the email should be from
* @param fromAddress the address of the individual that the email should
* be from
* @param subject the email subject. If <code>null</code>, the subject
* specified in <code>portal.properties</code> will be used.
* @param body the email body. If <code>null</code>, the body specified in
* <code>portal.properties</code> will be used.
* @param serviceContext the service context to be applied
* @throws PortalException if a user with the email address could not be
* found
* @throws SystemException if a system exception occurred
*/
@Override
public void sendPassword(long companyId, String emailAddress, String fromName, String fromAddress, String subject, String body, ServiceContext serviceContext) throws PortalException, SystemException {
Company company = companyPersistence.findByPrimaryKey(companyId);
if (!company.isSendPassword() && !company.isSendPasswordResetLink()) {
return;
}
emailAddress = StringUtil.toLowerCase(emailAddress.trim());
if (Validator.isNull(emailAddress)) {
throw new UserEmailAddressException();
}
User user = userPersistence.findByC_EA(companyId, emailAddress);
PasswordPolicy passwordPolicy = user.getPasswordPolicy();
String newPassword = StringPool.BLANK;
String passwordResetURL = StringPool.BLANK;
if (company.isSendPasswordResetLink()) {
Date expirationDate = null;
if ((passwordPolicy != null) && (passwordPolicy.getResetTicketMaxAge() > 0)) {
expirationDate = new Date(System.currentTimeMillis() + (passwordPolicy.getResetTicketMaxAge() * 1000));
}
Ticket ticket = ticketLocalService.addTicket(companyId, User.class.getName(), user.getUserId(), TicketConstants.TYPE_PASSWORD, null, expirationDate, serviceContext);
passwordResetURL = serviceContext.getPortalURL() + serviceContext.getPathMain() + "/portal/update_password?p_l_id=" + serviceContext.getPlid() + "&ticketKey=" + ticket.getKey();
} else {
if (!PasswordEncryptorUtil.PASSWORDS_ENCRYPTION_ALGORITHM.equals(PasswordEncryptorUtil.TYPE_NONE)) {
if (LDAPSettingsUtil.isPasswordPolicyEnabled(user.getCompanyId())) {
if (_log.isWarnEnabled()) {
StringBundler sb = new StringBundler(5);
sb.append("When LDAP password policy is enabled, ");
sb.append("it is possible that portal generated ");
sb.append("passwords will not match the LDAP policy.");
sb.append("Using RegExpToolkit to generate new ");
sb.append("password.");
_log.warn(sb.toString());
}
RegExpToolkit regExpToolkit = new RegExpToolkit();
newPassword = regExpToolkit.generate(null);
} else {
newPassword = PwdToolkitUtil.generate(passwordPolicy);
}
boolean passwordReset = false;
if (passwordPolicy.getChangeable() && passwordPolicy.getChangeRequired()) {
passwordReset = true;
}
user.setPassword(PasswordEncryptorUtil.encrypt(newPassword));
user.setPasswordUnencrypted(newPassword);
user.setPasswordEncrypted(true);
user.setPasswordReset(passwordReset);
user.setPasswordModified(true);
user.setPasswordModifiedDate(new Date());
userPersistence.update(user);
user.setPasswordModified(false);
} else {
newPassword = user.getPassword();
}
}
if (Validator.isNull(fromName)) {
fromName = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME);
}
if (Validator.isNull(fromAddress)) {
fromAddress = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
}
String toName = user.getFullName();
String toAddress = user.getEmailAddress();
if (Validator.isNull(subject)) {
if (company.isSendPasswordResetLink()) {
subject = PrefsPropsUtil.getContent(companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_SUBJECT);
} else {
subject = PrefsPropsUtil.getContent(companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_SENT_SUBJECT);
}
}
if (Validator.isNull(body)) {
if (company.isSendPasswordResetLink()) {
body = PrefsPropsUtil.getContent(companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_BODY);
} else {
body = PrefsPropsUtil.getContent(companyId, PropsKeys.ADMIN_EMAIL_PASSWORD_SENT_BODY);
}
}
SubscriptionSender subscriptionSender = new SubscriptionSender();
subscriptionSender.setBody(body);
subscriptionSender.setCompanyId(companyId);
subscriptionSender.setContextAttributes("[$PASSWORD_RESET_URL$]", passwordResetURL, "[$REMOTE_ADDRESS$]", serviceContext.getRemoteAddr(), "[$REMOTE_HOST$]", serviceContext.getRemoteHost(), "[$USER_ID$]", user.getUserId(), "[$USER_PASSWORD$]", newPassword, "[$USER_SCREENNAME$]", user.getScreenName());
subscriptionSender.setFrom(fromAddress, fromName);
subscriptionSender.setHtmlFormat(true);
subscriptionSender.setMailId("user", user.getUserId(), System.currentTimeMillis(), PwdGenerator.getPassword());
subscriptionSender.setServiceContext(serviceContext);
subscriptionSender.setSubject(subject);
subscriptionSender.setUserId(user.getUserId());
subscriptionSender.addRuntimeSubscribers(toAddress, toName);
subscriptionSender.flushNotificationsAsync();
}
use of com.liferay.portal.model.Ticket in project liferay-ide by liferay.
the class UserLocalServiceImpl method verifyEmailAddress.
/**
* Verifies the email address of the ticket.
*
* @param ticketKey the ticket key
* @throws PortalException if a ticket matching the ticket key could not be
* found, if the ticket has expired, if the ticket is an email
* address ticket, or if the email address is invalid
* @throws SystemException if a system exception occurred
*/
@Override
public void verifyEmailAddress(String ticketKey) throws PortalException, SystemException {
Ticket ticket = ticketLocalService.getTicket(ticketKey);
if (ticket.isExpired() || (ticket.getType() != TicketConstants.TYPE_EMAIL_ADDRESS)) {
throw new NoSuchTicketException("{ticketKey=" + ticketKey + "}");
}
User user = userPersistence.findByPrimaryKey(ticket.getClassPK());
String emailAddress = ticket.getExtraInfo();
emailAddress = StringUtil.toLowerCase(emailAddress).trim();
if (!emailAddress.equals(user.getEmailAddress())) {
if (userPersistence.fetchByC_EA(user.getCompanyId(), emailAddress) != null) {
throw new DuplicateUserEmailAddressException("{userId=" + user.getUserId() + "}");
}
setEmailAddress(user, StringPool.BLANK, user.getFirstName(), user.getMiddleName(), user.getLastName(), emailAddress);
Contact contact = user.getContact();
contact.setEmailAddress(user.getEmailAddress());
contactPersistence.update(contact);
}
user.setEmailAddressVerified(true);
userPersistence.update(user);
ticketLocalService.deleteTicket(ticket);
}
Aggregations