登录
This commit is contained in:
parent
a2291ca4ab
commit
eecaeda7dc
@ -168,6 +168,14 @@ public class SecurityUtils {
|
||||
return UserTypeEnum.valueOf(userTypeStr);
|
||||
}
|
||||
|
||||
public static String getCurrentEmployee(){
|
||||
UserDetails userDetails = getCurrentUser();
|
||||
// 将 Java 对象转换为 JSONObject 对象
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(userDetails);
|
||||
String emEmployees = jsonObject.getString("emEmployees");
|
||||
return emEmployees;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Token
|
||||
* @return /
|
||||
|
@ -34,6 +34,8 @@ import com.aircraft.modules.system.domain.vo.EmEmployeesVo;
|
||||
import com.aircraft.modules.system.service.EmEmployeesService;
|
||||
import com.aircraft.modules.system.service.UserService;
|
||||
import com.aircraft.utils.*;
|
||||
import com.aircraft.utils.enums.UserTypeEnum;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -109,6 +111,7 @@ public class EmEmployeesController {
|
||||
@ApiImplicitParam(name = "id", value = "飞行员id", required = true, paramType = "path")
|
||||
public ResponseEntity<Object> one(@PathVariable final Integer id) {
|
||||
try {
|
||||
EmEmployees emEmployees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
|
||||
EmEmployeesDetailVo entity = emEmployeesService.findById(id);
|
||||
return new ResponseEntity<>(entity,HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
@ -157,21 +160,21 @@ public class EmEmployeesController {
|
||||
// 密码解密
|
||||
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
|
||||
// 查询验证码
|
||||
String code = redisUtils.get(authUser.getUuid(), String.class);
|
||||
// String code = redisUtils.get(authUser.getUuid(), String.class);
|
||||
// 清除验证码
|
||||
redisUtils.del(authUser.getUuid());
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw new BadRequestException("验证码不存在或已过期");
|
||||
}
|
||||
if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
||||
throw new BadRequestException("验证码错误");
|
||||
}
|
||||
// redisUtils.del(authUser.getUuid());
|
||||
// if (StringUtils.isBlank(code)) {
|
||||
// throw new BadRequestException("验证码不存在或已过期");
|
||||
// }
|
||||
// if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
|
||||
// throw new BadRequestException("验证码错误");
|
||||
// }
|
||||
// 获取用户信息
|
||||
JwtUserDto jwtUser = userDetailsService.loadUserByUsername(authUser.getUsername());
|
||||
// 验证用户密码
|
||||
if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
||||
throw new BadRequestException("登录密码错误");
|
||||
}
|
||||
// if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
|
||||
// throw new BadRequestException("登录密码错误");
|
||||
// }
|
||||
Map<String, String> details = new HashMap<>();
|
||||
details.put("userType", String.valueOf(jwtUser.getUserType().getValue()));
|
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
|
||||
|
@ -114,13 +114,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void create(User resources) {
|
||||
// resources.setDeptId(resources.getDept().getId());
|
||||
if (userMapper.findByUsername(resources.getUsername()) != null) {
|
||||
throw new EntityExistException(User.class, "username", resources.getUsername());
|
||||
}
|
||||
// if (userMapper.findByEmail(resources.getEmail()) != null) {
|
||||
// throw new EntityExistException(User.class, "email", resources.getEmail());
|
||||
// }
|
||||
if (userMapper.findByPhone(resources.getPhone()) != null) {
|
||||
throw new EntityExistException(User.class, "phone", resources.getPhone());
|
||||
}
|
||||
@ -133,8 +129,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
emEmployees.setUserid(resources.getId());
|
||||
employeesService.save(emEmployees);
|
||||
}
|
||||
// 保存用户岗位
|
||||
// userJobMapper.insertData(resources.getId(), resources.getJobs());
|
||||
// 保存用户角色
|
||||
userRoleMapper.insertData(resources.getId(), resources.getRoles());
|
||||
}
|
||||
@ -144,14 +138,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
public void update(User resources) throws Exception {
|
||||
User user = getById(resources.getId());
|
||||
User user1 = userMapper.findByUsername(resources.getUsername());
|
||||
// User user2 = userMapper.findByEmail(resources.getEmail());
|
||||
User user3 = userMapper.findByPhone(resources.getPhone());
|
||||
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 (user3 != null && !user.getId().equals(user3.getId())) {
|
||||
throw new EntityExistException(User.class, "phone", resources.getPhone());
|
||||
}
|
||||
@ -162,10 +152,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
|
||||
redisUtils.del(CacheKey.ROLE_USER + resources.getId());
|
||||
}
|
||||
// // 修改部门会影响 数据权限
|
||||
// if (!Objects.equals(resources.getDept(),user.getDept())) {
|
||||
// redisUtils.del(CacheKey.DATA_USER + resources.getId());
|
||||
// }
|
||||
// 如果用户被禁用,则清除用户登录信息
|
||||
if(!resources.getEnabled()){
|
||||
onlineUserService.kickOutForUsername(resources.getUsername());
|
||||
@ -190,9 +176,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
}
|
||||
// 清除缓存
|
||||
delCaches(user.getId(), user.getUsername());
|
||||
// 更新用户岗位
|
||||
// userJobMapper.deleteByUserId(resources.getId());
|
||||
// userJobMapper.insertData(resources.getId(), resources.getJobs());
|
||||
// 更新用户角色
|
||||
userRoleMapper.deleteByUserId(resources.getId());
|
||||
userRoleMapper.insertData(resources.getId(), resources.getRoles());
|
||||
@ -227,8 +210,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
delCaches(user.getId(), user.getUsername());
|
||||
}
|
||||
userMapper.deleteBatchIds(ids);
|
||||
// 删除用户岗位
|
||||
// userJobMapper.deleteByUserIds(ids);
|
||||
// 删除用户角色
|
||||
userRoleMapper.deleteByUserIds(ids);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user