Search in sources :

Example 71 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.

the class MaterialServiceImpl method updateMaterial.

/**
 * 通过主键id更新material 不为null 的字段
 *
 * @param Material
 * @return 影响行数
 * @throws CheckedServiceException
 */
@Override
public Integer updateMaterial(Material material, String sessionId) throws CheckedServiceException {
    if (null == material.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "主键为空");
    }
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmphUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    // if (!pmphUser.getIsAdmin()) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL,
    // CheckedExceptionResult.ILLEGAL_PARAM,
    // "该用户没有操作权限");
    // }
    // 教材权限的检查
    List<PmphRole> pmphRoles = pmphUserService.getListUserRole(pmphUser.getId());
    Integer power = null;
    // 系统管理员权限检查
    for (PmphRole pmphRole : pmphRoles) {
        if (null != pmphRole && null != pmphRole.getRoleName() && "系统管理员".equals(pmphRole.getRoleName())) {
            // 我是系统管理原
            power = 1;
        }
    }
    // 教材主任检查
    Material materialDirector = materialService.getMaterialById(material.getId());
    if (null == power) {
        if (null != materialDirector && null != materialDirector.getDirector() && pmphUser.getId().equals(materialDirector.getDirector())) {
            // 我是教材的主任
            power = 2;
        }
    }
    return materialDao.updateMaterial(material);
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) PmphRole(com.bc.pmpheep.back.po.PmphRole)

Example 72 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.

the class MaterialServiceImpl method getMaterialMainInfoById.

@Override
public MaterialMainInfoVO getMaterialMainInfoById(Long materialId, String sessionId) throws CheckedServiceException {
    // 验证用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    // 教材权限的检查
    List<PmphRole> pmphRoles = pmphUserService.getListUserRole(pmphUser.getId());
    // 下面进行授权
    Integer projectEditorPowers = 0;
    Integer role = 0;
    // 系统管理员权限检查
    for (PmphRole pmphRole : pmphRoles) {
        if (null != pmphRole && null != pmphRole.getRoleName() && "系统管理员".equals(pmphRole.getRoleName())) {
            // 我是系统管理原
            // "11111111";
            projectEditorPowers = 255;
            role = 1;
        }
    }
    // 教材主任检查
    Material material = this.getMaterialById(materialId);
    if (null != material && null != material.getDirector() && pmphUser.getId().equals(material.getDirector())) {
        // 我是教材的主任
        projectEditorPowers = 255;
        role = (0 == role.intValue() ? 2 : role);
    }
    // 教材项目编辑检查
    List<MaterialProjectEditorVO> materialProjectEditors = materialProjectEditorService.listMaterialProjectEditors(materialId);
    if (null != materialProjectEditors && materialProjectEditors.size() > 0) {
        for (MaterialProjectEditorVO materialProjectEditor : materialProjectEditors) {
            if (null != materialProjectEditor && null != materialProjectEditor.getEditorId() && materialProjectEditor.getEditorId().equals(pmphUser.getId())) {
                // 我是教材的项目编辑
                projectEditorPowers = (projectEditorPowers | material.getProjectPermission());
                role = (0 == role.intValue() ? 3 : role);
            }
        }
    }
    // 教材策划编辑检查
    Integer num = this.getPlanningEditorSum(materialId, pmphUser.getId());
    if (null != num && num.intValue() > 0) {
        // 我是教材的策划编辑编辑
        projectEditorPowers = (projectEditorPowers | material.getPlanPermission());
        role = (0 == role.intValue() ? 4 : role);
    }
    MaterialMainInfoVO materialMainInfoVO = new MaterialMainInfoVO(materialId, material.getMaterialName(), material.getIsPublished(), material.getIsAllTextbookPublished(), material.getIsForceEnd(), material.getIsDeleted(), StringUtil.tentToBinary(projectEditorPowers), role);
    return materialMainInfoVO;
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) MaterialMainInfoVO(com.bc.pmpheep.back.vo.MaterialMainInfoVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) MaterialProjectEditorVO(com.bc.pmpheep.back.vo.MaterialProjectEditorVO) PmphRole(com.bc.pmpheep.back.po.PmphRole)

Example 73 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.

the class HandshakeInterceptor method beforeHandshake.

// 握手前
@Override
public boolean beforeHandshake(ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse, WebSocketHandler webSocketHandler, Map<String, Object> map) throws Exception {
    if (serverHttpRequest instanceof ServletServerHttpRequest) {
        ServletServerHttpRequest servletRequest = (ServletServerHttpRequest) serverHttpRequest;
        String userType = servletRequest.getServletRequest().getParameter("userType");
        String sessionId = servletRequest.getServletRequest().getParameter("sessionId");
        if (null == userType || "".equals(userType)) {
            return false;
        }
        String userId = null;
        // userType 1=社内用户/2=作家/3=机构用户
        if ("1".equals(userType)) {
            PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
            if (null == pmphUser) {
                return false;
            }
            Long pmphUserId = pmphUser.getId();
            if (null == pmphUserId) {
                return false;
            }
            userId = userType + "_" + pmphUserId;
        } else if ("2".equals(userType)) {
            String fonrtUserId = servletRequest.getServletRequest().getParameter("userId");
            if (null == fonrtUserId || "".equals(fonrtUserId.trim())) {
                return false;
            }
            userId = userType + "_" + fonrtUserId;
            // 验证前台是否登录过了
            if (!MyWebSocketHandler.isLogin(userId)) {
                return false;
            }
        } else if ("3".equals(userType)) {
        } else {
            return false;
        }
        if (null == userId) {
            return false;
        }
        // 为服务器创建WebSocketSession做准备
        map.put("userId", userId);
        return true;
    }
    return false;
}
Also used : ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) PmphUser(com.bc.pmpheep.back.po.PmphUser)

