Search in sources :

Example 21 with ResponseBean

use of com.bc.pmpheep.controller.bean.ResponseBean in project pmph by BCSquad.

the class PmphLoginController method login.

/**
 * <pre>
 * 功能描述:登陆
 * 使用示范:
 *
 * @param user
 * @param model
 * @return
 * </pre>
 *
 * //* @throws SingleSignOnException
 */
@ResponseBody
@OAuthRequired
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "wechatUserId", required = false) String wechatUserId, @RequestParam(value = "token", required = false) String token, HttpServletRequest request) throws CheckedServiceException {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    logger.info("username => " + username);
    logger.info("password => " + password);
    // HttpSingleSignOnService service = new HttpSingleSignOnService();
    // String url = service.getSingleSignOnURL();
    // try {
    // 判断是否从企业微信App登陆
    String userAgent = request.getHeader("user-agent").toLowerCase();
    Boolean isTrue = userAgent == null || userAgent.indexOf("micromessenger") == -1 ? false : true;
    if (isTrue) {
        if (StringUtil.notEmpty(token)) {
            String newToken = username + password + wechatUserId + "<pmpheep>";
            if (!newToken.equals(new DesRun(token).depsw)) {
                throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名密码错误!");
            }
        }
        username = new DesRun(username).depsw;
        password = new DesRun(password).depsw;
    }
    if (StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "请输入用户名和密码!");
    }
    PmphUser pmphUser = pmphUserService.login(username, new DesRun("", password).enpsw);
    // PmphUser pmphUser = pmphUserService.login(userName, null);
    pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
    if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
        pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
    }
    // 根据用户Id查询对应角色(是否为管理员)
    List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
    if (pmphRoles.isEmpty()) {
        // 添加默认权限
        pmphRoleService.addUserRole(pmphUser.getId(), 2L);
        pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
    }
    List<Long> roleIds = new ArrayList<Long>();
    for (PmphRole pmphRole : pmphRoles) {
        roleIds.add(pmphRole.getId());
        if (ObjectUtil.notNull(pmphRole)) {
            if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
                pmphUser.setIsAdmin(true);
            } else {
                pmphUser.setIsAdmin(false);
            }
        }
        if (Const.TRUE == pmphUser.getIsAdmin()) {
            break;
        }
    }
    // 根据用户Id查询对应权限Id
    List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
    // 判断是否从企业微信App登陆
    if (isTrue) {
        PmphUserWechat pmphUserWechat = pmphUserWechatService.getPmphUserWechatByWechatId(wechatUserId);
        if (ObjectUtil.isNull(pmphUserWechat)) {
            pmphUserWechatService.add(new PmphUserWechat(username, wechatUserId));
        }
    }
    // String materialPermission =
    // pmphUserService.getMaterialPermissionByUserId(pmphUser.getId()); 根据用户返回书籍
    // 验证成功在Session中保存用户信息
    request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
    // 验证成功在Session中保存用户Token信息
    request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
    // pmphUserSessionId
    resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
    resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
    resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(password, username).enpsw);
    resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
    // resultMap.put("materialPermission", materialPermission);
    return new ResponseBean(resultMap);
// } catch (CheckedServiceException cException) {
// return new ResponseBean(cException);
// }
}
Also used : HashMap(java.util.HashMap) PmphUser(com.bc.pmpheep.back.po.PmphUser) ArrayList(java.util.ArrayList) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphUserWechat(com.bc.pmpheep.back.po.PmphUserWechat) PmphRole(com.bc.pmpheep.back.po.PmphRole) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) OAuthRequired(com.bc.pmpheep.wechat.interceptor.OAuthRequired) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with ResponseBean

use of com.bc.pmpheep.controller.bean.ResponseBean in project pmph by BCSquad.

the class PmphLoginController method ssoLogin.

/**
 * <pre>
 * 功能描述:SSO登陆
 * 使用示范:
 *
 * @param request
 * @return
 * </pre>
 */
