修改密码
This commit is contained in:
parent
ffb3dbac36
commit
311a9724cf
@ -98,6 +98,21 @@ public class UserCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理用户缓存信息
|
||||
* 用户信息变更时
|
||||
* @param userName 用户名
|
||||
*/
|
||||
@Async
|
||||
public void cleanEmployeesCache(String userName) {
|
||||
// 转小写
|
||||
userName = StringUtils.lowerCase(userName);
|
||||
if (StringUtils.isNotEmpty(userName)) {
|
||||
// 清除数据
|
||||
redisUtils.del(LoginProperties.aCacheKey + userName);
|
||||
}
|
||||
}
|
||||
|
||||
public void addCustomerCache(String username, JwtUserDto customerDto) {
|
||||
// 转小写
|
||||
username = StringUtils.lowerCase(username);
|
||||
|
@ -2,9 +2,15 @@ package com.aircraft.modules.system.controller;
|
||||
|
||||
|
||||
import com.aircraft.annotation.Log;
|
||||
import com.aircraft.config.properties.RsaProperties;
|
||||
import com.aircraft.exception.BadRequestException;
|
||||
import com.aircraft.modules.system.domain.CnCustomer;
|
||||
import com.aircraft.modules.system.domain.EmEmployees;
|
||||
import com.aircraft.modules.system.domain.dto.UserPassVo;
|
||||
import com.aircraft.modules.system.service.CnCustomerService;
|
||||
import com.aircraft.utils.PageResult;
|
||||
import com.aircraft.utils.RsaUtils;
|
||||
import com.aircraft.utils.SecurityUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -112,5 +118,22 @@ public class CnCustomerController {
|
||||
return new ResponseEntity<>(Collections.emptyList(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("修改密码")
|
||||
@PostMapping(value = "/updatePass")
|
||||
public ResponseEntity<Object> updateUserPass(@RequestBody UserPassVo passVo) throws Exception {
|
||||
CnCustomer customer = entityService.findByUserName(SecurityUtils.getCurrentUsername());
|
||||
String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getOldPass());
|
||||
String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getNewPass());
|
||||
|
||||
if(!passwordEncoder.matches(oldPass, customer.getPassword())){
|
||||
throw new BadRequestException("修改失败,旧密码错误");
|
||||
}
|
||||
if(passwordEncoder.matches(newPass, customer.getPassword())){
|
||||
throw new BadRequestException("新密码不能与旧密码相同");
|
||||
}
|
||||
entityService.updatePass(customer.getUsername(),passwordEncoder.encode(newPass));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -126,17 +126,17 @@ public class EmEmployeesController {
|
||||
@ApiOperation("修改密码")
|
||||
@PostMapping(value = "/updatePass")
|
||||
public ResponseEntity<Object> updateUserPass(@RequestBody UserPassVo passVo) throws Exception {
|
||||
User user = userService.findByName(SecurityUtils.getCurrentUsername());
|
||||
EmEmployees emEmployees = emEmployeesService.findByUserName(SecurityUtils.getCurrentUsername());
|
||||
String oldPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getOldPass());
|
||||
String newPass = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey,passVo.getNewPass());
|
||||
|
||||
if(!passwordEncoder.matches(oldPass, user.getPassword())){
|
||||
if(!passwordEncoder.matches(oldPass, emEmployees.getPassword())){
|
||||
throw new BadRequestException("修改失败,旧密码错误");
|
||||
}
|
||||
if(passwordEncoder.matches(newPass, user.getPassword())){
|
||||
if(passwordEncoder.matches(newPass, emEmployees.getPassword())){
|
||||
throw new BadRequestException("新密码不能与旧密码相同");
|
||||
}
|
||||
userService.updatePass(user.getUsername(),passwordEncoder.encode(newPass));
|
||||
emEmployeesService.updatePass(emEmployees.getUsername(),passwordEncoder.encode(newPass));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ package com.aircraft.modules.system.mapper;
|
||||
import com.aircraft.modules.system.domain.CnCustomer;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -15,4 +17,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface CnCustomerMapper extends BaseMapper<CnCustomer> {
|
||||
|
||||
@Select("update cn_customer set password = #{password} where username = #{username}")
|
||||
void updatePass(@Param("username") String username, @Param("password") String password);
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ package com.aircraft.modules.system.mapper;
|
||||
|
||||
import com.aircraft.modules.system.domain.EmEmployees;
|
||||
import com.aircraft.modules.system.domain.dto.EmEmployeesQueryCriteria;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -28,6 +30,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author lhb
|
||||
@ -43,4 +46,7 @@ public interface EmEmployeesMapper extends BaseMapper<EmEmployees> {
|
||||
List<EmEmployeesDetailVo> findByExample(@Param(Constants.WRAPPER) QueryWrapper<EmEmployeesDetailVo> queryWrapper, Page page);
|
||||
|
||||
void deleteBatchIds(@Param("ids") List<Long> ids);
|
||||
|
||||
@Select("update em_employees set password = #{password} where username = #{username}")
|
||||
void updatePass(@Param("username") String username, @Param("password") String password);
|
||||
}
|
@ -40,4 +40,11 @@ public interface CnCustomerService extends IService<CnCustomer> {
|
||||
CnCustomer findByPhone(String phone);
|
||||
|
||||
CnCustomer findByUserName(String username);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param username 用户名
|
||||
* @param encryptPassword 密码
|
||||
*/
|
||||
void updatePass(String username, String encryptPassword);
|
||||
}
|
||||
|
@ -108,4 +108,18 @@ public interface EmEmployeesService extends IService<EmEmployees> {
|
||||
* @return List<EmEmployees>
|
||||
*/
|
||||
List<EmEmployees> obtainEmployeesByIds(List<Long> orderInitiatorIds);
|
||||
|
||||
/**
|
||||
* 用户名查询飞行员
|
||||
* @param currentUsername
|
||||
* @return
|
||||
*/
|
||||
EmEmployees findByUserName(String currentUsername);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @param username 用户名
|
||||
* @param encryptPassword 密码
|
||||
*/
|
||||
void updatePass(String username, String encryptPassword);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.aircraft.modules.system.service.impl;
|
||||
|
||||
import com.aircraft.base.BaseEntity;
|
||||
import com.aircraft.modules.security.service.UserCacheManager;
|
||||
import com.aircraft.modules.system.domain.CnCustomer;
|
||||
import com.aircraft.modules.system.mapper.CnCustomerMapper;
|
||||
import com.aircraft.modules.system.service.CnCustomerService;
|
||||
@ -10,6 +11,7 @@ import com.aircraft.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
@ -22,9 +24,12 @@ import java.util.List;
|
||||
* @author cli
|
||||
* @since 2025-07-09
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CnCustomerServiceImpl extends ServiceImpl<CnCustomerMapper, CnCustomer> implements CnCustomerService {
|
||||
|
||||
private final UserCacheManager userCacheManager;
|
||||
|
||||
@Override
|
||||
public List<CnCustomer> list(CnCustomer example) {
|
||||
return this.list(buildWrapper(example));
|
||||
@ -53,6 +58,12 @@ public class CnCustomerServiceImpl extends ServiceImpl<CnCustomerMapper, CnCusto
|
||||
return this.baseMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePass(String username, String encryptPassword) {
|
||||
this.baseMapper.updatePass(username, encryptPassword);
|
||||
userCacheManager.cleanEmployeesCache(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建查询
|
||||
*
|
||||
|
@ -16,6 +16,7 @@
|
||||
package com.aircraft.modules.system.service.impl;
|
||||
|
||||
import com.aircraft.base.BaseEntity;
|
||||
import com.aircraft.modules.security.service.UserCacheManager;
|
||||
import com.aircraft.modules.system.domain.EmEmployees;
|
||||
import com.aircraft.modules.system.domain.vo.EmEmployeesDetailVo;
|
||||
import com.aircraft.modules.system.domain.vo.EmEmployeesVo;
|
||||
@ -53,6 +54,7 @@ public class EmEmployeesServiceImpl extends ServiceImpl<EmEmployeesMapper, EmEmp
|
||||
private final EmAreaService areaService;
|
||||
private final EmScenicService scenicService;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
private final UserCacheManager userCacheManager;
|
||||
|
||||
@Override
|
||||
public PageResult<EmEmployees> queryAll(EmEmployeesQueryCriteria criteria, Page<Object> page){
|
||||
@ -92,6 +94,21 @@ public class EmEmployeesServiceImpl extends ServiceImpl<EmEmployeesMapper, EmEmp
|
||||
return this.list(Wrappers.lambdaQuery(EmEmployees.class).in(EmEmployees::getId,orderInitiatorIds));
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmEmployees findByUserName(String currentUsername) {
|
||||
QueryWrapper<EmEmployees> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda()
|
||||
.eq(EmEmployees::getUsername,currentUsername)
|
||||
.eq(EmEmployees::getDelFlag,0);
|
||||
return this.emEmployeesMapper.selectOne(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePass(String username, String encryptPassword) {
|
||||
emEmployeesMapper.updatePass(username, encryptPassword);
|
||||
userCacheManager.cleanEmployeesCache(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(EmEmployees resources) {
|
||||
|
Loading…
Reference in New Issue
Block a user