Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JC-2173 Added email sending when password was changed #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,28 @@ public void sendPasswordRecoveryMail(JCUser user, String newPassword) throws Mai
LOGGER.info("Password recovery email sent for {}", name);
}

/**
* Sends a notification to user that his e-mail was changed.
*
* @param user a person we will send a mail
* @throws MailingFailedException when mailing failed
*/
public void sendPasswordUpdatedMail(final JCUser user) {
String name = user.getUsername();
Locale locale = user.getLanguage().getLocale();
Map<String, Object> model = new HashMap<>();
model.put(NAME, name);
model.put(RECIPIENT_LOCALE, locale);
try {
this.sendEmail(user.getEmail(),
messageSource.getMessage("passwordUpdatedNotification.subject", new Object[]{}, locale),
model, "passwordUpdatedNotification.vm");
LOGGER.info("Password updated email sent for {}", name);
} catch (MailingFailedException e) {
LOGGER.info("Password update for '{}' wasn't sent because {}", name, e.getMessage());
}
}

/**
* Sends update notification to user specified if
* {@link SubscriptionAwareEntity} was updated, e.g. when some new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public JCUser saveEditedUserSecurity(long editedUserId, UserSecurityContainer us
editedUser.setPassword(encryptedPassword);
}

mailService.sendPasswordUpdatedMail(editedUser);
this.getDao().saveOrUpdate(editedUser);
LOGGER.info("Updated user security settings. Username: {}", editedUser.getUsername());
return editedUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ passwordRecovery.subject=Password recovery
passwordRecovery.content.part1=This is a password recovery mail from JTalks forum.
passwordRecovery.content.part2=Your new password is:
passwordRecovery.link=Feel free to log in at
passwordUpdatedNotification.subject=Password updated
passwordUpdatedNotification.content=Your password has been successfully changed. If you didn't change it, please get into touch with the admin [email protected]
moveTopic.subject=Topic was moved
moveTopic.content=Topic was moved to another branch
moveTopic.by=by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ passwordRecovery.subject=Recuperaci\u00f3n de contrase\u00f1a
passwordRecovery.content.part1=Este es un e-mail de recuperaci\u00f3n de contrase\u00f1a del foro JTalks.
passwordRecovery.content.part2=Tu nueva contrase\u00f1a es:
passwordRecovery.link=Puedes acceder en:
passwordUpdatedNotification.subject=Recuperaci actualizado
passwordUpdatedNotification.content=Su contrase\u00F1a ha sido cambiada con \u00E9xito. Si no cambia, por favor p\u00F3ngase en contacto con el administrador [email protected]
moveTopic.subject=El tema ha sido eliminado
moveTopic.content=El tema ha sido movido a otra categor\u00eda
moveTopic.by=por
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ passwordRecovery.subject=\u0412\u043E\u0441\u0441\u0442\u0430\u043D\u043E\u0432\
passwordRecovery.content.part1=\u0417\u0430\u0431\u044B\u043B\u0438 \u043F\u0430\u0440\u043E\u043B\u044C \u043E\u0442 \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u0430 \u043D\u0430 JTalks? \u041D\u0435 \u0441\u0442\u0440\u0430\u0448\u043D\u043E, \u043C\u044B \u0441\u0433\u0435\u043D\u0435\u0440\u0438\u0440\u043E\u0432\u0430\u043B\u0438 \u043D\u043E\u0432\u044B\u0439.
passwordRecovery.content.part2=\u0412\u0430\u0448 \u043D\u043E\u0432\u044B\u0439 \u043F\u0430\u0440\u043E\u043B\u044C:
passwordRecovery.link=\u0410\u0432\u0442\u043E\u0440\u0438\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u043C\u043E\u0436\u043D\u043E \u0437\u0434\u0435\u0441\u044C
passwordUpdatedNotification.subject=\u041F\u0430\u0440\u043E\u043B\u044C \u043E\u0431\u043D\u043E\u0432\u043B\u0435\u043D
passwordUpdatedNotification.content=\u0412\u0430\u0448 \u043F\u0430\u0440\u043E\u043B\u044C \u0431\u044B\u043B \u0443\u0441\u043F\u0435\u0448\u043D\u043E \u0438\u0437\u043C\u0435\u043D\u0435\u043D. \u0415\u0441\u043B\u0438 \u0412\u044B \u043D\u0435 \u043C\u0435\u043D\u044F\u043B\u0438 \u0435\u0433\u043E, \u043F\u043E\u0436\u0430\u043B\u0443\u0439\u0441\u0442\u0430, \u0441\u0432\u044F\u0436\u0438\u0442\u0435\u0441\u044C \u0441 \u0430\u0434\u043C\u0438\u043D\u0438\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u043E\u043C [email protected]
moveTopic.subject=\u0422\u043E\u043F\u0438\u043A \u0431\u044B\u043B \u043F\u0435\u0440\u0435\u043D\u0435\u0441\u0435\u043D
moveTopic.content=\u0422\u043E\u043F\u0438\u043A \u0431\u044B\u043B \u043F\u0435\u0440\u0435\u043D\u0435\u0441\u0435\u043D \u0432 \u0434\u0440\u0443\u0433\u0443\u044E \u0432\u0435\u0442\u043A\u0443
moveTopic.by=\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u0435\u043B\u0435\u043C
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ passwordRecovery.subject=\u0412\u0456\u0434\u043D\u043E\u0432\u043B\u0435\u043D\
passwordRecovery.content.part1=\u0426\u0435 \u043B\u0438\u0441\u0442 \u0434\u043B\u044F \u0432\u0456\u0434\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u044F \u043F\u0430\u0440\u043E\u043B\u044E \u043D\u0430 \u0444\u043E\u0440\u0443\u043C\u0456 JTalks.
passwordRecovery.content.part2=\u0412\u0430\u0448 \u043D\u043E\u0432\u0438\u0439 \u043F\u0430\u0440\u043E\u043B\u044C:
passwordRecovery.link=\u0410\u0432\u0442\u043E\u0440\u0438\u0437\u0443\u0432\u0430\u0442\u0438\u0441\u044C \u043C\u043E\u0436\u043D\u0430 \u0442\u0443\u0442
passwordUpdatedNotification.subject=\u041F\u0430\u0440\u043E\u043B\u044C \u043E\u043D\u043E\u0432\u043B\u0435\u043D\u043E
passwordUpdatedNotification.content=\u0412\u0430\u0448 \u043F\u0430\u0440\u043E\u043B\u044C \u0431\u0443\u043B\u043E \u0443\u043F\u0456\u0448\u043D\u043E \u0437\u043C\u0456\u043D\u0435\u043D\u043E. \u042F\u043A\u0449\u043E \u0412\u0438 \u043D\u0435 \u0437\u043C\u0456\u043D\u044E\u0432\u0430\u043B\u0438 \u0439\u043E\u0433\u043E, \u0431\u0443\u0434\u044C \u043B\u0430\u0441\u043A\u0430 \u0437\u0432\u2019\u044F\u0436\u0456\u0442\u044C\u0441\u044F \u0437 \u0430\u0434\u043C\u0456\u043D\u0456\u0441\u0442\u0440\u0430\u0442\u043E\u0440\u043E\u043C [email protected]
moveTopic.subject=\u0422\u0435\u043C\u0430 \u0431\u0443\u043B\u0430 \u043F\u0435\u0440\u0435\u043C\u0456\u0449\u0435\u043D\u0430
moveTopic.content=\u0422\u0435\u043C\u0430 \u0431\u0443\u043B\u0430 \u043F\u0435\u0440\u0435\u043C\u0456\u0449\u0435\u043D\u0430 \u0434\u043E \u0456\u043D\u0448\u043E\u0457 \u0433\u0456\u043B\u043A\u0438
moveTopic.by=\u043A\u043E\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0435\u043C
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#*

Copyright (C) 2011 JTalks.org Team
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*#
<p>${messageSource.getMessage("greeting", $noArgs, $locale)} ${escape.html($name)}!</p>
<br/>
<p>${messageSource.getMessage("passwordUpdatedNotification.content", $noArgs, $locale)}</p>
<br/>
<p>${messageSource.getMessage("wish", $noArgs, $locale)}</p>
<p>${messageSource.getMessage("signature", $noArgs, $locale)}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#*

Copyright (C) 2011 JTalks.org Team
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*#
${messageSource.getMessage("greeting", $noArgs, $locale)} ${name}!

${messageSource.getMessage("passwordUpdatedNotification.content", $noArgs, $locale)}

${messageSource.getMessage("wish", $noArgs, $locale)}
${messageSource.getMessage("signature", $noArgs, $locale)}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ public void passwordRecoveryMailShouldNotBeSentIfNotificationsAreDisabled() thro
verify(sender, never()).send(any(MimeMessage.class));
}

@Test
public void testSendPasswordUpdatedMail() throws Exception {
enableEmailNotifications();
service.sendPasswordUpdatedMail(user);

this.checkMailCredentials();
assertTrue(this.getMimeMailBody().contains(USERNAME));
}

@Test
public void testSendPasswordUpdatedMailWhenNotificationsAreDisabled() throws Exception {
disableEmailNotifications();
service.sendPasswordUpdatedMail(user);
verify(sender, never()).send(any(MimeMessage.class));
}

@Test
public void testSendTopicUpdatesEmail() throws Exception {
enableEmailNotifications();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
import org.jtalks.jcommune.model.entity.JCUser;
import org.jtalks.jcommune.model.entity.Language;
import org.jtalks.jcommune.model.entity.Post;
import org.jtalks.jcommune.plugin.api.exceptions.NotFoundException;
import org.jtalks.jcommune.plugin.api.web.util.BreadcrumbBuilder;
import org.jtalks.jcommune.service.PostService;
import org.jtalks.jcommune.service.UserContactsService;
import org.jtalks.jcommune.service.UserService;
import org.jtalks.jcommune.plugin.api.exceptions.NotFoundException;
import org.jtalks.jcommune.service.dto.EntityToDtoConverter;
import org.jtalks.jcommune.service.nontransactional.ImageConverter;
import org.jtalks.jcommune.service.nontransactional.ImageService;
import org.jtalks.jcommune.web.dto.*;
import org.jtalks.jcommune.plugin.api.web.util.BreadcrumbBuilder;
import org.jtalks.jcommune.web.dto.EditUserProfileDto;
import org.jtalks.jcommune.web.dto.UserContactsDto;
import org.jtalks.jcommune.web.dto.UserNotificationsDto;
import org.jtalks.jcommune.web.dto.UserProfileDto;
import org.jtalks.jcommune.web.dto.UserSecurityDto;
import org.jtalks.jcommune.web.validation.editors.DefaultAvatarEditor;
import org.jtalks.jcommune.web.validation.editors.DefaultStringEditor;
import org.jtalks.jcommune.web.validation.editors.PageSizeEditor;
Expand All @@ -41,7 +45,12 @@
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
Expand Down