优化短信登录配置

This commit is contained in:
阿沐 2022-10-17 12:12:39 +08:00
parent 50f8921318
commit 575340ec49
5 changed files with 50 additions and 9 deletions

View File

@ -0,0 +1,38 @@
package net.maku.security.config;
import net.maku.api.module.message.SmsApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
/**
* 登录配置信息
*
* @author 阿沐 babamu@126.com
*/
@Configuration
public class LoginConfig {
@Bean
@ConditionalOnMissingBean
SmsApi smsApi() {
return new SmsApi() {
@Override
public boolean send(String mobile, Map<String, String> params) {
return false;
}
@Override
public boolean sendCode(String mobile, String key, String value) {
return false;
}
@Override
public boolean verifyCode(String mobile, String code) {
return false;
}
};
}
}

View File

@ -47,7 +47,10 @@ public class SysAuthController {
@PostMapping("send/code")
@Operation(summary = "发送短信验证码")
public Result<String> sendCode(String mobile) {
sysAuthService.sendCode(mobile);
boolean flag = sysAuthService.sendCode(mobile);
if (!flag) {
return Result.error("短信发送失败!");
}
return Result.ok();
}

View File

@ -30,7 +30,7 @@ public interface SysAuthService {
*
* @param mobile 手机号
*/
void sendCode(String mobile);
boolean sendCode(String mobile);
/**
* 退出登录

View File

@ -95,7 +95,7 @@ public class SysAuthServiceImpl implements SysAuthService {
}
@Override
public void sendCode(String mobile) {
public boolean sendCode(String mobile) {
// 生成6位验证码
String code = RandomUtil.randomNumbers(6);
@ -105,7 +105,7 @@ public class SysAuthServiceImpl implements SysAuthService {
}
// 发送短信
smsApi.sendCode(mobile, "code", code);
return smsApi.sendCode(mobile, "code", code);
}
@Override

View File

@ -25,11 +25,11 @@
<!-- <artifactId>maku-module-quartz</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>net.maku</groupId>
<artifactId>maku-module-message</artifactId>
<version>${revision}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>net.maku</groupId>-->
<!-- <artifactId>maku-module-message</artifactId>-->
<!-- <version>${revision}</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-springdoc-ui</artifactId>