Переглянути джерело

Merge branch 'fix/register' of fxie/hichina2023 into master

sigpeg 1 рік тому
батько
коміт
5a241c75d2

+ 6 - 9
hichina-main-back/src/main/java/com/hichina/main/back/hichinamainback/controller/PublicRegisterController.java

@@ -4,8 +4,10 @@ package com.hichina.main.back.hichinamainback.controller;
 import com.hichina.main.back.hichinamainback.config.CustomAuthenticationProvider;
 import com.hichina.main.back.hichinamainback.config.EnableHichinaAutoLog;
 import com.hichina.main.back.hichinamainback.mapper.UserMapper;
+import com.hichina.main.back.hichinamainback.model.DTO.HiChinaResult;
 import com.hichina.main.back.hichinamainback.model.DTO.HichinaResponse;
 import com.hichina.main.back.hichinamainback.model.DTO.RegisterDTO;
+import com.hichina.main.back.hichinamainback.model.DTO.RegisterResult;
 import com.hichina.main.back.hichinamainback.model.User;
 import com.hichina.main.back.hichinamainback.utils.MailUtil;
 import org.slf4j.Logger;
@@ -39,15 +41,13 @@ public class PublicRegisterController {
 
     @PostMapping
     @EnableHichinaAutoLog(description = "register api")
-    public HichinaResponse register(@RequestBody RegisterDTO request){
-        HichinaResponse ret = new HichinaResponse();
+    public HiChinaResult<RegisterResult> register(@RequestBody RegisterDTO request){
 
         List<User> users = userMapper.findByEmail(request.getEmail());
 
         if(!users.isEmpty()){
-            ret.setOk(false);
-            ret.setMessage(String.format("User %s already exist",request.getEmail()));
-            return ret;
+            return HiChinaResult.error(String.format("User %s already exist",request.getEmail()),
+                    RegisterResult.exist());
         }
 
         String redisKey = java.util.UUID.randomUUID().toString();
@@ -62,10 +62,7 @@ public class PublicRegisterController {
             // LOG.info("Doing phone reg");
         }
 
-        ret.setOk(true);
-        ret.setMessage("Succeed insert into redis");
-
-        return ret;
+        return HiChinaResult.ok(RegisterResult.ok(request.getEmail()));
     }
 
     @PostMapping("/pushintodb/{regKey}")

+ 24 - 0
hichina-main-back/src/main/java/com/hichina/main/back/hichinamainback/model/DTO/RegisterResult.java

@@ -0,0 +1,24 @@
+package com.hichina.main.back.hichinamainback.model.DTO;
+
+import lombok.Data;
+
+@Data
+public class RegisterResult {
+
+    private boolean exist;
+
+    private String email;
+
+    public static RegisterResult exist() {
+        RegisterResult result = new RegisterResult();
+        result.setExist(true);
+        return result;
+    }
+
+    public static RegisterResult ok(String email) {
+        RegisterResult result = new RegisterResult();
+        result.setEmail(email);
+        return result;
+    }
+
+}

+ 7 - 2
hichina-main-front-mobile-first/src/pages/RegisterPage.vue

@@ -100,11 +100,16 @@ export default {
             console.log(response.data);
             if (response.data.ok == true) {
               gp.$generalNotify($q, true, "Succeed sending registering info");
+              gp.$goPage("/regsuccess");
             } else {
-              gp.$generalNotify($q, false, response.data.message);
+              $q.notify({
+                message: response.data.message,
+                color: "negative",
+                position: "center",
+                timeout: 2000,
+              });
             }
             gp.$hideLoading($q);
-            gp.$goPage("/regsuccess");
           })
           .catch((e) => {
             gp.$hideLoading($q);