@ResponseBody
@RequestMapping(value = "/sso", method = RequestMethod.GET)
public ResponseBean ssoLogin(HttpServletRequest request, HttpServletResponse response) {
    String sessionId = CookiesUtil.getSessionId(request);
    PmphUser pmUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (ObjectUtil.isNull(pmUser)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "用户为空");
    }
    Map<String, Object> resultMap = new HashMap<String, Object>();
    HttpSingleSignOnService service = new HttpSingleSignOnService();
    // String url = service.getSingleSignOnURL();
    try {
        Principal principal = service.singleSignOn(request);
        String userName = principal.getName();
        PmphUser pmphUser = pmphUserService.login(userName, null);
        if (ObjectUtil.isNull(pmphUser)) {
            // 为空就新建一个用户
            pmphUser = pmphUserService.add(new PmphUser(userName, "888888", userName, "DEFAULT"));
            // 添加默认权限
            pmphRoleService.addUserRole(pmphUser.getId(), 2L);
        }
        pmphUser.setLoginType(Const.LOGIN_TYPE_PMPH);
        if (!RouteUtil.DEFAULT_USER_AVATAR.equals(pmphUser.getAvatar())) {
            pmphUser.setAvatar(RouteUtil.userAvatar(pmphUser.getAvatar()));
        }
        // 根据用户Id查询对应角色(是否为管理员)
        List<PmphRole> pmphRoles = pmphRoleService.getPmphRoleByUserId(pmphUser.getId());
        List<Long> roleIds = new ArrayList<Long>(pmphRoles.size());
        for (PmphRole pmphRole : pmphRoles) {
            roleIds.add(pmphRole.getId());
            if (ObjectUtil.notNull(pmphRole)) {
                if (Const.LOGIN_USER_IS_ADMIN.equals(pmphRole.getRoleName()) || Const.LOGIN_USER_IS_ADMINS.equals(pmphRole.getRoleName()) || Const.LOGIN_SYS_USER_IS_ADMIN.equals(pmphRole.getRoleName())) {
                    pmphUser.setIsAdmin(true);
                } else {
                    pmphUser.setIsAdmin(false);
                }
            }
            if (Const.TRUE == pmphUser.getIsAdmin()) {
                break;
            }
        }
        // 根据用户Id查询对应权限Id
        List<Long> pmphUserPermissionIds = pmphUserService.getPmphUserPermissionByUserId(pmphUser.getId());
        // 验证成功在Session中保存用户信息
        request.getSession().setAttribute(Const.SESSION_PMPH_USER, pmphUser);
        // 验证成功在Session中保存用户Token信息
        request.getSession().setAttribute(Const.SEESION_PMPH_USER_TOKEN, new DesRun(userName, userName).enpsw);
        // pmphUserSessionId
        resultMap.put(Const.USER_SEESION_ID, request.getSession().getId());
        resultMap.put(Const.SESSION_PMPH_USER, pmphUser);
        resultMap.put(Const.SEESION_PMPH_USER_TOKEN, new DesRun(userName, userName).enpsw);
        resultMap.put("pmphUserPermissionIds", pmphUserPermissionIds);
        return new ResponseBean(resultMap);
    } catch (SingleSignOnException e) {
        return new ResponseBean(e);
    }
}
Also used : PmphUser(com.bc.pmpheep.back.po.PmphUser) HashMap(java.util.HashMap) HttpSingleSignOnService(small.danfer.sso.http.HttpSingleSignOnService) ArrayList(java.util.ArrayList) SingleSignOnException(small.danfer.sso.SingleSignOnException) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) PmphRole(com.bc.pmpheep.back.po.PmphRole) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) Principal(java.security.Principal) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ResponseBean

use of com.bc.pmpheep.controller.bean.ResponseBean in project pmph by BCSquad.

the class PmphUserController method resources.

