Browse Source

VppTeamServiceImpl 类邮件逻辑删除

wangpenghui 10 months ago
parent
commit
9c903e5bf8

+ 6 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/controller/VppKeyFileController.java

@@ -2,8 +2,10 @@ package cn.kdan.pdf.tech.core.controller;
 
 import cn.kdan.pdf.tech.core.service.VppKeyFileService;
 import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * @author ComPDFKit-WPH 2024/1/2
@@ -17,5 +19,9 @@ public class VppKeyFileController {
 
     private final VppKeyFileService vppKeyFileService;
 
+    @PostMapping("/parseKeyFile")
+    public void parseKeyFile(MultipartFile keyFile, boolean updateOrInit) {
+        vppKeyFileService.parseKeyFile(keyFile, updateOrInit);
+    }
 
 }

+ 9 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/params/VppMemberRegisterParam.java

@@ -37,4 +37,13 @@ public class VppMemberRegisterParam {
     private Boolean isSuperAdmin;
 
     private String area;
+
+    /**
+     * 是否不校验code
+     * <p>
+     * true:不校验
+     * <p>
+     * false or null:校验
+     */
+    private Boolean codeFlag;
 }

+ 18 - 11
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppMemberServiceImpl.java

@@ -282,17 +282,24 @@ public class VppMemberServiceImpl implements VppMemberService {
         //密码位数
         checkPwdLength(param.getPassword());
         //邮件验证码错误
-        if (!authService.checkVerifyCode(CaptchaActionEnum.USER_REGISTER.value(), param.getEmail(), param.getVerifyCode())) {
-            throw new BackendRuntimeException(VppMemberConstant.EXCEPTION_MSG_FALSE_CODE);
-        } else {
-            // 验证成功删除验证码缓存
-            redisUtils.hdel(AuthConstant.VERIFY_CODE_KEY + CaptchaActionEnum.USER_REGISTER.value(), param.getEmail());
-        }
-        if(!StringUtils.isEmpty(param.getInviteEmailCode())&&!authService.checkVerifyCode(CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN.value(), param.getEmail(), param.getInviteEmailCode())) {
-            throw new BackendRuntimeException(VppMemberConstant.EXCEPTION_MSG_FALSE_EMAIL_CODE);
-        }else{
-            // 验证成功删除验证码缓存
-            redisUtils.hdel(AuthConstant.VERIFY_CODE_KEY + CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN.value(), param.getEmail());
+        /*
+         * 是否不校验code
+         * true:不校验
+         * false or null:校验
+         */
+        if(ObjectUtils.isEmpty(param.getCodeFlag()) || !param.getCodeFlag()) {
+            if (!authService.checkVerifyCode(CaptchaActionEnum.USER_REGISTER.value(), param.getEmail(), param.getVerifyCode())) {
+                throw new BackendRuntimeException(VppMemberConstant.EXCEPTION_MSG_FALSE_CODE);
+            } else {
+                // 验证成功删除验证码缓存
+                redisUtils.hdel(AuthConstant.VERIFY_CODE_KEY + CaptchaActionEnum.USER_REGISTER.value(), param.getEmail());
+            }
+            if(!StringUtils.isEmpty(param.getInviteEmailCode())&&!authService.checkVerifyCode(CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN.value(), param.getEmail(), param.getInviteEmailCode())) {
+                throw new BackendRuntimeException(VppMemberConstant.EXCEPTION_MSG_FALSE_EMAIL_CODE);
+            }else{
+                // 验证成功删除验证码缓存
+                redisUtils.hdel(AuthConstant.VERIFY_CODE_KEY + CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN.value(), param.getEmail());
+            }
         }
     }
 

+ 82 - 66
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppTeamServiceImpl.java

@@ -8,6 +8,7 @@ import cn.kdan.pdf.tech.core.enums.LicenseCodeStatusEnum;
 import cn.kdan.pdf.tech.core.enums.RoleEnum;
 import cn.kdan.pdf.tech.core.mapper.ext.ExtVppTeamMapper;
 import cn.kdan.pdf.tech.core.model.*;
+import cn.kdan.pdf.tech.core.params.VppMemberRegisterParam;
 import cn.kdan.pdf.tech.core.pojo.dto.CreateTeamDTO;
 import cn.kdan.pdf.tech.core.pojo.dto.EditTeamDTO;
 import cn.kdan.pdf.tech.core.pojo.vo.*;
@@ -52,6 +53,8 @@ import java.util.stream.Collectors;
 @Transactional
 public class VppTeamServiceImpl implements VppTeamService {
 
+    private final static String DEFAULT_PASSWORD = "123456";
+
     @Resource
     private VppMemberService vppMemberService;
     @Resource
@@ -70,17 +73,17 @@ public class VppTeamServiceImpl implements VppTeamService {
     private AuthService authService;
     @Resource
     private VppCompanyService companyService;
-    @Value("${webUrl}")
-    private String  webUrl;
-    @Value("${createUrl}")
-    private String  createUrl;
-    @Value("${loginUrl}")
-    private String  loginUrl;
-    // 运营后台地址,图片地址emailImagesUrl
-    @Value("${readerproUrl}")
-    private String readerproUrl;
-    @Value("${emailImagesUrl}")
-    private String emailImagesUrl;
+//    @Value("${webUrl}")
+//    private String  webUrl;
+//    @Value("${createUrl}")
+//    private String  createUrl;
+//    @Value("${loginUrl}")
+//    private String  loginUrl;
+//    // 运营后台地址,图片地址emailImagesUrl
+//    @Value("${readerproUrl}")
+//    private String readerproUrl;
+//    @Value("${emailImagesUrl}")
+//    private String emailImagesUrl;
     @Autowired
     private RedisUtils<String, String> redisUtils;
     private static final ThreadPoolExecutor SEND_MAIL_THREAD_POOL = new ThreadPoolExecutor( Runtime.getRuntime().availableProcessors(),
@@ -287,29 +290,31 @@ public class VppTeamServiceImpl implements VppTeamService {
             VppCompany vppCompany = vppCompanyService.getById(superAdmin.getCompanyId());
             if(vppMember.getRole().equals("3") && StringUtils.isEmpty(vppMember.getDigestPassword())) {
                 actionEnum = CaptchaActionEnum.JOIN_TEAM_FOR_ADD_ADMIN_NO_PASSWORD;
-                String pwd = CommonUtils.generateVerifyCode();
+                String pwd = DEFAULT_PASSWORD;
                 vppMember.setDigestPassword(new RSAUtils().encrypt(pwd));
                 vppMemberService.update(vppMember);
                 //若管理员已注册账号,则仅发放邀请加入团队邮件;邮件带上memberId和用户的TeamId集合(emailTeamList)和code
-                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
-                //用户邮箱 超管邮箱 用户邮箱 密码 链接
-                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(),
-                        vppMember.getEmail(), pwd, url);
+//                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
+//                //用户邮箱 超管邮箱 用户邮箱 密码 链接
+//                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(),
+//                        vppMember.getEmail(), pwd, url);
+                this.enterTeam(vppMember.getId(),Collections.singletonList(newVppTeam.getId()),actionEnum.value(),code);
             } else {
                 actionEnum = CaptchaActionEnum.JOIN_TEAM_FOR_ADD_ADMIN;
-                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
-                //用户邮箱 超管邮箱 链接
-                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(), url);
+//                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
+//                //用户邮箱 超管邮箱 链接
+//                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(), url);
+                this.enterTeam(vppMember.getId(),Collections.singletonList(newVppTeam.getId()),actionEnum.value(),code);
             }
-            //发送邮件
-            // 替换图片动态地址和取消订阅链接
-            text = text.replace("emailImagesUrl", emailImagesUrl).replace("cancelEmailUrl", readerproUrl + "/unsubscribe?email=" + vppMember.getEmail());
-            String finalText = text;
-            ThreadPoolSingleUtil.getInstance().excute(() -> {
-//                if(emailUtils.sendMail(actionEnum.subject(), finalText, Collections.singletonList(vppMember.getEmail()))){
-//                    redisUtils.hset(AuthConstant.VERIFY_CODE_KEY + actionEnum.value(), vppMember.getEmail(), code, AuthConstant.INVITE_VERIFY_CODE_KEY_EXPIRE_TIME);
-//                }
-            });
+//            //发送邮件
+//            // 替换图片动态地址和取消订阅链接
+//            text = text.replace("emailImagesUrl", emailImagesUrl).replace("cancelEmailUrl", readerproUrl + "/unsubscribe?email=" + vppMember.getEmail());
+//            String finalText = text;
+//            ThreadPoolSingleUtil.getInstance().excute(() -> {
+////                if(emailUtils.sendMail(actionEnum.subject(), finalText, Collections.singletonList(vppMember.getEmail()))){
+////                    redisUtils.hset(AuthConstant.VERIFY_CODE_KEY + actionEnum.value(), vppMember.getEmail(), code, AuthConstant.INVITE_VERIFY_CODE_KEY_EXPIRE_TIME);
+////                }
+//            });
         }
     }
 
@@ -497,29 +502,31 @@ public class VppTeamServiceImpl implements VppTeamService {
             VppCompany vppCompany = vppCompanyService.getById(member.getCompanyId());
             if(vppMember.getRole().equals("3") && StringUtils.isEmpty(vppMember.getDigestPassword())) {
                 actionEnum = CaptchaActionEnum.JOIN_TEAM_FOR_ADD_ADMIN_NO_PASSWORD;
-                String pwd = CommonUtils.generateVerifyCode();
+                String pwd = DEFAULT_PASSWORD;
                 vppMember.setDigestPassword(new RSAUtils().encrypt(pwd));
                 vppMemberService.update(vppMember);
                 //若管理员已注册账号,则仅发放邀请加入团队邮件;邮件带上memberId和用户的TeamId集合(emailTeamList)和code
-                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
-                //用户邮箱 超管邮箱 用户邮箱 密码 链接
-                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(),
-                        vppMember.getEmail(), pwd, url);
+//                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
+//                //用户邮箱 超管邮箱 用户邮箱 密码 链接
+//                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(),
+//                        vppMember.getEmail(), pwd, url);
+                this.enterTeam(vppMember.getId(), Collections.singletonList(vppTeam.getId()),actionEnum.value(),code);
             } else {
                 actionEnum = CaptchaActionEnum.JOIN_TEAM_FOR_ADD_ADMIN;
-                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
-                //用户邮箱 超管邮箱 链接
-                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(), url);
+//                String url = webUrl + loginUrl + "?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
+//                //用户邮箱 超管邮箱 链接
+//                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(), url);
+                this.enterTeam(vppMember.getId(), Collections.singletonList(vppTeam.getId()),actionEnum.value(),code);
             }
             //发送邮件
