Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Robert Lalyko
Password Reset Mail - use other Email Address
23. Juni 2012 16:28
Antwort

Robert Lalyko

Rang: New Member

Nachrichten: 3

Eintrittsdatum: 8. Februar 2012

Neue 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
Jelmer Kuperus
RE: Password Reset Mail - use other Email Address
23. Juni 2012 18:31
Antwort

Jelmer Kuperus

Rang: Liferay Legend

Nachrichten: 1192

Eintrittsdatum: 10. März 2010

Neue Beiträge

Try getting the preferences like this

1PortletPreferences 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 :

1PrefsPropsUtil.getString(PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_BODY);
Robert Lalyko
RE: Password Reset Mail - use other Email Address
24. Juni 2012 03:06
Antwort

Robert Lalyko

Rang: New Member

Nachrichten: 3

Eintrittsdatum: 8. Februar 2012

Neue 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...

1
2String body = <READ FROM TEMPLATE???>
3String subject = <READ FROM TEMPLATE???>
4
5InternetAddress to = new InternetAddress( alternativeEmailAddress, user.getFirstName() + StringPool.SPACE + user.getLastName() );
6InternetAddress from = new InternetAddress( admin.getEmailAddress(), admin.getFirstName() + StringPool.SPACE + user.getLastName() );
7MailMessage message = new MailMessage( from, to,subject, body, true );
8MailServiceUtil.sendEmail( message );


Thanks and regards,
Robert
Jelmer Kuperus
RE: Password Reset Mail - use other Email Address
24. Juni 2012 07:10
Antwort

Jelmer Kuperus

Rang: Liferay Legend

Nachrichten: 1192

Eintrittsdatum: 10. März 2010

Neue 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
Robert Lalyko
RE: Password Reset Mail - use other Email Address
24. Juni 2012 10:26
Antwort

Robert Lalyko

Rang: New Member

Nachrichten: 3

Eintrittsdatum: 8. Februar 2012

Neue 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
Jelmer Kuperus
RE: Password Reset Mail - use other Email Address
24. Juni 2012 11:57
Antwort

Jelmer Kuperus

Rang: Liferay Legend

Nachrichten: 1192

Eintrittsdatum: 10. März 2010

Neue Beiträge

Something like this should do it :


 1ServiceContext serviceContext = ServiceContextFactory.getInstance(request);
 2
 3Ticket ticket = TicketLocalServiceUtil.addTicket(
 4    companyId, User.class.getName(), userId,
 5    TicketConstants.TYPE_PASSWORD, null, expirationDate,
 6    serviceContext);
 7
 8String passwordResetURL =
 9    serviceContext.getPortalURL() + serviceContext.getPathMain() +
10        "/portal/update_password?p_l_id="+
11            serviceContext.getPlid() +
12                "&ticketKey=" + ticket.getKey();