Foren

Password Reset Mail - use other Email Address

thumbnail
Robert Lalyko, geändert vor 11 Jahren.

Password Reset Mail - use other Email Address

New Member Beiträge: 4 Beitrittsdatum: 08.02.12 Neueste Beiträge
Hi all,
i'm stuck on the following Problem:
i need to send the Email with the Password Reset Link to an Mail Address of the user, which is stored in an Expando Attribute. Mail sending to arbitrary addresses can be done with the MailServiceUtil, so far so good. I use this in a custom BaseStrutsPortletAction as a Hook.
But i need the Mail Body with the actual link to reset your Password, and this is the Problem. I had a look in the forgotPasswordAction and there the body is retrieved via PortletPreferences. If i do this in my custom BaseStrutsPortletAction i get null. Has anyone an idea how to get the Mail Content? Maybe by using another Util-Class?
Many thanks and regards,
Robert
thumbnail
jelmer kuperus, geändert vor 11 Jahren.

RE: Password Reset Mail - use other Email Address

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
Try getting the preferences like this

PortletPreferences preferences =  PortletPreferencesFactoryUtil.getPortletSetup(request, PortletKeys.LOGIN);


Btw the behaviour of UserLocalService.sendPassword is such that if the preference is null the body is loaded from portal properties. So if its unset you must do this :

PrefsPropsUtil.getString(PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_BODY);
thumbnail
Robert Lalyko, geändert vor 11 Jahren.

RE: Password Reset Mail - use other Email Address

New Member Beiträge: 4 Beitrittsdatum: 08.02.12 Neueste Beiträge
Hi Jelmer,
at first thanks for your answer. I tried the way you posted to get the PortletPreferences, but they are still null emoticon.
The second snippet you've posted leads to "com/liferay/portlet/admin/dependencies/email_password_reset_body.tmpl", i guess that's the template Name. But how can i now get the Template content and fill it with the right params (reset link etc.)?
For sending email i use the MailServiceUtil, where i just can pass a body as plain String, so the message body has to be constructed before. I want to use the default Email Reset Notification Message...


String body = <read from template???>
String subject = <read from template???>

InternetAddress to = new InternetAddress( alternativeEmailAddress, user.getFirstName() + StringPool.SPACE + user.getLastName() );
InternetAddress from = new InternetAddress( admin.getEmailAddress(), admin.getFirstName() + StringPool.SPACE + user.getLastName() );
MailMessage message = new MailMessage( from, to,subject, body, true );
MailServiceUtil.sendEmail( message );
</read></read>


Thanks and regards,
Robert
thumbnail
jelmer kuperus, geändert vor 11 Jahren.

RE: Password Reset Mail - use other Email Address

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
Ah.. Meh

Take a look at what i do in the code of this post http://www.liferay.com/community/forums/-/message_boards/message/6436989 then
thumbnail
Robert Lalyko, geändert vor 11 Jahren.

RE: Password Reset Mail - use other Email Address

New Member Beiträge: 4 Beitrittsdatum: 08.02.12 Neueste Beiträge
Hi Jelmer,
thanks for your post. I'm now able to get the Forgot Email Template and i want to fill it like you posted through String replace. The only thing i'm now missing is the generated reset link. Is there a service that generates this link or where can i get it from? I searched a lot with google but found nothing...
Many thanks and regards,
Robert
thumbnail
jelmer kuperus, geändert vor 11 Jahren.

RE: Password Reset Mail - use other Email Address

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
Something like this should do it :


ServiceContext serviceContext = ServiceContextFactory.getInstance(request);

Ticket ticket = TicketLocalServiceUtil.addTicket(
	companyId, User.class.getName(), userId,
	TicketConstants.TYPE_PASSWORD, null, expirationDate,
	serviceContext);

String passwordResetURL =
	serviceContext.getPortalURL() + serviceContext.getPathMain() +
		"/portal/update_password?p_l_id="+
			serviceContext.getPlid() +
				"&amp;ticketKey=" + ticket.getKey();