/**
 * <pre>
 * 功能描述:根据用户 id 跳转到用户权限的列表页面
 * 使用示范:
 *
 * @param userId
 * @param model
 * @return
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "查询指定用户 id 所拥有的权限")
@RequestMapping(value = "/resources/{id}", method = RequestMethod.GET)
public ResponseBean resources(@PathVariable("id") Long userId) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<PmphPermission> resourceList = userService.getListAllResource(userId);
    PmphUser user = userService.get(userId);
    result.put("resources", resourceList);
    result.put("user", user);
    return new ResponseBean(result);
}
Also used : HashMap(java.util.HashMap) PmphPermission(com.bc.pmpheep.back.po.PmphPermission) PmphUser(com.bc.pmpheep.back.po.PmphUser) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ResponseBean

use of com.bc.pmpheep.controller.bean.ResponseBean in project pmph by BCSquad.

the class WriterLoginController method login.

/**
 * <pre>
 * 功能描述:登陆
 * 使用示范:
 *
 * &#64;param user
 * &#64;param model
 * &#64;return
 * </pre>
 */
@ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam("username") String username, @RequestParam("password") String password, HttpServletRequest request) {
    logger.info("username => " + username);
    logger.info("password => " + password);
    Map<String, Object> resultMap = new HashMap<String, Object>();
    try {
        WriterUser writerUser = writerUserService.login(username, new DesRun("", password).enpsw);
        writerUser.setLoginType(Const.LOGIN_TYPE_WRITER);
        if (!RouteUtil.DEFAULT_USER_AVATAR.equals(writerUser.getAvatar())) {
            writerUser.setAvatar(RouteUtil.userAvatar(writerUser.getAvatar()));
        }
        // 根据用户Id查询对应权限Id
        List<Long> writerUserPermissionIds = writerUserService.getWriterUserPermissionByUserId(writerUser.getId());
        // 验证成功在Session中保存用户信息
        request.getSession().setAttribute(Const.SESSION_WRITER_USER, writerUser);
        // 验证成功在Session中保存用户Token信息
        request.getSession().setAttribute(Const.SEESION_WRITER_USER_TOKEN, new DesRun(password, username).enpsw);
        resultMap.put(Const.USER_SEESION_ID, new DesRun("", request.getSession().getId()).enpsw);
        resultMap.put(Const.SESSION_WRITER_USER, writerUser);
        resultMap.put(Const.SEESION_WRITER_USER_TOKEN, new DesRun(password, username).enpsw);
        resultMap.put("writerUserPermissionIds", writerUserPermissionIds);
        return new ResponseBean(resultMap);
    } catch (CheckedServiceException cException) {
        return new ResponseBean(cException);
    }
}
Also used : HashMap(java.util.HashMap) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with ResponseBean

use of com.bc.pmpheep.controller.bean.ResponseBean in project pmph by BCSquad.

the class WriterUserController method resources.

/**
 * <pre>
 * 功能描述:根据用户 id 跳转到用户权限的列表页面
 * 使用示范:
 *
 * &#64;param userId
 * &#64;param model
 * &#64;return
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "跳转到用户权限的列表页面")
@RequestMapping(value = "/resources/{id}", method = RequestMethod.GET)
public ResponseBean resources(@PathVariable("id") Long userId) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<WriterPermission> resourceList = writerUserService.getListAllResource(userId);
    WriterUser user = writerUserService.get(userId);
    result.put("resources", resourceList);
    result.put("user", user);
    return new ResponseBean(result);
}
Also used : WriterPermission(com.bc.pmpheep.back.po.WriterPermission) HashMap(java.util.HashMap) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) WriterUser(com.bc.pmpheep.back.po.WriterUser) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ResponseBean (com.bc.pmpheep.controller.bean.ResponseBean)67 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)67 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)65 LogDetail (com.bc.pmpheep.annotation.LogDetail)61 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)37 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 TopicLog (com.bc.pmpheep.back.po.TopicLog)5 DesRun (com.bc.pmpheep.back.util.DesRun)4 Properties (java.util.Properties)4 BookVideo (com.bc.pmpheep.back.po.BookVideo)3 PmphGroupMember (com.bc.pmpheep.back.po.PmphGroupMember)3 PmphUser (com.bc.pmpheep.back.po.PmphUser)3 Topic (com.bc.pmpheep.back.po.Topic)3 PmphGroup (com.bc.pmpheep.back.po.PmphGroup)2 PmphRole (com.bc.pmpheep.back.po.PmphRole)2 WriterUser (com.bc.pmpheep.back.po.WriterUser)2 DeclarationResultSchoolVO (com.bc.pmpheep.back.vo.DeclarationResultSchoolVO)2