/** * Customized serialization of the fields {@link org.jtalks.common.model.entity.Entity#id}, * {@link org.jtalks.common.model.entity.Entity#uuid} * * Note: The {@link org.jtalks.common.model.entity.User#groups} is marked as transient and will not be serialized * (for more details pls. see at <a href="http://jira.jtalks.org/browse/POULPE-528">JIRA</a>). * * @serialData {@link org.jtalks.common.model.entity.Entity#id}, * {@link org.jtalks.common.model.entity.Entity#uuid}, * and the hole entities {@link org.jtalks.common.model.entity.User}, * {@link org.jtalks.jcommune.model.entity.JCUser} * expect for the transient fields {@link org.jtalks.common.model.entity.User#groups} and * {@link org.jtalks.jcommune.model.entity.JCUser#contacts} * @param s * @throws IOException */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeLong(getId()); s.writeObject(getUuid()); } }
/** * 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()); } }
/** * Activates user account with UUID-based URL * We use UUID's to be sure activation link cannot be generated from username * by script or any other tool. * * @param uuid unique entity identifier * @param request Servlet request. * @param response Servlet response. * @return redirect to the login page * @throws org.jtalks.jcommune.plugin.api.exceptions.UnexpectedErrorException * @throws org.jtalks.jcommune.plugin.api.exceptions.NoConnectionException */ @RequestMapping(value = "user/activate/{uuid}") public String activateAccount(@PathVariable String uuid, HttpServletRequest request, HttpServletResponse response) throws Exception { try { JCUser user = userService.getByUuid(uuid); authenticator.activateAccount(user.getUuid()); MutableHttpRequest wrappedRequest = new MutableHttpRequest(request); wrappedRequest.addParameter(AbstractRememberMeServices.DEFAULT_PARAMETER, "true"); LoginUserDto loginUserDto = new LoginUserDto(user.getUsername(), user.getPassword(), true, getClientIpAddress(request)); retryTemplate.execute(new LoginRetryCallback(loginUserDto, request, response, plainPasswordUserService)); return "redirect:/"; } catch (NotFoundException e) { return "errors/activationExpired"; } catch (UserTriesActivatingAccountAgainException e) { return "redirect:/"; } }
copy.setAvatarLastModificationTime(user.getAvatarLastModificationTime()); copy.setAllForumMarkedAsReadTime(user.getAllForumMarkedAsReadTime()); copy.setUuid(user.getUuid());