mirror of https://gitee.com/stylefeng/roses
【7.1.6】增加重置秘钥功能
parent
195fe94c7a
commit
009d0b4544
|
@ -60,4 +60,14 @@ public interface CustomerApi {
|
|||
*/
|
||||
void updateMemberExpiryDate(Long customerId, Date expiryDate);
|
||||
|
||||
/**
|
||||
* 重置个人秘钥
|
||||
*
|
||||
* @param customerId 用户id
|
||||
* @return 用户秘钥
|
||||
* @author fengshuonan
|
||||
* @date 2021/7/20 10:44
|
||||
*/
|
||||
String createOrUpdateCustomerSecret(Long customerId);
|
||||
|
||||
}
|
||||
|
|
|
@ -126,6 +126,7 @@ public interface CustomerService extends IService<Customer>, CustomerApi {
|
|||
/**
|
||||
* 重置个人秘钥
|
||||
*
|
||||
* @return 用户秘钥
|
||||
* @author fengshuonan
|
||||
* @date 2021/7/20 10:44
|
||||
*/
|
||||
|
|
|
@ -49,7 +49,6 @@ import cn.stylefeng.roses.kernel.security.api.expander.SecurityConfigExpander;
|
|||
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -365,19 +364,28 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
|||
// 获取当前登录用户
|
||||
Long userId = LoginContext.me().getLoginUser().getUserId();
|
||||
|
||||
return this.createOrUpdateCustomerSecret(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createOrUpdateCustomerSecret(Long customerId) {
|
||||
if(customerId == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
// 重新生成秘钥
|
||||
String uuid = IdWorker.get32UUID();
|
||||
String randomString = RandomUtil.randomString(32);
|
||||
|
||||
// 更新用户秘钥
|
||||
LambdaUpdateWrapper<Customer> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.set(Customer::getSecretKey, uuid);
|
||||
wrapper.eq(Customer::getCustomerId, userId);
|
||||
wrapper.set(Customer::getSecretKey, randomString);
|
||||
wrapper.eq(Customer::getCustomerId, customerId);
|
||||
this.update(wrapper);
|
||||
|
||||
// 清除缓存中的用户信息
|
||||
customerInfoCacheOperatorApi.remove(String.valueOf(userId));
|
||||
customerInfoCacheOperatorApi.remove(String.valueOf(customerId));
|
||||
|
||||
return uuid;
|
||||
return randomString;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue