Search in sources :

Example 1 with SysEmailToken

use of com.publiccms.entities.sys.SysEmailToken in project PublicCMS-preview by sanluan.

the class UserController method verifyEmail.

/**
 * @param authToken
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "verifyEmail", method = RequestMethod.POST)
public String verifyEmail(String authToken, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    SysEmailToken sysEmailToken = sysEmailTokenService.getEntity(authToken);
    if (ControllerUtils.verifyNotEmpty("verifyEmail.authToken", authToken, model) || ControllerUtils.verifyNotExist("verifyEmail.sysEmailToken", sysEmailToken, model)) {
        return REDIRECT + returnUrl;
    } else {
        sysEmailTokenService.delete(sysEmailToken.getAuthToken());
        service.checked(sysEmailToken.getUserId(), sysEmailToken.getEmail());
        clearUserTimeToSession(session);
        model.addAttribute(MESSAGE, "verifyEmail.success");
        return REDIRECT + returnUrl;
    }
}
Also used : SysEmailToken(com.publiccms.entities.sys.SysEmailToken) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with SysEmailToken

use of com.publiccms.entities.sys.SysEmailToken in project PublicCMS-preview by sanluan.

the class UserController method saveEmail.

/**
 * @param email
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "saveEmail", method = RequestMethod.POST)
public String saveEmail(String email, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    Map<String, String> config = configComponent.getConfigData(site.getId(), EmailComponent.CONFIG_CODE);
    String emailTitle = config.get(EmailTemplateConfigComponent.CONFIG_EMAIL_TITLE);
    String emailPath = config.get(EmailTemplateConfigComponent.CONFIG_EMAIL_PATH);
    SysUser user = getUserFromSession(session);
    if (ControllerUtils.verifyNotEmpty("user", user, model) || ControllerUtils.verifyNotEmpty("email", email, model) || ControllerUtils.verifyNotEmpty("email.config", emailTitle, model) || ControllerUtils.verifyNotEmpty("email.config", emailPath, model) || verifyNotEMail("email", email, model) || ControllerUtils.verifyHasExist("email", service.findByEmail(site.getId(), email), model)) {
        return REDIRECT + returnUrl;
    } else {
        SysEmailToken sysEmailToken = new SysEmailToken();
        sysEmailToken.setUserId(user.getId());
        sysEmailToken.setAuthToken(UUID.randomUUID().toString());
        sysEmailToken.setEmail(email);
        sysEmailTokenService.save(sysEmailToken);
        try {
            Map<String, Object> emailModel = new HashMap<>();
            emailModel.put("user", user);
            emailModel.put("site", site);
            emailModel.put("email", email);
            emailModel.put("authToken", sysEmailToken.getAuthToken());
            if (emailComponent.sendHtml(site.getId(), email, FreeMarkerUtils.generateStringByString(emailTitle, templateComponent.getWebConfiguration(), emailModel), FreeMarkerUtils.generateStringByFile(siteComponent.getWebTemplateFilePath(site, emailPath), templateComponent.getWebConfiguration(), emailModel))) {
                model.addAttribute(MESSAGE, "sendEmail.success");
            } else {
                model.addAttribute(MESSAGE, "sendEmail.error");
            }
        } catch (IOException | TemplateException | MessagingException e) {
            model.addAttribute(ERROR, "sendEmail.error");
        }
        return REDIRECT + returnUrl;
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) MessagingException(javax.mail.MessagingException) SysEmailToken(com.publiccms.entities.sys.SysEmailToken) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysEmailToken (com.publiccms.entities.sys.SysEmailToken)2 SysSite (com.publiccms.entities.sys.SysSite)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 SysUser (com.publiccms.entities.sys.SysUser)1 TemplateException (freemarker.template.TemplateException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 MessagingException (javax.mail.MessagingException)1