lyhzzz пре 2 месеци
родитељ
комит
47232f0a07

+ 1 - 0
src/main/java/com/fdkankan/ucenter/common/constants/ResultCode.java

@@ -24,6 +24,7 @@ public enum ResultCode {
     email_submit(500009, "邮件已提交"),
     email_submit_error(500010, "邮件发送失败"),
     USER_EXSIT(500011, "用户已存在"),
+    url_exprix(500012, "链接已过期"),
 
 
     ;

+ 3 - 2
src/main/java/com/fdkankan/ucenter/controller/ContactUsController.java

@@ -8,6 +8,7 @@ import com.fdkankan.ucenter.entity.ContactUs;
 import com.fdkankan.ucenter.entity.ContactUsPoint;
 import com.fdkankan.ucenter.geo.IPUtils;
 import com.fdkankan.ucenter.service.IContactUsService;
+import com.fdkankan.ucenter.vo.response.LoginVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -38,8 +39,8 @@ public class ContactUsController extends BaseController {
     }
 
     @GetMapping("/callBack/{uuid}")
-    public void callBack(@PathVariable String uuid){
-        contactUsService.callBack(uuid,response);
+    public Result callBack(@PathVariable String uuid){
+        return Result.success(contactUsService.callBack(uuid));
     }
 
     @PostMapping("/point")

+ 2 - 1
src/main/java/com/fdkankan/ucenter/service/IContactUsService.java

@@ -3,6 +3,7 @@ package com.fdkankan.ucenter.service;
 import com.fdkankan.ucenter.entity.ContactUs;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.ucenter.entity.ContactUsPoint;
+import com.fdkankan.ucenter.vo.response.LoginVo;
 import org.springframework.http.ResponseEntity;
 
 import javax.servlet.http.HttpServletResponse;
@@ -20,7 +21,7 @@ public interface IContactUsService extends IService<ContactUs> {
 
     void submit(ContactUs contactUs);
 
-    void callBack(String email, HttpServletResponse response);
+    LoginVo callBack(String email);
 
     void point(ContactUsPoint contactUsPoint);
 }

+ 22 - 24
src/main/java/com/fdkankan/ucenter/service/impl/ContactUsServiceImpl.java

@@ -89,35 +89,37 @@ public class ContactUsServiceImpl extends ServiceImpl<IContactUsMapper, ContactU
     }
 
     @Override
-    public void callBack(String uuid, HttpServletResponse response) {
-        String redirectUrl =ucenterConfig.getContactUsRedirectUrl();
+    public LoginVo callBack(String uuid) {
         String rediskey = String.format(RedisKeyUtil.CONTACT_US_KEY,uuid);
         String rediskey2 = null;
+        if(!redisUtil.hasKey(rediskey)){
+            throw new BusinessException(ResultCode.url_exprix);
+        }
+
         try {
             if(redisUtil.hasKey(rediskey) ){
                 ContactUs contactUs = JSONObject.parseObject( redisUtil.get(rediskey),ContactUs.class);
                 contactUs.setCountry(IPUtils.getCountry(contactUs.getIpAddress()));
                 this.save(contactUs);
                 rediskey2 = String.format(RedisKeyUtil.CONTACT_US_KEY,contactUs.getEmail());
-                User user = userService.getByUserName(contactUs.getEmail());
-                if(user !=null){
-                    return;
+                User userEntity = userService.getByUserName(contactUs.getEmail());
+                if(userEntity == null){
+                    userEntity = new User();
+                    userEntity.setPassword(SecurityUtil.MD5(ucenterConfig.getContactUsDfPassword()));
+                    userEntity.setEmail(contactUs.getEmail());
+                    userEntity.setUserName(contactUs.getEmail());
+                    userEntity.setNickName(contactUs.getName());
+                    userEntity.setHead(ConstantUrl.DEFAULT_USER_HEAD);
+                    userEntity.setStatus(1);
+                    userEntity.setIsNotice(1);
+                    userEntity.setRecStatus("A");
+                    userEntity.setCreateTime(DateUserUtil.getDate(new Date()));
+                    userEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
+                    userEntity.setAgentKey("wherefor");
+                    userService.save(userEntity);
                 }
-                User userEntity = new User();
-                userEntity.setPassword(SecurityUtil.MD5(ucenterConfig.getContactUsDfPassword()));
-                userEntity.setEmail(contactUs.getEmail());
-                userEntity.setUserName(contactUs.getEmail());
-                userEntity.setNickName(contactUs.getName());
-                userEntity.setHead(ConstantUrl.DEFAULT_USER_HEAD);
-                userEntity.setStatus(1);
-                userEntity.setIsNotice(1);
-                userEntity.setRecStatus("A");
-                userEntity.setCreateTime(DateUserUtil.getDate(new Date()));
-                userEntity.setUpdateTime(DateUserUtil.getDate(new Date()));
-                userEntity.setAgentKey("wherefor");
-                userService.save(userEntity);
                 LoginVo login = loginService.login(userEntity);
-                response.setHeader("token", login.getToken());
+                return login;
             }
 
         }catch (Exception e){
@@ -127,12 +129,8 @@ public class ContactUsServiceImpl extends ServiceImpl<IContactUsMapper, ContactU
             if(rediskey2 != null){
                 redisUtil.del(rediskey2);
             }
-            try {
-                response.sendRedirect(redirectUrl);
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            }
         }
+        return null;
     }
 
     @Override