Search in sources :

Example 16 with SysUser

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

the class LoginController method login.

/**
 * @param username
 * @param password
 * @param returnUrl
 * @param request
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "doLogin", method = RequestMethod.POST)
public String login(String username, String password, String returnUrl, HttpServletRequest request, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    Map<String, String> config = configComponent.getConfigData(site.getId(), Config.CONFIG_CODE_SITE);
    String loginPath = config.get(LoginConfigComponent.CONFIG_LOGIN_PATH);
    if (CommonUtils.empty(loginPath)) {
        loginPath = site.getDynamicPath();
    }
    username = StringUtils.trim(username);
    password = StringUtils.trim(password);
    if (ControllerUtils.verifyNotEmpty("username", username, model) || ControllerUtils.verifyNotEmpty("password", password, model)) {
        return REDIRECT + loginPath;
    } else {
        SysUser user;
        if (verifyNotEMail(username)) {
            user = service.findByName(site.getId(), username);
        } else {
            user = service.findByEmail(site.getId(), username);
        }
        String ip = RequestUtils.getIpAddress(request);
        if (ControllerUtils.verifyNotExist("username", user, model) || ControllerUtils.verifyNotEquals("password", VerificationUtils.md5Encode(password), user.getPassword(), model) || verifyNotEnablie(user, model)) {
            Long userId = null;
            if (null != user) {
                userId = user.getId();
            }
            logLoginService.save(new LogLogin(site.getId(), username, userId, ip, LogLoginService.CHANNEL_WEB, false, CommonUtils.getDate(), password));
            return REDIRECT + loginPath;
        } else {
            user.setPassword(null);
            setUserToSession(request.getSession(), user);
            String authToken = UUID.randomUUID().toString();
            addLoginStatus(user, authToken, request, response);
            sysUserTokenService.save(new SysUserToken(authToken, site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, CommonUtils.getDate(), ip));
            service.updateLoginStatus(user.getId(), ip);
            logLoginService.save(new LogLogin(site.getId(), username, user.getId(), ip, LogLoginService.CHANNEL_WEB, true, CommonUtils.getDate(), null));
            return REDIRECT + returnUrl;
        }
    }
}
Also used : SysUserToken(com.publiccms.entities.sys.SysUserToken) SysUser(com.publiccms.entities.sys.SysUser) LogLogin(com.publiccms.entities.log.LogLogin) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with SysUser

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

the class LoginController method loginStatus.

/**
 * @param request
 * @param session
 * @param response
 * @param model
 * @return result
 */