-            // 替换图片动态地址和取消订阅链接
-            text = text.replace("emailImagesUrl", emailImagesUrl).replace("cancelEmailUrl", readerproUrl + "/unsubscribe?email=" + vppMember.getEmail());
-            String finalText = text;
-            ThreadPoolSingleUtil.getInstance().excute(() -> {
-//                if(emailUtils.sendMail(actionEnum.subject(), finalText, Collections.singletonList(vppMember.getEmail()))){
-//                    redisUtils.hset(AuthConstant.VERIFY_CODE_KEY + actionEnum.value(), vppMember.getEmail(), code, AuthConstant.INVITE_VERIFY_CODE_KEY_EXPIRE_TIME);
-//                }
-            });
+//            // 替换图片动态地址和取消订阅链接
+//            text = text.replace("emailImagesUrl", emailImagesUrl).replace("cancelEmailUrl", readerproUrl + "/unsubscribe?email=" + vppMember.getEmail());
+//            String finalText = text;
+//            ThreadPoolSingleUtil.getInstance().excute(() -> {
+////                if(emailUtils.sendMail(actionEnum.subject(), finalText, Collections.singletonList(vppMember.getEmail()))){
+////                    redisUtils.hset(AuthConstant.VERIFY_CODE_KEY + actionEnum.value(), vppMember.getEmail(), code, AuthConstant.INVITE_VERIFY_CODE_KEY_EXPIRE_TIME);
+////                }
+//            });
         }
     }
 