Example 74 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.

the class WeChatLoginController method load.

/**
 * <pre>
 * 功能描述:加载个人信息,此处添加了@OAuthRequired注解
 * 使用示范:
 *
 * @param request
 * @param model
 * @return
 * </pre>
 */
@RequestMapping(value = { "/wechatUserInfo" })
@OAuthRequired
public Object load(HttpServletRequest request, Model model) {
    // System.out.println("Load a User!");
    HttpSession session = request.getSession();
    // 判断是否从企业微信App登陆
    model.addAttribute("Userid", session.getAttribute("UserId"));
    String userAgent = request.getHeader("user-agent").toLowerCase();
    Boolean isTrue = userAgent == null || userAgent.indexOf("micromessenger") == -1 ? false : true;
    if (isTrue) {
        String wechatUserId = (String) session.getAttribute("UserId");
        if (StringUtil.isEmpty(wechatUserId)) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "网络异常,请重新再试!");
        }
        PmphUserWechat pmphUserWechat = pmphUserWechatService.getPmphUserWechatByWechatId(wechatUserId);
        if (ObjectUtil.isNull(pmphUserWechat)) {
            model.addAttribute("isLogin", "0");
        } else {
            PmphUser pu = pmphUserService.getPmphUserByUsername(pmphUserWechat.getUsername());
            if (ObjectUtil.notNull(pu)) {
                String username = new DesRun(null, pmphUserWechat.getUsername()).enpsw;
                String password = pu.getPassword();
                model.addAttribute(Const.PMPH_WECHAT_USER_TOKEN, new DesRun(password, username + password + wechatUserId + "<pmpheep>").enpsw);
                model.addAttribute("username", username);
                model.addAttribute("password", password);
                model.addAttribute("isLogin", "1");
            }
        }
    }
    return "wechat";
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) HttpSession(javax.servlet.http.HttpSession) DesRun(com.bc.pmpheep.back.util.DesRun) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphUserWechat(com.bc.pmpheep.back.po.PmphUserWechat) OAuthRequired(com.bc.pmpheep.wechat.interceptor.OAuthRequired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 75 with PmphUser

use of com.bc.pmpheep.back.po.PmphUser in project pmph by BCSquad.

the class PmphUserRealm method doGetAuthenticationInfo.

/**
 * 认证
 *
 * @param authenticationToken
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
    logger.info("--- MyRealm doGetAuthenticationInfo ---[SecondRealm] doGetAuthenticationInfo " + authenticationToken);
    String username = authenticationToken.getPrincipal().toString();
    String password = new String((char[]) authenticationToken.getCredentials());
    try {
        PmphUser user = userService.login(username, password);
        if (user != null) {
            // 第 1 个参数可以传一个实体对象,然后在认证的环节可以取出
            // 第 2 个参数应该传递在数据库中“正确”的数据,然后和 token 中的数据进行匹配
            SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), getName());
            // 设置盐值
            info.setCredentialsSalt(ByteSource.Util.bytes(username.getBytes()));
            return info;
        }
    } catch (Exception e) {
        logger.debug("message => " + e);
    }
    return null;
}
Also used : SimpleAuthenticationInfo(org.apache.shiro.authc.SimpleAuthenticationInfo) PmphUser(com.bc.pmpheep.back.po.PmphUser) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Aggregations

PmphUser (com.bc.pmpheep.back.po.PmphUser)102 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)81 ArrayList (java.util.ArrayList)33 PageResult (com.bc.pmpheep.back.plugin.PageResult)17 HashMap (java.util.HashMap)13 Material (com.bc.pmpheep.back.po.Material)11 WriterUser (com.bc.pmpheep.back.po.WriterUser)11 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)10 PmphRole (com.bc.pmpheep.back.po.PmphRole)9 UserMessage (com.bc.pmpheep.back.po.UserMessage)9 PmphGroupMemberVO (com.bc.pmpheep.back.vo.PmphGroupMemberVO)9 BaseTest (com.bc.pmpheep.test.BaseTest)9 Test (org.junit.Test)9 CmsContent (com.bc.pmpheep.back.po.CmsContent)8 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)8 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)7 Textbook (com.bc.pmpheep.back.po.Textbook)7 WriterUserTrendst (com.bc.pmpheep.back.po.WriterUserTrendst)6 Gson (com.google.gson.Gson)6 OrgUser (com.bc.pmpheep.back.po.OrgUser)5