From 336b1ee18a1d1ff4230e8edb7faa43e3b5ef1ffc Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 08 九月 2023 08:50:35 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/crm/common/web/AuthController.java |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/crm/common/web/AuthController.java b/src/main/java/com/zy/crm/common/web/AuthController.java
index 1c436f6..4b8fe69 100644
--- a/src/main/java/com/zy/crm/common/web/AuthController.java
+++ b/src/main/java/com/zy/crm/common/web/AuthController.java
@@ -8,6 +8,8 @@
 import com.core.common.Cools;
 import com.core.common.R;
 import com.core.exception.CoolException;
+import com.zy.crm.manager.service.SmsCodeService;
+import com.zy.crm.manager.utils.SmsUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.transaction.annotation.Transactional;
@@ -53,9 +55,11 @@
     private RolePermissionService rolePermissionService;
     @Autowired
     private HostService hostService;
+    @Autowired
+    private SmsCodeService smsCodeService;
 
     @RequestMapping("/login.action")
-    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "鐧诲綍")
+    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "瀵嗙爜鐧诲綍")
     public R loginAction(String username, String password){
         if (username.equals("super") && password.equals(Cools.md5(superPwd))) {
             Map<String, Object> res = new HashMap<>();
@@ -72,6 +76,9 @@
         if (user.getStatus()!=1){
             return R.parse(CodeRes.USER_10002);
         }
+        if (Cools.isEmpty(user.getPassword())){
+            return R.parse(CodeRes.USER_10004);
+        }
         if (!user.getPassword().equals(password)){
             return R.parse(CodeRes.USER_10003);
         }
@@ -92,6 +99,39 @@
         return R.ok(res);
     }
 
+    @RequestMapping("/smsLogin.action")
+    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "鐭俊鐧诲綍")
+    public R smsLoginAction(String phone, String code){
+        EntityWrapper<User> userWrapper = new EntityWrapper<>();
+        userWrapper.eq("mobile", phone);
+        User user = userService.selectOne(userWrapper);
+        if (Cools.isEmpty(user)){
+            return R.parse(CodeRes.USER_10001);
+        }
+        if (user.getStatus()!=1){
+            return R.parse(CodeRes.USER_10002);
+        }
+        boolean verify = smsCodeService.verifySmsCode(phone, code);
+        if (!verify) {
+            return R.parse(CodeRes.USER_10005);
+        }
+        String token = Cools.enToken(System.currentTimeMillis() + phone, code);
+        userLoginService.delete(new EntityWrapper<UserLogin>().eq("user_id", user.getId()));
+        UserLogin userLogin = new UserLogin();
+        userLogin.setUserId(user.getId());
+        userLogin.setToken(token);
+        userLogin.setCreateTime(new Date());
+        if (user.getRoleId() == 1) {
+            userLogin.setHostId(hostService.getTop1().getId());
+        }
+        userLoginService.insert(userLogin);
+        Map<String, Object> res = new HashMap<>();
+        res.put("username", user.getUsername());
+        res.put("nickname", user.getNickname());
+        res.put("token", token);
+        return R.ok(res);
+    }
+
     @RequestMapping("/show/host.action")
     @ManagerAuth
     public R showHosts() {

--
Gitblit v1.9.1