@RequestMapping("loginStatus")
@ResponseBody
public ModelMap loginStatus(HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysUser user = getUserFromSession(session);
    if (null != user) {
        model.addAttribute("id", user.getId());
        model.addAttribute("name", user.getName());
        model.addAttribute("nickname", user.getNickName());
        model.addAttribute("email", user.getEmail());
        model.addAttribute("emailChecked", user.isEmailChecked());
        model.addAttribute("superuserAccess", user.isSuperuserAccess());
    }
    return model;
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with SysUser

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

the class LotteryController method lottery.

/**
 * @param callback
 * @param request
 * @param session
 * @param response
 */
@RequestMapping("lottery")
public void lottery(String callback, HttpServletRequest request, HttpSession session, HttpServletResponse response) {
    try {
        HttpParameterHandler handler = new HttpParameterHandler(mappingJackson2HttpMessageConverter, jsonMediaType, request, callback, response);
        SysUser user = getUserFromSession(session);
        if (null != user) {
            lotteryDirective.execute(handler, null, user);
        }
        handler.render();
    } catch (Exception e) {
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) HttpParameterHandler(com.publiccms.common.handler.HttpParameterHandler) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with SysUser

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

the class PlaceController method delete.

/**
 * @param id
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping("delete")
public String delete(Long id, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    CmsPlace entity = service.getEntity(id);
    SysUser user = getUserFromSession(session);
    String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
    CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
    if (ControllerUtils.verifyCustom("manage", null == entity || null == user || CommonUtils.empty(metadata.getAdminIds()) || !ArrayUtils.contains(metadata.getAdminIds(), user.getId()), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model)) {
        return REDIRECT + returnUrl;
    } else {
        service.delete(id);
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "delete.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), id.toString()));
        return REDIRECT + returnUrl;
    }
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with SysUser

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

the class PlaceController method save.

/**
 * @param entity
 * @param returnUrl
 * @param placeParamters
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "save")
public String save(CmsPlace entity, String returnUrl, @ModelAttribute CmsPlaceParamters placeParamters, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    if (null != entity && CommonUtils.notEmpty(entity.getPath())) {
        entity.setPath(entity.getPath().replace("//", SEPARATOR));
        String filePath = siteComponent.getWebTemplateFilePath(site, TemplateComponent.INCLUDE_DIRECTORY + entity.getPath());
        CmsPlaceMetadata metadata = metadataComponent.getPlaceMetadata(filePath);
        SysUser user = getUserFromSession(session);
        if (ControllerUtils.verifyCustom("contribute", null == metadata || !metadata.isAllowContribute() || 0 >= metadata.getSize() || (null == user && !metadata.isAllowAnonymous()), model)) {
            return REDIRECT + returnUrl;
        }
        if (null != entity.getId()) {
            CmsPlace oldEntity = service.getEntity(entity.getId());
            if (null == oldEntity || CommonUtils.empty(oldEntity.getUserId()) || null == user || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model) || ControllerUtils.verifyNotEquals("siteId", user.getId(), oldEntity.getUserId(), model)) {
                return REDIRECT + returnUrl;
            }
            entity = service.update(entity.getId(), entity, ignoreProperties);
            logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "update.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
        } else {
            entity.setSiteId(site.getId());
            Long userId = null;
            if (null != user) {
                userId = user.getId();
                entity.setUserId(user.getId());
            }
            service.save(entity);
            logOperateService.save(new LogOperate(site.getId(), userId, LogLoginService.CHANNEL_WEB, "save.place", RequestUtils.getIpAddress(request), CommonUtils.getDate(), entity.getPath()));
        }
        Map<String, String> map = ExtendUtils.getExtentDataMap(placeParamters.getExtendDataList(), metadataComponent.getPlaceMetadata(filePath).getExtendList());
        String extentString = ExtendUtils.getExtendString(map);
        attributeService.updateAttribute(entity.getId(), extentString);
    }
    return REDIRECT + returnUrl;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) CmsPlace(com.publiccms.entities.cms.CmsPlace) SysUser(com.publiccms.entities.sys.SysUser) CmsPlaceMetadata(com.publiccms.views.pojo.entities.CmsPlaceMetadata) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SysUser (com.publiccms.entities.sys.SysUser)29 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 SysSite (com.publiccms.entities.sys.SysSite)21 LogOperate (com.publiccms.entities.log.LogOperate)15 SysDept (com.publiccms.entities.sys.SysDept)5 HttpParameterHandler (com.publiccms.common.handler.HttpParameterHandler)3 CmsContent (com.publiccms.entities.cms.CmsContent)3 CmsPlace (com.publiccms.entities.cms.CmsPlace)3 SysRoleUser (com.publiccms.entities.sys.SysRoleUser)3 SysRoleUserId (com.publiccms.entities.sys.SysRoleUserId)3 SysUserToken (com.publiccms.entities.sys.SysUserToken)3 CmsPlaceMetadata (com.publiccms.views.pojo.entities.CmsPlaceMetadata)3 Cookie (javax.servlet.http.Cookie)3 CmsCategory (com.publiccms.entities.cms.CmsCategory)2 CmsCategoryModel (com.publiccms.entities.cms.CmsCategoryModel)2 CmsCategoryModelId (com.publiccms.entities.cms.CmsCategoryModelId)2 LogLogin (com.publiccms.entities.log.LogLogin)2 SysExtendField (com.publiccms.entities.sys.SysExtendField)2 CmsModel (com.publiccms.views.pojo.entities.CmsModel)2 ExtendField (com.publiccms.views.pojo.entities.ExtendField)2