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