登录时判断用户状态

This commit is contained in:
shiziyuan9527 2020-05-22 14:47:07 +08:00
parent 788939936d
commit 7421b4b89d
1 changed files with 6 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtUserMapper;
import io.metersphere.base.mapper.ext.ExtUserRoleMapper;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.constants.UserStatus;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.CodingUtil;
@ -19,6 +20,7 @@ import io.metersphere.dto.UserDTO;
import io.metersphere.dto.UserRoleDTO;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authc.DisabledAccountException;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -115,7 +117,7 @@ public class UserService {
user.setCreateTime(System.currentTimeMillis());
user.setUpdateTime(System.currentTimeMillis());
// 默认1:启用状态
user.setStatus("1");
user.setStatus(UserStatus.NORMAL);
// 密码使用 MD5
user.setPassword(CodingUtil.md5(user.getPassword()));
UserExample userExample = new UserExample();
@ -134,6 +136,9 @@ public class UserService {
if (user == null) {
return null;
}
if (StringUtils.equals(user.getStatus(), UserStatus.DISABLED)) {
throw new DisabledAccountException();
}
UserDTO userDTO = new UserDTO();
BeanUtils.copyProperties(user, userDTO);
UserRoleDTO userRole = getUserRole(userId);