Search in sources :

Example 21 with SysUser

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

the class UserController method changePassword.

/**
 * @param oldpassword
 * @param password
 * @param repassword
 * @param returnUrl
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "changePassword", method = RequestMethod.POST)
public String changePassword(String oldpassword, String password, String repassword, String returnUrl, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    SysSite site = getSite(request);
    if (CommonUtils.empty(returnUrl)) {
        returnUrl = site.getDynamicPath();
    }
    SysUser user = getUserFromSession(session);
    if (ControllerUtils.verifyNotEmpty("user", user, model) || ControllerUtils.verifyNotEmpty("password", password, model) || ControllerUtils.verifyNotEquals("repassword", password, repassword, model) || ControllerUtils.verifyNotEquals("password", user.getPassword(), VerificationUtils.md5Encode(oldpassword), model)) {
        return REDIRECT + returnUrl;
    } else {
        Cookie userCookie = RequestUtils.getCookie(request.getCookies(), CommonConstants.getCookiesUser());
        if (null != userCookie && CommonUtils.notEmpty(userCookie.getValue())) {
            String value = userCookie.getValue();
            if (null != value) {
                String[] userData = value.split(CommonConstants.getCookiesUserSplit());
                if (userData.length > 1) {
                    sysUserTokenService.delete(userData[1]);
                }
            }
        }
        clearUserToSession(request.getContextPath(), session, response);
        service.updatePassword(user.getId(), VerificationUtils.md5Encode(password));
        model.addAttribute(MESSAGE, SUCCESS);
        logOperateService.save(new LogOperate(site.getId(), user.getId(), LogLoginService.CHANNEL_WEB, "changepassword", RequestUtils.getIpAddress(request), CommonUtils.getDate(), user.getPassword()));
        return REDIRECT + returnUrl;
    }
}
Also used : Cookie(javax.servlet.http.Cookie) LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with SysUser

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

the class OauthController method callback.

/**
 * @param channel
 * @param state
 * @param code
 * @param request
 * @param session
 * @param response
 * @param model
 * @return view name
 */
@RequestMapping(value = "callback/{channel}")
public String callback(@PathVariable("channel") String channel, String state, String code, HttpServletRequest request, HttpSession session, HttpServletResponse response, ModelMap model) {
    Oauth oauthComponent = oauthChannelMap.get(channel);
    SysSite site = getSite(request);
    Cookie stateCookie = RequestUtils.getCookie(request.getCookies(), STATE_COOKIE_NAME);
    if (null != oauthComponent && oauthComponent.enabled(site.getId()) && null != stateCookie && null != state && state.equals(stateCookie.getValue())) {
        try {
            OauthAccess oauthAccess = oauthComponent.getOpenId(site.getId(), code);
            if (null != oauthAccess && null != oauthAccess.getOpenId()) {
                Cookie cookie = RequestUtils.getCookie(request.getCookies(), RETURN_URL);
                String returnUrl = site.getDynamicPath();
                if (null != cookie && null != cookie.getValue()) {
                    returnUrl = cookie.getValue();
                }
                SysUserToken entity = sysUserTokenService.getEntity(oauthAccess.getOpenId());
                if (null != entity) {
                    if (entity.getChannel().equals(channel)) {
                        setUserToSession(session, sysUserService.getEntity(entity.getUserId()));
                        return REDIRECT + returnUrl;
                    }
                } else {
                    SysUser user = getUserFromSession(session);
                    if (null == user) {
                        OauthUser oauthUser = oauthComponent.getUserInfo(site.getId(), oauthAccess);
                        Map<String, String> config = configComponent.getConfigData(site.getId(), AbstractOauth.CONFIG_CODE);
                        if (null != oauthUser && CommonUtils.notEmpty(config) && CommonUtils.notEmpty(config.get(LoginConfigComponent.CONFIG_REGISTER_URL))) {
                            model.addAttribute("nickname", oauthUser.getNickname());
                            model.addAttribute("openId", oauthUser.getOpenId());
                            model.addAttribute("avatar", oauthUser.getAvatar());
                            model.addAttribute("gender", oauthUser.getGender());
                            model.addAttribute("channel", channel);
                            model.addAttribute("returnUrl", returnUrl);
                            return REDIRECT + config.get(LoginConfigComponent.CONFIG_REGISTER_URL);
                        }
                    } else {
                        String authToken = new StringBuilder(channel).append(DOT).append(site.getId()).append(DOT).append(oauthAccess.getOpenId()).toString();
                        entity = new SysUserToken(authToken, site.getId(), user.getId(), channel, CommonUtils.getDate(), RequestUtils.getIpAddress(request));
                        sysUserTokenService.save(entity);
                        setUserToSession(session, user);
                        return REDIRECT + returnUrl;
                    }
                }
            }
        } catch (IOException e) {
            log.error(e);
        }
    }
    return REDIRECT + site.getDynamicPath();
}
Also used : AbstractOauth(com.publiccms.common.base.oauth.AbstractOauth) Oauth(com.publiccms.common.api.oauth.Oauth) Cookie(javax.servlet.http.Cookie) OauthAccess(com.publiccms.view.pojo.oauth.OauthAccess) SysUserToken(com.publiccms.entities.sys.SysUserToken) SysUser(com.publiccms.entities.sys.SysUser) IOException(java.io.IOException) SysSite(com.publiccms.entities.sys.SysSite) OauthUser(com.publiccms.view.pojo.oauth.OauthUser) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with SysUser

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

the class SysUserService method deleteRoleIds.

/**
 * @param userId
 * @param roleId
 */