@@ -695,11 +702,26 @@ public class VppTeamServiceImpl implements VppTeamService {
         String code = CommonUtils.generateVerifyCode();
         if (ObjectUtils.isEmpty(vppMember)) {
             VppCompany vppCompany = vppCompanyService.getById(member.getCompanyId());
-            actionEnum = CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN;
+//            actionEnum = CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN;
             //发送注册邮件,前端根据注册页面表单信息和teamIds,还有code去进行注册
-            String url = webUrl + createUrl +"?teamIds=" + teamString + "&code=" + code + "&action=" + actionEnum.value() + "&account=" + account;
-            //用户邮箱 超管邮箱  链接
-            text = String.format(CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN.text(), account, vppCompany.getName(), url, account);
+//            String url = webUrl + createUrl +"?teamIds=" + teamString + "&code=" + code + "&action=" + actionEnum.value() + "&account=" + account;
+//            //用户邮箱 超管邮箱  链接
+//            text = String.format(CaptchaActionEnum.USER_REGISTER_FOR_ADD_ADMIN.text(), account, vppCompany.getName(), url, account);
+            VppMemberRegisterParam param = new VppMemberRegisterParam();
+            param.setEmail(account);
+            param.setUsername(account);
+//            param.setArea();
+            param.setCompany(vppCompany.getName());
+            param.setTeamIds(teamIds);
+            param.setPassword(DEFAULT_PASSWORD);
+            param.setConfirmPassword(DEFAULT_PASSWORD);
+            param.setCodeFlag(true);
+//            param.setIndustry();
+//            param.setInviteEmailCode();
+//            param.setIsSuperAdmin();
+//            param.setVerifyCode();
+            vppMemberService.create(param);
+
         } else {
             VppCompany vppCompany = vppCompanyService.getById(vppMember.getCompanyId());
             // 用户管理的所有团队提取备用
@@ -719,30 +741,24 @@ public class VppTeamServiceImpl implements VppTeamService {
             //如果已经注册账号需要判断该账号是普通用户还是管理员,如果是普通用户的话给一个密码
             if(vppMember.getRole().contains("3")&&StringUtils.isEmpty(vppMember.getDigestPassword())){
                 actionEnum = CaptchaActionEnum.JOIN_TEAM_FOR_ADD_ADMIN_NO_PASSWORD;
-                String pwd = CommonUtils.generateVerifyCode();
+                String pwd = DEFAULT_PASSWORD;
                 vppMember.setDigestPassword(new RSAUtils().encrypt(pwd));
                 vppMemberService.update(vppMember);
                 //若管理员已注册账号,则仅发放邀请加入团队邮件;邮件带上memberId和用户的TeamId集合(emailTeamList)和code
-                String url = webUrl + loginUrl +"?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
-                //用户邮箱 超管邮箱 用户邮箱 密码 链接
-                text = String.format(actionEnum.text(),vppMember.getFullName(),
-                        vppCompany.getName(), vppMember.getEmail(), pwd, url);
+//                String url = webUrl + loginUrl +"?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
+//                //用户邮箱 超管邮箱 用户邮箱 密码 链接
+//                text = String.format(actionEnum.text(),vppMember.getFullName(),
+//                        vppCompany.getName(), vppMember.getEmail(), pwd, url);
+
+                this.enterTeam(vppMember.getId(),teamIds,actionEnum.value(),code);
             }else{
                 actionEnum = CaptchaActionEnum.JOIN_TEAM_FOR_ADD_ADMIN;
-                String url = webUrl + loginUrl +"?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
-                //用户邮箱 超管邮箱 链接
-                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(), url);
+//                String url = webUrl + loginUrl +"?teamIds=" + teamString + "&code=" + code + "&memberId=" + vppMember.getId() + "&action=" + actionEnum.value();
+//                //用户邮箱 超管邮箱 链接
+//                text = String.format(actionEnum.text(), vppMember.getFullName(), vppCompany.getName(), url);
+                this.enterTeam(vppMember.getId(),teamIds,actionEnum.value(),code);
             }
         }
-        // 替换图片动态地址和取消订阅链接
-        text = text.replace("emailImagesUrl", emailImagesUrl).replace("cancelEmailUrl", readerproUrl + "/unsubscribe?email=" + account);
-        String finalText = text;
-        SEND_MAIL_THREAD_POOL.submit(() -> {
-            //发送邮件
-//            if(emailUtils.sendMail(actionEnum.subject(), finalText, Collections.singletonList(account))){
-//                redisUtils.hset(AuthConstant.VERIFY_CODE_KEY + actionEnum.value(), account, code, AuthConstant.INVITE_VERIFY_CODE_KEY_EXPIRE_TIME);
-//            }
-        });
     }
 
 
@@ -833,7 +849,7 @@ public class VppTeamServiceImpl implements VppTeamService {
         VppMember member = vppMemberService.getById(memberId);
         CaptchaActionEnum captchaActionEnum = CaptchaActionEnum.getEnumByValue(action);
         //检查验证码
-        authService.checkVerifyCodeByAction(captchaActionEnum, member.getEmail(), code);
+//        authService.checkVerifyCodeByAction(captchaActionEnum, member.getEmail(), code);
         List<VppRTeamMemberRole> rTeamMemberRoles = vppRTeamMemberRoleService.listByMemberId(memberId);
         Map<String, List<VppRTeamMemberRole>> teamMap = rTeamMemberRoles.stream().collect(Collectors.groupingBy(VppRTeamMemberRole::getTeamId));
         teamIds.forEach(teamId -> {

+ 2 - 2
pdf-tech-core/src/main/resources/application-pro.yml

@@ -12,9 +12,9 @@ security:
 
 jdbc:
   driverClassName: org.postgresql.Driver
-  url: jdbc:postgresql://34.145.212.19:5432/pdf-store-prod
+  url: jdbc:postgresql://localhost:5432/db_larger1
   username: postgres
-  password: uiddd123..89
+  password: postgres
 
 
 redis: