Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Robert Lalyko
Password Reset Mail - use other Email Address
23 de Junho de 2012 16:28
Resposta

Robert Lalyko

Ranking: New Member

Mensagens: 3

Data de entrada: 8 de Fevereiro de 2012

Mensagens recentes

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 de Junho de 2012 18:31
Resposta

Jelmer Kuperus

Ranking: Liferay Legend

Mensagens: 1192

Data de entrada: 10 de Março de 2010

Mensagens recentes

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 de Junho de 2012 03:06
Resposta

Robert Lalyko

Ranking: New Member

Mensagens: 3

Data de entrada: 8 de Fevereiro de 2012

Mensagens recentes

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 de Junho de 2012 07:10
Resposta

Jelmer Kuperus

Ranking: Liferay Legend

Mensagens: 1192

Data de entrada: 10 de Março de 2010

Mensagens recentes

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 de Junho de 2012 10:26
Resposta

Robert Lalyko

Ranking: New Member

Mensagens: 3

Data de entrada: 8 de Fevereiro de 2012

Mensagens recentes

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 de Junho de 2012 11:57
Resposta

Jelmer Kuperus

Ranking: Liferay Legend

Mensagens: 1192

Data de entrada: 10 de Março de 2010

Mensagens recentes

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();