public void deleteRoleIds(Serializable userId, Integer roleId) {
    SysUser entity = getEntity(userId);
    if (null != entity) {
        String roles = entity.getRoles();
        String[] roleArray = StringUtils.split(roles, ',');
        ArrayUtils.removeElement(roleArray, roleId.toString());
        entity.setRoles(arrayToCommaDelimitedString(roleArray));
    }
}
Also used : SysUser(com.publiccms.entities.sys.SysUser) StringUtils.arrayToCommaDelimitedString(org.springframework.util.StringUtils.arrayToCommaDelimitedString)

Example 24 with SysUser

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

the class SysDeptAdminController method enable.

/**
 * @param id
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping(value = "enableUser", method = RequestMethod.POST)
public String enable(Long id, HttpServletRequest request, HttpSession session, ModelMap model) {
    if (ControllerUtils.verifyEquals("admin.operate", getAdminFromSession(session).getId(), id, model)) {
        return TEMPLATE_ERROR;
    }
    SysUser entity = userService.getEntity(id);
    if (null != entity) {
        SysSite site = getSite(request);
        SysDept dept = service.getEntity(entity.getDeptId());
        SysUser admin = getAdminFromSession(session);
        if (ControllerUtils.verifyNotEquals("siteId", site.getId(), entity.getSiteId(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model)) {
            return TEMPLATE_ERROR;
        }
        userService.updateStatus(id, false);
        logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "enable.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysDept(com.publiccms.entities.sys.SysDept) SysSite(com.publiccms.entities.sys.SysSite) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with SysUser

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

the class SysDeptAdminController method saveUser.

/**
 * @param entity
 * @param repassword
 * @param roleIds
 * @param request
 * @param session
 * @param model
 * @return view name
 */
@RequestMapping("saveUser")
public String saveUser(SysUser entity, String repassword, Integer[] roleIds, HttpServletRequest request, HttpSession session, ModelMap model) {
    SysSite site = getSite(request);
    entity.setName(StringUtils.trim(entity.getName()));
    entity.setNickName(StringUtils.trim(entity.getNickName()));
    entity.setPassword(StringUtils.trim(entity.getPassword()));
    repassword = StringUtils.trim(repassword);
    SysDept dept = service.getEntity(entity.getDeptId());
    SysUser admin = getAdminFromSession(session);
    if (ControllerUtils.verifyNotEmpty("username", entity.getName(), model) || ControllerUtils.verifyNotEmpty("deptId", dept, model) || ControllerUtils.verifyNotEquals("userId", dept.getUserId(), admin.getId(), model) || ControllerUtils.verifyNotEquals("siteId", site.getId(), dept.getSiteId(), model) || ControllerUtils.verifyNotEmpty("nickname", entity.getNickName(), model) || verifyNotUserName("username", entity.getName(), model) || verifyNotNickName("nickname", entity.getNickName(), model)) {
        return TEMPLATE_ERROR;
    }
    entity.setSuperuserAccess(true);
    entity.setRoles(arrayToCommaDelimitedString(roleIds));
    if (null != entity.getId()) {
        SysUser oldEntity = userService.getEntity(entity.getId());
        if (null == oldEntity || ControllerUtils.verifyNotEquals("siteId", site.getId(), oldEntity.getSiteId(), model)) {
            return TEMPLATE_ERROR;
        }
        SysUser user = userService.getEntity(entity.getId());
        if ((!user.getName().equals(entity.getName()) && ControllerUtils.verifyHasExist("username", userService.findByName(site.getId(), entity.getName()), model)) || (!user.getNickName().equals(entity.getNickName()) && ControllerUtils.verifyHasExist("nickname", userService.findByNickName(site.getId(), entity.getNickName()), model))) {
            return TEMPLATE_ERROR;
        }
        if (CommonUtils.notEmpty(entity.getPassword())) {
            if (ControllerUtils.verifyNotEquals("repassword", entity.getPassword(), repassword, model)) {
                return TEMPLATE_ERROR;
            }
            entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
        } else {
            entity.setPassword(user.getPassword());
            if (CommonUtils.empty(entity.getEmail()) || !entity.getEmail().equals(user.getEmail())) {
                entity.setEmailChecked(false);
            }
        }
        entity = userService.update(entity.getId(), entity, userIgnoreProperties);
        if (null != entity) {
            roleUserService.dealRoleUsers(entity.getId(), roleIds);
            logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "update.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
        }
    } else {
        if (ControllerUtils.verifyNotEmpty("password", entity.getPassword(), model) || ControllerUtils.verifyNotEquals("repassword", entity.getPassword(), repassword, model) || ControllerUtils.verifyHasExist("username", userService.findByName(site.getId(), entity.getName()), model)) {
            return TEMPLATE_ERROR;
        }
        entity.setDeptId(dept.getId());
        entity.setSiteId(site.getId());
        entity.setPassword(VerificationUtils.md5Encode(entity.getPassword()));
        userService.save(entity);
        if (CommonUtils.notEmpty(roleIds)) {
            for (Integer roleId : roleIds) {
                roleUserService.save(new SysRoleUser(new SysRoleUserId(roleId, entity.getId())));
            }
        }
        logOperateService.save(new LogOperate(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER, "save.user", RequestUtils.getIpAddress(request), CommonUtils.getDate(), JsonUtils.getString(entity)));
    }
    return TEMPLATE_DONE;
}
Also used : LogOperate(com.publiccms.entities.log.LogOperate) SysUser(com.publiccms.entities.sys.SysUser) SysDept(com.publiccms.entities.sys.SysDept) SysRoleUserId(com.publiccms.entities.sys.SysRoleUserId) SysSite(com.publiccms.entities.sys.SysSite) SysRoleUser(com.publiccms.entities.sys.SysRoleUser) 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