Search in sources :

Example 76 with SysSite

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;
}
Also used : SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 77 with SysSite

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;
    }
}
Also used : SysEmailToken(com.publiccms.entities.sys.SysEmailToken) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with SysSite

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

Example 79 with SysSite

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);
}
Also used : SysUserToken(com.publiccms.entities.sys.SysUserToken) LogLogin(com.publiccms.entities.log.LogLogin) SysSite(com.publiccms.entities.sys.SysSite)

Example 80 with SysSite

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());
            }
        }
    }
}
Also used : CmsLotteryUser(com.publiccms.entities.cms.CmsLotteryUser) CmsLottery(com.publiccms.entities.cms.CmsLottery) SysSite(com.publiccms.entities.sys.SysSite)

Aggregations

SysSite (com.publiccms.entities.sys.SysSite)175 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)135 LogOperate (com.publiccms.entities.log.LogOperate)117 IOException (java.io.IOException)33 SysUser (com.publiccms.entities.sys.SysUser)21 LinkedHashMap (java.util.LinkedHashMap)19 TemplateException (freemarker.template.TemplateException)15 File (java.io.File)14 CmsContent (com.publiccms.entities.cms.CmsContent)12 CmsCategory (com.publiccms.entities.cms.CmsCategory)11 MultipartFile (org.springframework.web.multipart.MultipartFile)10 SysTask (com.publiccms.entities.sys.SysTask)9 HashMap (java.util.HashMap)8 LogUpload (com.publiccms.entities.log.LogUpload)7 SysDept (com.publiccms.entities.sys.SysDept)7 SysUserToken (com.publiccms.entities.sys.SysUserToken)7 CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)7 CmsPageMetadata (com.publiccms.views.pojo.entities.CmsPageMetadata)6 CmsPlace (com.publiccms.entities.cms.CmsPlace)5 SysDomain (com.publiccms.entities.sys.SysDomain)5