【7.0.4】【c】更新C端用户注册等

pull/22/head
fengshuonan 2021-06-07 22:01:02 +08:00
parent 65710cc505
commit 2da22f7751
4 changed files with 61 additions and 22 deletions

View File

@ -46,7 +46,22 @@ public enum CustomerExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
CUSTOMER_STATUS_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + CustomerConstants.CUSTOMER_EXCEPTION_STEP_CODE + "02", "用户被禁用,请联系管理员!{}");
CUSTOMER_STATUS_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + CustomerConstants.CUSTOMER_EXCEPTION_STEP_CODE + "02", "用户被禁用,请联系管理员!{}"),
/**
*
*/
CUSTOMER_NOT_VERIFIED(RuleConstants.BUSINESS_ERROR_TYPE_CODE + CustomerConstants.CUSTOMER_EXCEPTION_STEP_CODE + "03", "用户未激活,请查阅注册邮箱中的激活邮件并点击链接!"),
/**
*
*/
ACCOUNT_REPEAT(RuleConstants.BUSINESS_ERROR_TYPE_CODE + CustomerConstants.CUSTOMER_EXCEPTION_STEP_CODE + "04", "账号重复,请更换账号"),
/**
*
*/
EMAIL_REPEAT(RuleConstants.BUSINESS_ERROR_TYPE_CODE + CustomerConstants.CUSTOMER_EXCEPTION_STEP_CODE + "05", "邮箱重复,请更换邮箱");
/**
*

View File

@ -28,7 +28,7 @@ public class CustomerConfigExpander {
* @date 2021/6/7 15:42
*/
public static String getRegMailContent() {
return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_REG_EMAIL_CONTENT", String.class, "感谢您注册Guns官方论坛请点击此激活链接激活您的账户<a href=\"http://localhost:8080/customer/active?verifyCode={}\">https://localhost:8080/customer/active?verifyCode={}</a>");
return ConfigContext.me().getSysConfigValueWithDefault("CUSTOMER_REG_EMAIL_CONTENT", String.class, "感谢您注册Guns官方论坛请点击此激活链接激活您的账户<a href=\"http://localhost:8080/customer/active?verifyCode={}\">http://localhost:8080/customer/active?verifyCode={} </a>");
}
}

View File

@ -2,7 +2,6 @@ package cn.stylefeng.roses.kernel.customer.modular.request;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
import cn.stylefeng.roses.kernel.validator.api.validators.unique.TableUniqueValue;
import lombok.Data;
import lombok.EqualsAndHashCode;
@ -31,12 +30,6 @@ public class CustomerRequest extends BaseRequest {
*/
@ChineseDescription("账号")
@NotBlank(message = "账号不能为空", groups = {add.class, edit.class, reg.class})
@TableUniqueValue(
message = "账号存在重复,请从新输入账号",
groups = reg.class,
tableName = "toc_customer",
columnName = "account",
idFieldName = "customer_id")
private String account;
/**
@ -60,12 +53,6 @@ public class CustomerRequest extends BaseRequest {
*/
@ChineseDescription("邮箱")
@NotBlank(message = "邮箱不能为空", groups = {reg.class})
@TableUniqueValue(
message = "邮箱存在重复,请从新输入邮箱",
groups = reg.class,
tableName = "toc_customer",
columnName = "email",
idFieldName = "customer_id")
private String email;
/**

View File

@ -55,6 +55,11 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
*/
private static final Object SESSION_OPERATE_LOCK = new Object();
/**
*
*/
private static final Object REG_LOCK = new Object();
@Resource
private MailSenderApi mailSenderApi;
@ -70,16 +75,20 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
@Override
@Transactional(rollbackFor = Exception.class)
public void reg(CustomerRequest customerRequest) {
synchronized (REG_LOCK) {
// 校验邮箱和账号是否重复
validateRepeat(customerRequest);
// 创建C端用户
Customer regCustomer = CustomerFactory.createRegCustomer(customerRequest);
// 创建C端用户
Customer regCustomer = CustomerFactory.createRegCustomer(customerRequest);
// 保存用户
this.save(regCustomer);
// 保存用户
this.save(regCustomer);
// 发送邮箱验证码
SendMailParam regEmailParam = CustomerFactory.createRegEmailParam(regCustomer.getEmail(), regCustomer.getVerifyCode());
mailSenderApi.sendMail(regEmailParam);
// 发送邮箱验证码
SendMailParam regEmailParam = CustomerFactory.createRegEmailParam(regCustomer.getEmail(), regCustomer.getVerifyCode());
mailSenderApi.sendMailHtml(regEmailParam);
}
}
@Override
@ -120,6 +129,11 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
throw new CustomerException(CustomerExceptionEnum.CUSTOMER_STATUS_ERROR, customer.getStatusFlag());
}
// 校验用户是否激活
if (!YesOrNotEnum.Y.getCode().equals(customer.getVerifiedFlag())) {
throw new CustomerException(CustomerExceptionEnum.CUSTOMER_NOT_VERIFIED);
}
// 获取LoginUser用于用户的缓存
LoginUser loginUser = CustomerFactory.createLoginUser(customer);
@ -236,4 +250,27 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
return queryWrapper;
}
/**
*
*
* @author fengshuonan
* @date 2021/6/7 21:43
*/
private void validateRepeat(CustomerRequest customerRequest) {
LambdaQueryWrapper<Customer> accountWrapper = new LambdaQueryWrapper<>();
accountWrapper.eq(Customer::getAccount, customerRequest.getAccount());
int count = this.count(accountWrapper);
if (count > 0) {
throw new CustomerException(CustomerExceptionEnum.ACCOUNT_REPEAT);
}
LambdaQueryWrapper<Customer> emailWrapper = new LambdaQueryWrapper<>();
emailWrapper.eq(Customer::getEmail, customerRequest.getEmail());
int emailCount = this.count(emailWrapper);
if (emailCount > 0) {
throw new CustomerException(CustomerExceptionEnum.EMAIL_REPEAT);
}
}
}