From 247f19f6c3f17c2ac2f37b55c7d0550731f31ffe Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Thu, 25 Mar 2021 17:24:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 screen-api/src/main/java/com/moral/api/controller/LoginController.java |   95 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/LoginController.java b/screen-api/src/main/java/com/moral/api/controller/LoginController.java
index 6b1a304..cb1862a 100644
--- a/screen-api/src/main/java/com/moral/api/controller/LoginController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/LoginController.java
@@ -6,22 +6,29 @@
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 
+import java.io.IOException;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ObjectUtils;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.moral.api.entity.Group;
-import com.moral.api.service.GroupService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.moral.api.entity.SysConfig;
+import com.moral.api.service.SysConfigService;
 import com.moral.api.service.UserService;
+import com.moral.constant.Constants;
 import com.moral.constant.ResponseCodeEnum;
 import com.moral.constant.ResultMessage;
+import com.moral.pojo.VerificationCode;
+import com.moral.util.KaptchaUtils;
 import com.moral.util.TokenUtils;
-import com.moral.util.WebUtils;
 
 @Slf4j
 @Api(tags = {"������"})
@@ -32,53 +39,81 @@
     private UserService userService;
 
     @Autowired
-    private GroupService groupService;
+    private SysConfigService sysConfigService;
 
     @ApiOperation(value = "������", notes = "������")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "account", value = "������", required = false, paramType = "query", dataType = "String"),
-            @ApiImplicitParam(name = "password", value = "������", required = false, paramType = "query", dataType = "String")
-    })
     @RequestMapping(value = "login", method = RequestMethod.POST)
-    public ResultMessage login(HttpServletRequest request) {
-        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
+    public ResultMessage login(@RequestBody Map<String, Object> parameters) {
         if (!(parameters.containsKey("account") && parameters.containsKey("password"))) {
             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
         }
         Map<String, Object> result = userService.login(parameters);
         if (!result.containsKey("data")) {
-            return ResultMessage.fail(Integer.parseInt(result.get("code").toString()), result.get("msg").toString());
+            return ResultMessage.fail((int) result.get("code"), (String) result.get("msg"));
         }
         return ResultMessage.ok(result.get("data"));
     }
 
-    @ApiOperation(value = "������", notes = "������")
+    @ApiOperation(value = "������", notes = "������")
     @RequestMapping(value = "logout", method = RequestMethod.POST)
-    public ResultMessage logout(HttpServletRequest request) {
-        Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
-        if (!parameters.containsKey("uid")) {
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "uid", value = "������id", required = true, paramType = "query", dataType = "String"),
+            @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String")
+    })
+    public ResultMessage logout(String uid, HttpServletRequest request) {
+        if (uid == null) {
             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
         }
-        String userId = parameters.get("uid").toString();
         String token = request.getHeader("token");
-        TokenUtils.destoryToken(userId, token);
+        TokenUtils.destoryToken(uid, token);
         return ResultMessage.ok();
     }
 
-    @ApiOperation(value = "���������", notes = "���������")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "groupName", value = "������", required = true, paramType = "query", dataType = "String")
-    })
-    @RequestMapping(value = "addGroup", method = RequestMethod.POST)
-    private ResultMessage addGroup(Group group, HttpServletRequest request) {
-        String currentUserId = request.getHeader("uid");
-        Map<String, Object> map = groupService.addGroup(group, currentUserId);
-        String msg = map.get("msg").toString();
-        boolean flag = Boolean.parseBoolean(map.get("flag").toString());
-        if (flag) {
-            return ResultMessage.ok(msg);
+    /**
+     * @Description: ���������������������������
+     * @Param: []
+     * @return: com.moral.constant.ResultMessage
+     * @Author: ���������
+     * @Date: 2021/3/18
+     */
+
+    @ApiOperation(value = "���������������������������", notes = "���������������������������")
+    @RequestMapping(value = "verificationCode/config", method = RequestMethod.GET)
+    public void verifyConfig(HttpServletResponse response) {
+        QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("type", Constants.VERIFICATION_TYPE);
+        SysConfig sysConfig = sysConfigService.getOne(queryWrapper);
+        String code = sysConfig.getCode();
+        if (Constants.VERIFICATION_OPEN_CODE.equals(code)) {
+            try {
+                response.sendRedirect("/verificationCode/get");
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
-        return ResultMessage.fail(msg);
     }
 
+    @ApiOperation(value = "���������������", notes = "���������������")
+    @RequestMapping(value = "verificationCode/get", method = RequestMethod.GET)
+    public ResultMessage getVerificationCode() {
+        VerificationCode verificationCode = null;
+        try {
+            verificationCode = KaptchaUtils.createVerificationCode();
+        } catch (IOException e) {
+            log.error(e.getMessage());
+        }
+        if (ObjectUtils.isEmpty(verificationCode))
+            return ResultMessage.fail();
+        return ResultMessage.ok(verificationCode);
+    }
+
+    @ApiOperation(value = "���������������", notes = "���������������")
+    @RequestMapping(value = "verificationCode/verify", method = RequestMethod.GET)
+    public ResultMessage gverifyVerificationCode(VerificationCode verificationCode) {
+        if (!verificationCode.valid())
+            return ResultMessage.fail();
+        if (KaptchaUtils.verify(verificationCode))
+            return ResultMessage.ok();
+        return ResultMessage.fail();
+    }
 }

--
Gitblit v1.8.0