【7.1.6】增加重置秘钥功能

pull/23/head
fengshuonan 2021-11-26 17:06:04 +08:00
parent 195fe94c7a
commit 009d0b4544
3 changed files with 25 additions and 6 deletions

View File

@ -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);
}

View File

@ -126,6 +126,7 @@ public interface CustomerService extends IService<Customer>, CustomerApi {
/**
*
*
* @return
* @author fengshuonan
* @date 2021/7/20 10:44
*/

View File

@ -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