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;
}
}
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;
}
}
Aggregations