修复用户登陆时的用户禁用状态判断
This commit is contained in:
@@ -32,8 +32,8 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
"/swagger-ui/**",
|
||||
"/favicon.ico",
|
||||
// 你的其他放行路径,例如登录接口
|
||||
"/user/doLogin",
|
||||
"/save_data/add_host"
|
||||
"/user/doLogin"
|
||||
// "/save_data/add_host"
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.yupi.springbootinit.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.yupi.springbootinit.common.BaseResponse;
|
||||
@@ -30,7 +31,7 @@ public class UserController {
|
||||
@Resource
|
||||
private SystemUsersService usersService;
|
||||
|
||||
// 测试登录,浏览器访问: http://localhost:8081/user/doLogin?username=zhang&password=123456
|
||||
// 用户登陆接口
|
||||
@PostMapping("doLogin")
|
||||
public BaseResponse<SystemUsersVO> doLogin(@RequestBody SystemUsersDTO usersDTO) {
|
||||
SystemUsers user = usersService.getUserByUserName(usersDTO.getUsername());
|
||||
@@ -42,18 +43,15 @@ public class UserController {
|
||||
throw new BusinessException(ErrorCode.USERNAME_OR_PASSWORD_ERROR);
|
||||
}
|
||||
|
||||
if (CommonStatusEnum.isDisable(user.getStatus())) {
|
||||
if (CommonStatusEnum.isDisable(Integer.valueOf(user.getStatus()))) {
|
||||
throw new BusinessException(ErrorCode.USER_DISABLE);
|
||||
}
|
||||
SystemUsersVO systemUsersVO = new SystemUsersVO();
|
||||
BeanUtil.copyProperties(user, systemUsersVO);
|
||||
StpUtil.login(user.getId());
|
||||
systemUsersVO.setTokenName(StpUtil.getTokenName());
|
||||
systemUsersVO.setTokenValue(StpUtil.getTokenValue());
|
||||
return ResultUtils.success(systemUsersVO);
|
||||
}
|
||||
|
||||
// // 查询登录状态,浏览器访问: http://localhost:8081/user/isLogin
|
||||
// @RequestMapping("isLogin")
|
||||
// public String isLogin() {
|
||||
// return "当前会话是否登录:" + StpUtil.isLogin();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public enum CommonStatusEnum implements ArrayValuable<Integer> {
|
||||
return ObjUtil.equal(ENABLE.status, status);
|
||||
}
|
||||
|
||||
public static boolean isDisable(Byte status) {
|
||||
public static boolean isDisable(Integer status) {
|
||||
return ObjUtil.equal(DISABLE.status, status);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,4 +23,10 @@ public class SystemUsersVO {
|
||||
* 租户编号
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
private String username;
|
||||
|
||||
private String tokenName;
|
||||
|
||||
private String tokenValue;
|
||||
}
|
||||
@@ -104,7 +104,7 @@ sa-token:
|
||||
# 在多人登录同一账号时,是否共用一个 token (为 true 时所有登录共用一个 token, 为 false 时每次登录新建一个 token)
|
||||
is-share: false
|
||||
# token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||
token-style: uuid
|
||||
token-style: random-128
|
||||
# 是否输出操作日志
|
||||
is-log: true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user