use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.
the class UserController method deleteToken.
/**
* @param authToken
* @param returnUrl
* @param request
* @return view name
*/
@RequestMapping(value = "deleteToken", method = RequestMethod.POST)
public String deleteToken(String authToken, String returnUrl, HttpServletRequest request) {
SysSite site = getSite(request);
if (CommonUtils.empty(returnUrl)) {
returnUrl = site.getDynamicPath();
}
sysUserTokenService.delete(authToken);
return REDIRECT + returnUrl;
}
use of com.publiccms.entities.sys.SysSite 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.SysSite 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;
}
}
use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.
the class LoginDirective method execute.
@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
String username = StringUtils.trim(handler.getString("username"));
String password = StringUtils.trim(handler.getString("password"));
boolean result = false;
if (CommonUtils.notEmpty(username) && CommonUtils.notEmpty(password)) {
SysSite site = getSite(handler);
if (AbstractController.verifyNotEMail(username)) {
user = service.findByName(site.getId(), username);
} else {
user = service.findByEmail(site.getId(), username);
}
String ip = RequestUtils.getIpAddress(handler.getRequest());
if (null != user && !user.isDisabled() && user.getPassword().equals(VerificationUtils.md5Encode(password))) {
String authToken = UUID.randomUUID().toString();
sysUserTokenService.save(new SysUserToken(authToken, site.getId(), user.getId(), app.getChannel(), CommonUtils.getDate(), ip));
service.updateLoginStatus(user.getId(), ip);
logLoginService.save(new LogLogin(site.getId(), username, user.getId(), ip, app.getChannel(), true, CommonUtils.getDate(), null));
user.setPassword(null);
result = true;
handler.put("authToken", authToken).put("user", user);
} else {
LogLogin log = new LogLogin();
log.setSiteId(site.getId());
log.setName(username);
log.setErrorPassword(password);
log.setIp(ip);
log.setChannel(app.getChannel());
logLoginService.save(log);
}
}
handler.put("result", result);
}
use of com.publiccms.entities.sys.SysSite in project PublicCMS-preview by sanluan.
the class LotteryDirective method execute.
@Override
public void execute(RenderHandler handler, SysApp app, SysUser user) throws IOException, Exception {
Long lotteryId = handler.getLong("lotteryId");
CmsLottery lottery = lotteryService.getEntity(lotteryId);
SysSite site = getSite(handler);
handler.put("result", "failure");
if (null != lottery && site.getId() == lottery.getSiteId() && !lottery.isDisabled()) {
if (lotteryUserService.getPage(lotteryId, user.getId(), true, null, null, null, null, null).getTotalCount() == 0) {
if (lottery.getLotteryCount() - lotteryUserService.getPage(lotteryId, user.getId(), null, null, null, null, null, null).getTotalCount() > 0) {
CmsLotteryUser entity = new CmsLotteryUser(lotteryId, user.getId(), false, false, RequestUtils.getIpAddress(handler.getRequest()), CommonUtils.getDate());
entity.setUserId(user.getId());
if (lottery.getFractions() > random.nextInt(lottery.getNumerator()) && lotteryService.updateLastGift(lotteryId) && lottery.getLotteryCount() > lotteryUserService.getPage(lotteryId, null, true, null, null, null, null, null).getTotalCount()) {
entity.setWinning(true);
}
lotteryUserService.save(entity);
handler.put("result", "success");
handler.put("winning", entity.isWinning());
}
}
}
}
Aggregations