diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java b/lms/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java index 7b1ced2..d4325e2 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/security/rest/AuthorizationController.java @@ -92,6 +92,9 @@ public class AuthorizationController { throw new BadRequestException("账号或密码错误"); } + // 判断是否被锁 + if (!userDto.getEnabled()) throw new BadRequestException("账号未激活"); + // 获取权限列表 - 登录查找权限 List permissionList = roleService.getPermissionList(userDto); diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java b/lms/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java index d82eff0..672e2ef 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/system/rest/UserController.java @@ -19,6 +19,7 @@ import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.secure.SaSecureUtil; import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ObjectUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -38,7 +39,9 @@ import org.nl.modules.system.service.UserService; import org.nl.modules.system.service.dto.RoleSmallDto; import org.nl.modules.system.service.dto.UserDto; import org.nl.modules.system.service.dto.UserQueryCriteria; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Pageable; +import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.CollectionUtils; @@ -109,7 +112,10 @@ public class UserController { public ResponseEntity create(@Validated @RequestBody User resources){ checkLevel(resources); // 默认密码 123456 - resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt")); + if (ObjectUtil.isEmpty(resources.getPassword())) + resources.setPassword(SaSecureUtil.md5BySalt("123456", "salt")); + else + resources.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt")); userService.create(resources); return new ResponseEntity<>(HttpStatus.CREATED); } diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java index 23c5723..6ec7033 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/system/service/impl/UserServiceImpl.java @@ -15,6 +15,8 @@ */ package org.nl.modules.system.service.impl; +import cn.dev33.satoken.secure.SaSecureUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import lombok.RequiredArgsConstructor; import org.nl.modules.common.config.FileProperties; @@ -89,9 +91,6 @@ public class UserServiceImpl implements UserService { if (userRepository.findByUsername(resources.getUsername()) != null) { throw new EntityExistException(User.class, "username", resources.getUsername()); } - if (userRepository.findByEmail(resources.getEmail()) != null) { - throw new EntityExistException(User.class, "email", resources.getEmail()); - } resources.setCreateBy(SecurityUtils.getCurrentUsername()); userRepository.save(resources); } @@ -102,45 +101,36 @@ public class UserServiceImpl implements UserService { User user = userRepository.findById(resources.getId()).orElseGet(User::new); ValidationUtil.isNull(user.getId(), "User", "id", resources.getId()); User user1 = userRepository.findByUsername(resources.getUsername()); - User user2 = userRepository.findByEmail(resources.getEmail()); if (user1 != null && !user.getId().equals(user1.getId())) { throw new EntityExistException(User.class, "username", resources.getUsername()); } - - if (user2 != null && !user.getId().equals(user2.getId())) { - throw new EntityExistException(User.class, "email", resources.getEmail()); - } // 如果用户的角色改变 if (!resources.getRoles().equals(user.getRoles())) { redisUtils.del(CacheKey.DATA_USER + resources.getId()); redisUtils.del(CacheKey.MENU_USER + resources.getId()); redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); } - // 如果用户名称修改 - if(!resources.getUsername().equals(user.getUsername())){ - redisUtils.del("user::username:" + user.getUsername()); - } + redisUtils.del("user::username:" + user.getUsername()); // 如果用户被禁用,则清除用户登录信息 if(!resources.getEnabled()){ onlineUserService.kickOutForUsername(resources.getUsername()); } - User clone = new User(); // jpa 多表问题,需要用新的类来进行修改 - clone.setId(resources.getId()); - clone.setUsername(resources.getUsername()); - clone.setEmail(resources.getEmail()); - clone.setEnabled(resources.getEnabled()); - clone.setRoles(resources.getRoles()); - clone.setDept(resources.getDept()); - clone.setPhone(resources.getPhone()); - clone.setNickName(resources.getNickName()); - clone.setGender(resources.getGender()); - - userRepository.save(clone); + user.setId(resources.getId()); + user.setUsername(resources.getUsername()); + user.setEmail(resources.getEmail()); + user.setEnabled(resources.getEnabled()); + user.setRoles(resources.getRoles()); + user.setDept(resources.getDept()); + user.setPhone(resources.getPhone()); + user.setNickName(resources.getNickName()); + user.setGender(resources.getGender()); + if (ObjectUtil.isNotEmpty(resources.getPassword())) + user.setPassword(SaSecureUtil.md5BySalt(resources.getPassword(), "salt")); + + userRepository.save(user); // 清除缓存 delCaches(user.getId(), user.getUsername()); - // 修改session -// flushSession(user); } @Override @@ -153,8 +143,6 @@ public class UserServiceImpl implements UserService { userRepository.save(user); // 清理缓存 delCaches(user.getId(), user.getUsername()); - // 修改session -// flushSession(user); } @Override @@ -184,7 +172,6 @@ public class UserServiceImpl implements UserService { public void updatePass(String username, String pass) { userRepository.updatePass(username, pass, new Date()); redisUtils.del("user::username:" + username); -// flushSession(userRepository.findByUsername(username)); } @Override @@ -200,7 +187,6 @@ public class UserServiceImpl implements UserService { FileUtil.del(oldPath); } @NotBlank String username = user.getUsername(); -// flushSession(user); return new HashMap(1) {{ put("avatar", file.getName()); }}; @@ -210,7 +196,6 @@ public class UserServiceImpl implements UserService { @Transactional(rollbackFor = Exception.class) public void updateEmail(String username, String email) { userRepository.updateEmail(username, email); -// flushSession(userRepository.findByUsername(username)); } @Override @@ -239,17 +224,6 @@ public class UserServiceImpl implements UserService { */ public void delCaches(Long id, String username) { redisUtils.del(CacheKey.USER_ID + id); -// flushCache(username); } - /** - * 清理 登陆时 用户缓存信息 - * - * @param user / - */ -// private void flushSession(User user) { -// UserDto userDto = this.findByName(user.getUsername()); -// List permissionList = roleService.getPermissionList(userDto.getId().toString()); -// flushSessionUtil.flushSessionInfo(userDto, permissionList); -// } } diff --git a/lms/nladmin-ui/src/views/login.vue b/lms/nladmin-ui/src/views/login.vue index 976355e..a2092fe 100644 --- a/lms/nladmin-ui/src/views/login.vue +++ b/lms/nladmin-ui/src/views/login.vue @@ -2,7 +2,7 @@