From c246abab12009324e22b7afce3de84e2a77bc0e5 Mon Sep 17 00:00:00 2001 From: zyx <1029606625@qq.com> Date: Tue, 28 Feb 2023 19:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E9=AA=8C=E8=AF=81=E7=A0=81=E7=94=B1?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=80=BC=E6=9B=BF=E6=8D=A2=E4=B8=BA=E6=AD=A3?= =?UTF-8?q?=E5=BC=8F=E7=9A=84=E9=82=AE=E7=AE=B1=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/czyx007/reggie/controller/UserController.java | 12 +++++++----- src/main/resources/static/front/page/login.html | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/cn/czyx007/reggie/controller/UserController.java b/src/main/java/cn/czyx007/reggie/controller/UserController.java index cb3a86b..d0a805e 100644 --- a/src/main/java/cn/czyx007/reggie/controller/UserController.java +++ b/src/main/java/cn/czyx007/reggie/controller/UserController.java @@ -3,6 +3,8 @@ package cn.czyx007.reggie.controller; import cn.czyx007.reggie.bean.User; import cn.czyx007.reggie.common.R; import cn.czyx007.reggie.service.UserService; +import cn.czyx007.reggie.utils.SendEmailUtils; +import cn.czyx007.reggie.utils.ValidateCodeUtils; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; @@ -39,12 +41,12 @@ public class UserController { String phone = user.getPhone(); if (StringUtils.hasLength(phone)) { //生成随机的4位验证码 - //String code = ValidateCodeUtils.generateValidateCode4String(4); + String code = ValidateCodeUtils.generateValidateCode4String(4); //发送邮件验证码 - //SendEmailUtils.sendAuthCodeEmail(phone, code); + SendEmailUtils.sendAuthCodeEmail(phone, code); //将生成的验证码保存到Redis用于校验,并且设置有效期为5分钟 -// redisTemplate.opsForValue().set(phone, code, 5, TimeUnit.MINUTES); - redisTemplate.opsForValue().set(phone, "1234", 5, TimeUnit.MINUTES); + redisTemplate.opsForValue().set(phone, code, 5, TimeUnit.MINUTES); +// redisTemplate.opsForValue().set(phone, "1234", 5, TimeUnit.MINUTES); return R.success("验证码发送成功"); } return R.error("验证码发送失败"); @@ -59,7 +61,7 @@ public class UserController { //从Redis中获取保存的验证码 String codeInRedis = redisTemplate.opsForValue().get(phone); - codeInRedis = "1234"; + //codeInRedis = "1234"; //将两个验证码进行比对 if(StringUtils.hasLength(codeInRedis) && codeInRedis.equals(code)){ diff --git a/src/main/resources/static/front/page/login.html b/src/main/resources/static/front/page/login.html index 023f403..da098b9 100644 --- a/src/main/resources/static/front/page/login.html +++ b/src/main/resources/static/front/page/login.html @@ -65,7 +65,7 @@ if (regex.test(this.form.phone)) { this.msgFlag = false //this.form.code = (Math.random()*1000000).toFixed(0) - this.form.code = '1234' + //this.form.code = '1234' sendMsgApi({phone:this.form.phone}) }else{ this.msgFlag = true