limingming 1 éve
szülő
commit
a358de8065

+ 51 - 0
rouyi-api/src/main/java/com/info666/infraredRemote/controller/UserLoginController.java

@@ -0,0 +1,51 @@
+package com.info666.infraredRemote.controller;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.domain.UserInfo;
+import com.ruoyi.system.domain.vo.SmsResponseVo;
+import com.ruoyi.system.service.UserInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.regex.Pattern;
+
+/**
+ * @Author: LiMingMing
+ * @Date: 2023/8/1 16:09
+ * @Description: TODO
+ **/
+@RestController
+@RequestMapping("/api/v1/user")
+public class UserLoginController {
+
+    @Autowired
+    private UserInfoService userInfoService;
+    @Autowired
+    private RedisCache redisCache;
+
+    @PostMapping("/login")
+    public R<SmsResponseVo> sendSms(@RequestBody UserInfo param) {
+        if (StringUtils.isEmpty(param.getUserPhone()) || Pattern.matches("^1[3-9]\\d{9}$\n",param.getUserPhone())){
+            return R.fail("手机号格式不正确");
+        }
+        if (StringUtils.isEmpty(param.getCode())){
+            return R.fail("验证不能为空");
+        }
+        UserInfo userInfo = userInfoService.getOne(new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserPhone,param.getUserPhone()),false);
+        if (userInfo == null){
+            param.setCreateTime(DateUtils.getNowDate());
+            userInfoService.save(param);
+        }
+        if (!redisCache.getCacheObject(param.getKeyCode()).equals(param.getCode())){
+            return R.fail("验证码错误");
+        }
+        return R.ok();
+    }
+}

+ 15 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/UserInfo.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.domain;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.ruoyi.common.annotation.Excel;
 import lombok.Data;
@@ -39,4 +40,18 @@ public class UserInfo implements Serializable {
 
     /** 更新时间 */
     private Date updateTime;
+
+
+    /**
+     * 验证码的key
+     */
+    @TableField(exist = false)
+    private String keyCode;
+
+    /**
+     * 验证码的
+     */
+    @TableField(exist = false)
+    private String code;
+
 }