From 9f7007896f29b3b6fd05b35e31acb68462117617 Mon Sep 17 00:00:00 2001 From: panqihua Date: Fri, 10 Feb 2023 17:26:29 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E9=87=8D=E7=BD=AE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlatformStoreAccountController.java | 5 ++++ .../framework/config/SecurityConfig.java | 2 +- .../ruoyi/framework/service/ISmsService.java | 2 +- .../service/impl/SmsServiceImpl.java | 7 ++--- .../resources/mapper/PlatformSmsMapper.xml | 12 ++++---- .../store/service/IStoreAccountService.java | 2 ++ .../service/impl/StoreAccountServiceImpl.java | 29 +++++++++++++++++-- 7 files changed, 44 insertions(+), 15 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java index 2b40bba..43f6c27 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/platform/store/account/PlatformStoreAccountController.java @@ -47,6 +47,11 @@ public class PlatformStoreAccountController extends BaseController { return ajax; } + @PostMapping("resetpwd") + public AjaxResult resetpwd(@RequestBody StoreAccountVo account) { + return success(platformStoreAccountService.resetpwd(account)); + } + /** * 查询店家账号列表 */ diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index b472afe..2d76d24 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -120,7 +120,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter //平台短信发送 .antMatchers("/platform/public/sms/send").permitAll() //店家注册登录 - .antMatchers("/platform/store/account/register", "/platform/store/account/login").permitAll() + .antMatchers("/platform/store/account/register", "/platform/store/account/login", "/platform/store/account/resetpwd").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() .and() diff --git a/ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java index c4abbbb..d463dcd 100644 --- a/ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/ISmsService.java @@ -68,5 +68,5 @@ public interface ISmsService { */ public String send(String mobile, Integer integer); - public boolean existsSms(String mobile, String code); + public Sms querySms(String mobile, String code); } diff --git a/ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java index 032df70..5a26759 100644 --- a/ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java +++ b/ttsbg-framework/src/main/java/com/ruoyi/framework/service/impl/SmsServiceImpl.java @@ -95,20 +95,19 @@ public class SmsServiceImpl implements ISmsService { * @return */ @Override - public boolean existsSms(String mobile, String code) { + public Sms querySms(String mobile, String code) { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); Date d = new Date(); wrapper.select(Sms::getId).eq(Sms::getMobile, mobile).le(Sms::getSendtime, d).ge(Sms::getDeadtime, d); if (code != null) { wrapper.eq(Sms::getCode, code); } - Sms sms = smsMapper.selectOne(wrapper); - return sms != null; + return smsMapper.selectOne(wrapper); } @Override public String send(String mobile, Integer smsTime) { - if (existsSms(mobile, null)) { + if (querySms(mobile, null) != null) { return "短信发送过于频繁"; } else { String code = RandomStringUtils.randomNumeric(6); diff --git a/ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml b/ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml index 13f6bf6..8c1393e 100644 --- a/ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml +++ b/ttsbg-framework/src/main/resources/mapper/PlatformSmsMapper.xml @@ -19,7 +19,7 @@ from platform_sms - and mobile = #{mobile} @@ -30,12 +30,12 @@ - where id = #{id} - + insert into platform_sms id, @@ -57,7 +57,7 @@ - + update platform_sms mobile = #{mobile}, @@ -70,13 +70,13 @@ where id = #{id} - + delete from platform_sms where id = #{id} - + delete from platform_sms where id in #{id} diff --git a/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java b/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java index 082b1e8..fa8997c 100644 --- a/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java +++ b/ttsbg-store/src/main/java/com/ruoyi/store/service/IStoreAccountService.java @@ -70,4 +70,6 @@ public interface IStoreAccountService { * @return */ public StoreAccount selectAccountByMobile(String mobile); + + String resetpwd(StoreAccountVo account); } diff --git a/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java b/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java index d868e76..400cfbb 100644 --- a/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java +++ b/ttsbg-store/src/main/java/com/ruoyi/store/service/impl/StoreAccountServiceImpl.java @@ -2,6 +2,7 @@ package com.ruoyi.store.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.framework.domain.Sms; import com.ruoyi.framework.service.ISmsService; import com.ruoyi.store.domain.StoreAccount; import com.ruoyi.store.domain.vo.StoreAccountVo; @@ -25,7 +26,7 @@ public class StoreAccountServiceImpl implements IStoreAccountService { private StoreAccountMapper storeAccountMapper; @Autowired - private ISmsService SmsService; + private ISmsService smsService; /** * 查询店家账号 @@ -103,7 +104,10 @@ public class StoreAccountServiceImpl implements IStoreAccountService { @Override public String register(StoreAccountVo account) { //检查验证码是否有效 - if (SmsService.existsSms(account.getMobile(), account.getVerificationCode())) { + Sms sms = smsService.querySms(account.getMobile(), account.getVerificationCode()); + if (sms != null) { + sms.setDeadtime(new Date()); + smsService.updateSms(sms); if (selectAccountByMobile(account.getMobile()) != null) { return "手机号已注册"; } else { @@ -121,7 +125,26 @@ public class StoreAccountServiceImpl implements IStoreAccountService { } } } else { - return "无效验证码"; + return "手机号或验证码错误"; + } + } + + @Override + public String resetpwd(StoreAccountVo account) { + //检查验证码是否有效 + Sms sms = smsService.querySms(account.getMobile(), account.getVerificationCode()); + if (sms != null) { + sms.setDeadtime(new Date()); + smsService.updateSms(sms); + StoreAccount storeAccount = selectAccountByMobile(account.getMobile()); + storeAccount.setPassword(SecurityUtils.encryptPassword(account.getPassword())); + if (storeAccountMapper.updateById(storeAccount) > 0) { + return "密码重置成功"; + } else { + return "密码重置失败"; + } + } else { + return "手机号或验证码错误"; } } }