/** * Get email of user by user's id. * * @param userId user's id * @return an email of user by user's id */ private String getEmailOfUser(long userId) { try { JCUser user = userService.get(userId); return user.getEmail(); } catch (NotFoundException e) { return null; } } }
/** * Sends email on forum updates. * * @param recipient a person to be notified about updates by email * @param model template params to be substituted in velocity template * @param locale recipient locale * @throws MailingFailedException when mailing failed */ private void sendEmailOnForumUpdates(JCUser recipient, Map<String, Object> model, Locale locale, Entity entity, String subject, String nameTemplate) throws MailingFailedException { model.put(USER, recipient); model.put(RECIPIENT_LOCALE, locale); String titleEntity = this.getTitleName(entity); this.sendEmail(recipient.getEmail(), messageSource.getMessage(subject, new Object[]{}, locale) + titleEntity, model, nameTemplate); }
/** * Sends a password recovery message for the user. * This method does not generate new password, just sends a message. * * @param user a person we will send a mail * @param newPassword new user password to be placed in an email * @throws MailingFailedException when mailing failed */ public void sendPasswordRecoveryMail(JCUser user, String newPassword) throws MailingFailedException { String urlSuffix = "/login"; String url = this.getDeploymentRootUrl() + urlSuffix; String name = user.getUsername(); Locale locale = user.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(NAME, name); model.put("newPassword", newPassword); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); this.sendEmail(user.getEmail(), messageSource.getMessage("passwordRecovery.subject", new Object[]{}, locale), model, "passwordRecovery.vm"); LOGGER.info("Password recovery email sent for {}", name); }
/** * Send email notification to user when he was mentioned in forum. * Email notification will be sent only when notifications are enabled * in forum, otherwise nothing will happen. * * @param recipient mentioned user who will receive notification * @param postId id of post where user was mentioned */ public void sendUserMentionedNotification(JCUser recipient, long postId) { String urlSuffix = "/posts/" + postId; String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(NAME, recipient.getUsername()); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); try { this.sendEmail(recipient.getEmail(), messageSource.getMessage("userMentioning.subject", new Object[]{}, locale), model, "userMentioning.vm"); } catch (MailingFailedException e) { LOGGER.error("Failed to sent activation mail for user: " + recipient.getUsername()); } }
/** * Sends notification to user about received private message. * * @param recipient a person to be notified about received private message by email * @param pm private message itself */ public void sendReceivedPrivateMessageNotification(JCUser recipient, PrivateMessage pm) { try { String urlSuffix = "/pm/inbox/" + pm.getId(); String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put("recipient", recipient); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); this.sendEmail(recipient.getEmail(), messageSource.getMessage("receivedPrivateMessageNotification.subject", new Object[]{}, locale), model, "receivedPrivateMessageNotification.vm"); } catch (MailingFailedException e) { LOGGER.error(String.format(LOG_TEMPLATE, "Private message", pm.getId(), recipient.getUsername())); } }
/** * Sends email with a hyperlink to activate user account. * * @param recipient user to send activation mail to */ public void sendAccountActivationMail(JCUser recipient) { try { String urlSuffix = "/user/activate/" + recipient.getUuid(); String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(NAME, recipient.getUsername()); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); this.sendEmail(recipient.getEmail(), messageSource.getMessage("accountActivation.subject", new Object[]{}, locale), model, "accountActivation.vm"); } catch (MailingFailedException e) { LOGGER.error("Failed to sent activation mail for user: " + recipient.getUsername()); } }
/** * Set mail about removing topic. * * @param recipient Recipient for which send notification * @param topic Current topic * @param curUser User that removed the topic */ public void sendRemovingTopicMail(JCUser recipient, Topic topic, String curUser) { Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(USER, recipient); model.put(RECIPIENT_LOCALE, locale); model.put(CUR_USER, curUser); //Topic not exist more and user not subscribed to branch, so simply redirect to branch model.put(LINK_UNSUBSCRIBE, this.getDeploymentRootUrl() + "/branches/" + topic.getBranch().getId()); model.put(TOPIC, topic); try { String subjectTemplate = REMOVE_TOPIC_SUBJECT_TEMPLATE; String messageBodyTemplate = REMOVE_TOPIC_MESSAGE_BODY_TEMPLATE; if (topic.isCodeReview()) { subjectTemplate = REMOVE_CODE_REVIEW_SUBJECT_TEMPLATE; messageBodyTemplate = REMOVE_CODE_REVIEW_MESSAGE_BODY_TEMPLATE; } String subject = messageSource.getMessage(subjectTemplate, new Object[]{}, locale); this.sendEmail(recipient.getEmail(), subject, model, messageBodyTemplate); } catch (MailingFailedException e) { LOGGER.error("Failed to sent mail about removing topic or code review for user: " + recipient.getUsername()); } }
/** * Sends email to topic starter that his or her topic was moved * * @param recipient user to send notification * @param topic relocated topic * @param curUser User that moved topic */ public <T extends SubscriptionAwareEntity> void sendTopicMovedMail( JCUser recipient, Topic topic, String curUser, Class<T> subsсriptionTargetClass) { String urlSuffix = getTopicUrlSuffix(topic); String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(NAME, recipient.getUsername()); model.put(CUR_USER, curUser); model.put(LINK, url); model.put(LINK_UNSUBSCRIBE, this.getDeploymentRootUrl() + topic.getUnsubscribeLinkForSubscribersOf(subsсriptionTargetClass)); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); try { this.sendEmail(recipient.getEmail(), messageSource.getMessage("moveTopic.subject", new Object[]{}, locale), model, "moveTopic.vm"); } catch (MailingFailedException e) { LOGGER.error("Failed to sent activation mail for user: " + recipient.getUsername()); } }
/** * Constructor which fills dto fields from user. * * @param user copying source */ public UserProfileDto(JCUser user) { this.userId = user.getId(); this.firstName = user.getFirstName(); this.lastName = user.getLastName(); this.email = user.getEmail(); this.signature = user.getSignature(); this.pageSize = user.getPageSize(); this.location = user.getLocation(); this.postCount = user.getPostCount(); this.registrationDate = user.getRegistrationDate(); this.lastLogin = user.getLastLogin(); }
throw new IllegalArgumentException("User should not be null"); JCUser copy = new JCUser(user.getUsername(), user.getEmail(), user.getPassword()); copy.setId(user.getId()); copy.setFirstName(user.getFirstName());