@@ -1,11 +1,12 @@
|
||||
package com.yunhai.userhome.controller.api;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.openapi.client.YschBaseOpenApi;
|
||||
import com.yunhai.platform.openapi.client.OpenApiUserClient;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.platform.utils.model.BoaUser;
|
||||
import com.yunhai.userhome.config.Config;
|
||||
import com.yunhai.userhome.utils.OtherUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
@@ -25,6 +26,9 @@ import java.util.Map;
|
||||
@RequestMapping(value = Config.API_PATH)
|
||||
public class MiscController {
|
||||
|
||||
@Autowired
|
||||
private OpenApiUserClient openApiUserClient;
|
||||
|
||||
/**
|
||||
* 修改用户密码(对齐旧 UserController.updateUserPassword)。
|
||||
* 前端调用:BaseApi.updatePassword → POST /api/updateUserPassword
|
||||
@@ -40,7 +44,7 @@ public class MiscController {
|
||||
throw new BizException(ErrorCode.CUSTOM, "新密码不得与旧密码相同!");
|
||||
}
|
||||
try {
|
||||
YschBaseOpenApi.updateUserPassword(authUserWithDept.getId(), oldPassword, password);
|
||||
openApiUserClient.updateUserPassword(authUserWithDept.getId(), oldPassword, password);
|
||||
} catch (Exception e) {
|
||||
throw new BizException(ErrorCode.CUSTOM, e.getMessage());
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yunhai.userhome.controller.api;
|
||||
|
||||
import com.yunhai.platform.apistd.BizException;
|
||||
import com.yunhai.platform.openapi.client.OpenApiUserClient;
|
||||
import com.yunhai.platform.openapi.client.YschBaseOpenApi;
|
||||
import com.yunhai.platform.utils.exception.ErrorCode;
|
||||
import com.yunhai.platform.utils.model.BoaApp;
|
||||
@@ -8,9 +9,7 @@ import com.yunhai.platform.utils.model.BoaAppType;
|
||||
import com.yunhai.platform.utils.model.BoaRoleInfo;
|
||||
import com.yunhai.platform.utils.model.BoaUser;
|
||||
import com.yunhai.userhome.config.Config;
|
||||
import com.yunhai.userhome.entity.UserCurrentRole;
|
||||
import com.yunhai.userhome.service.AppRemoteService;
|
||||
import com.yunhai.userhome.service.IUserCurrentRoleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -33,7 +32,7 @@ public class UserController {
|
||||
private AppRemoteService appRemoteService;
|
||||
|
||||
@Autowired
|
||||
private IUserCurrentRoleService userCurrentRoleService;
|
||||
private OpenApiUserClient openApiUserClient;
|
||||
|
||||
|
||||
/** 当前登录用户信息(CAS 注入)。 */
|
||||
@@ -76,23 +75,21 @@ public class UserController {
|
||||
return YschBaseOpenApi.getUserRoleList(authUserWithDept.getId());
|
||||
}
|
||||
|
||||
/** 当前用户激活的角色(本地 user_current_role,可能为空)。 */
|
||||
/** 当前用户激活的身份(UserBase 单一权威源;未切换时兜底主身份,无身份为 null)。 */
|
||||
@GetMapping("findUserRole")
|
||||
public UserCurrentRole findUserRole(BoaUser authUserWithDept) {
|
||||
return userCurrentRoleService.findById(authUserWithDept.getId()).orElse(null);
|
||||
public BoaRoleInfo findUserRole(BoaUser authUserWithDept) {
|
||||
return YschBaseOpenApi.getCurrentIdentity(authUserWithDept.getId());
|
||||
}
|
||||
|
||||
/** 保存当前激活角色(校验所选 学校+角色 属于用户角色列表,防越权)。 */
|
||||
/**
|
||||
* 保存当前激活角色:userId 只取 CAS 会话(无视请求体,防切他人),
|
||||
* 目标 (roleId, schId) 是否属该用户由 UserBase 侧 sys_user_role_rel 三元组校验。
|
||||
*/
|
||||
@PostMapping("savUserRole")
|
||||
public void savUserRole(BoaUser authUserWithDept, @RequestBody UserCurrentRole roleInfo) {
|
||||
List<BoaRoleInfo> roleList = YschBaseOpenApi.getUserRoleList(authUserWithDept.getId());
|
||||
boolean exists = roleList.stream().anyMatch(r ->
|
||||
r.getRoleId() != null && r.getRoleId().equals(roleInfo.getRoleId())
|
||||
&& r.getSchId() != null && r.getSchId().equals(roleInfo.getSchId()));
|
||||
if (!exists) {
|
||||
throw new BizException(ErrorCode.FORBIDDEN, "非法操作,没有权限");
|
||||
public void savUserRole(BoaUser authUserWithDept, @RequestBody BoaRoleInfo roleInfo) {
|
||||
if (roleInfo.getRoleId() == null || roleInfo.getSchId() == null) {
|
||||
throw new BizException(ErrorCode.PARAM_ERROR, "角色或学校不能为空");
|
||||
}
|
||||
roleInfo.setUserId(authUserWithDept.getId());
|
||||
userCurrentRoleService.save(roleInfo);
|
||||
openApiUserClient.switchIdentity(authUserWithDept.getId(), roleInfo.getRoleId(), roleInfo.getSchId());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user