support sms login
This commit is contained in:
@@ -213,7 +213,7 @@
|
||||
<dependency>
|
||||
<groupId>com.imyeyu.font.icon</groupId>
|
||||
<artifactId>timi-icon-font</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -240,11 +240,6 @@
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-mysql</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.e2ins.ms.notify</groupId>
|
||||
<artifactId>e2ins-msg-notify-service-sdk</artifactId>
|
||||
<version>0.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.tencentcloudapi</groupId>
|
||||
<artifactId>tencentcloud-sdk-java-sms</artifactId>
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.imyeyu.api.config;
|
||||
|
||||
import com.e2ins.ms.notify.SmsNotifyService;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.imyeyu.utils.Time;
|
||||
@@ -32,12 +29,6 @@ public class BeanConfig {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SmsNotifyService smsNotifyService() {
|
||||
// TODO
|
||||
return new SmsNotifyService(null, null);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Yaml yaml() {
|
||||
return new Yaml();
|
||||
|
||||
@@ -7,11 +7,16 @@ import com.imyeyu.api.modules.common.entity.Notify;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||
import com.imyeyu.api.modules.common.service.SmsService;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.api.modules.user.service.UserService;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.spring.annotation.AOPLog;
|
||||
import com.imyeyu.spring.annotation.CaptchaValid;
|
||||
import com.imyeyu.spring.annotation.RequestRateLimit;
|
||||
import com.imyeyu.spring.annotation.RequiredToken;
|
||||
import com.imyeyu.spring.bean.CaptchaData;
|
||||
import com.imyeyu.spring.bean.Page;
|
||||
import com.imyeyu.spring.bean.PageResult;
|
||||
import com.imyeyu.spring.util.ResponseView;
|
||||
@@ -37,6 +42,8 @@ import java.util.stream.Stream;
|
||||
@RequestMapping("/notify")
|
||||
public class NotifyController {
|
||||
|
||||
|
||||
private final SmsService smsService;
|
||||
private final UserService userService;
|
||||
private final NotifyService service;
|
||||
private final UserLoginService userLoginService;
|
||||
@@ -104,6 +111,14 @@ public class NotifyController {
|
||||
service.cancel(id);
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@CaptchaValid
|
||||
@RequestRateLimit(value = 1, inSeconds = 59)
|
||||
@PostMapping("/sms/captcha/create")
|
||||
public String smsCaptchaCreate(@RequestBody CaptchaData<Notify> req) {
|
||||
return smsService.captchaCreate(req.getData());
|
||||
}
|
||||
|
||||
/// 查询当前用户的站内通知
|
||||
///
|
||||
/// @param page 分页参数
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.imyeyu.spring.annotation.table.AutoUUID;
|
||||
import com.imyeyu.spring.annotation.table.Id;
|
||||
import com.imyeyu.spring.entity.Creatable;
|
||||
@@ -28,7 +29,7 @@ public class BaseQueueEntity implements IDEntity<String>, Creatable, Destroyable
|
||||
protected String data;
|
||||
|
||||
/** 参数 */
|
||||
protected String args;
|
||||
protected JsonNode args;
|
||||
|
||||
/** 发送去向 */
|
||||
protected String sendTo;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.imyeyu.api.modules.common.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.imyeyu.api.TimiServerAPI;
|
||||
import com.imyeyu.api.modules.common.service.BaseQueueService;
|
||||
import com.imyeyu.api.modules.common.service.HTTPQueueService;
|
||||
@@ -103,7 +104,7 @@ public class NotifyDetail extends UUIDEntity {
|
||||
|
||||
/** 参数 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
private String args;
|
||||
private JsonNode args;
|
||||
|
||||
/** 发送来源 */
|
||||
@JsonView(ResponseView.Public.class)
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
//package com.imyeyu.api.modules.common.service;
|
||||
//
|
||||
//import com.e2ins.ms.notify.entity.Notify;
|
||||
//import com.e2ins.ms.notify.entity.NotifyDetail;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// *
|
||||
// * @author 夜雨
|
||||
// * @since 2026-05-14 12:12
|
||||
// */
|
||||
//public interface SmsService {
|
||||
//
|
||||
// /**
|
||||
// * 创建短信验证码通知
|
||||
// *
|
||||
// * @param detail 通知
|
||||
// * @return 通知详情 ID
|
||||
// */
|
||||
// String captchaCreate(Notify detail);
|
||||
//
|
||||
// /**
|
||||
// * 校验短信验证码
|
||||
// *
|
||||
// * @param detailId 通知详情 ID
|
||||
// * @param captcha 请求验证码
|
||||
// * @return 通知详情
|
||||
// */
|
||||
// NotifyDetail captchaVerify(String detailId, String captcha);
|
||||
//}
|
||||
package com.imyeyu.api.modules.common.service;
|
||||
|
||||
import com.imyeyu.api.modules.common.entity.Notify;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-05-14 12:12
|
||||
*/
|
||||
public interface SmsService {
|
||||
|
||||
/**
|
||||
* 创建短信验证码通知
|
||||
*
|
||||
* @param detail 通知
|
||||
* @return 通知详情 ID
|
||||
*/
|
||||
String captchaCreate(Notify detail);
|
||||
|
||||
/**
|
||||
* 校验短信验证码
|
||||
*
|
||||
* @param detailId 通知详情 ID
|
||||
* @param captcha 请求验证码
|
||||
* @return 通知详情
|
||||
*/
|
||||
NotifyDetail captchaVerify(String detailId, String captcha);
|
||||
}
|
||||
|
||||
+2
-8
@@ -1,6 +1,5 @@
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
@@ -11,9 +10,9 @@ import com.imyeyu.api.modules.common.service.SmsQueueService;
|
||||
import com.imyeyu.api.modules.common.util.QCloudSmsProxy;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.utils.Regex;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
|
||||
import com.tencentcloudapi.sms.v20210111.models.SendStatus;
|
||||
import com.imyeyu.utils.Regex;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -56,12 +55,7 @@ public class SmsQueueServiceImplement extends AbstractQueueService<SmsQueue, Not
|
||||
@Override
|
||||
protected void doSend(SmsQueue queue) {
|
||||
try {
|
||||
String[] args = new String[0];
|
||||
if (queue.getArgs() != null && !queue.getArgs().isBlank()) {
|
||||
JsonNode argsNode = jackson.readTree(queue.getArgs());
|
||||
TimiException.requiredTrue(argsNode != null && argsNode.isArray(), "短信参数必须是数组");
|
||||
args = jackson.treeToValue(argsNode, String[].class);
|
||||
}
|
||||
String[] args = jackson.treeToValue(queue.getArgs(), String[].class);
|
||||
SendSmsResponse response = smsProxy.send(queue.getSendTo(), queue.getTemplateId(), args);
|
||||
TimiException.required(response, "未找到短信响应");
|
||||
SendStatus[] statusSet = response.getSendStatusSet();
|
||||
|
||||
+82
-82
@@ -1,82 +1,82 @@
|
||||
//package com.imyeyu.api.modules.common.service.implement;
|
||||
//
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
//import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
//import com.imyeyu.api.modules.common.entity.Notify;
|
||||
//import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
//import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
//import com.imyeyu.api.modules.common.service.NotifyService;
|
||||
//import com.imyeyu.api.modules.common.service.SmsService;
|
||||
//import com.imyeyu.java.bean.timi.TimiException;
|
||||
//import com.imyeyu.utils.Regex;
|
||||
//import com.imyeyu.utils.Text;
|
||||
//import com.imyeyu.utils.Time;
|
||||
//import lombok.RequiredArgsConstructor;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// *
|
||||
// * @author 夜雨
|
||||
// * @since 2026-05-14 12:12
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Service
|
||||
//@RequiredArgsConstructor
|
||||
//public class SmsServiceImplement implements SmsService {
|
||||
//
|
||||
// @Value("${spring.profiles.active}")
|
||||
// private String env;
|
||||
//
|
||||
// private final NotifyQueueConfig config;
|
||||
// private final ObjectMapper jackson;
|
||||
//
|
||||
// private final NotifyService notifyService;
|
||||
// private final NotifyDetailService notifyDetailService;
|
||||
//
|
||||
// @Override
|
||||
// public String captchaCreate(Notify notify) {
|
||||
// NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||
// TimiException.required(notify.getAppId(), "not found appId");
|
||||
//
|
||||
// NotifyDetail detail = notify.getDetailList().getFirst();
|
||||
//
|
||||
// TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, detail.getSendTo()), "invalid mobilePhone", "captcha.sms.invalid_mobile_phone");
|
||||
//
|
||||
// String code = Text.randomString("0123456789", 6);
|
||||
// if (!env.equalsIgnoreCase("prod")) {
|
||||
// code = "123456";
|
||||
// }
|
||||
// detail.setMsgType(NotifyDetail.MsgType.SMS);
|
||||
// detail.setTemplateId(captchaConf.getTemplateId());
|
||||
// detail.setArgs(jackson.valueToTree(List.of(code, captchaConf.getTtlMinute())));
|
||||
//
|
||||
// notifyService.create(notify);
|
||||
// return notifyDetailService.listByNotifyId(notify.getId()).getFirst().getId();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public NotifyDetail captchaVerify(String detailId, String captcha) {
|
||||
// AppConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||
//
|
||||
// NotifyDetail detail = notifyDetailService.get(detailId);
|
||||
// if (Time.M * captchaConf.getTtlMinute() < Time.now() - detail.getSendAt()) {
|
||||
// throw new AppException(ResultCode.ARG_EXPIRED).msgKey("captcha.expired");
|
||||
// }
|
||||
// if (detail.getArgs() instanceof ArrayNode array) {
|
||||
// String dbCaptcha = array.get(captchaConf.getArgIndex()).asText();
|
||||
// if (!dbCaptcha.equalsIgnoreCase(captcha)) {
|
||||
// throw new AppException(ResultCode.RESULT_BAD).msgKey("captcha.invalid");
|
||||
// }
|
||||
// } else {
|
||||
// throw new AppException(ResultCode.ERROR, "not array args");
|
||||
// }
|
||||
// detail.setNotify(notifyService.get(detail.getNotifyId()));
|
||||
// return detail;
|
||||
// }
|
||||
//}
|
||||
package com.imyeyu.api.modules.common.service.implement;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.imyeyu.api.modules.common.config.NotifyQueueConfig;
|
||||
import com.imyeyu.api.modules.common.entity.Notify;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.service.NotifyDetailService;
|
||||
import com.imyeyu.api.modules.common.service.NotifyService;
|
||||
import com.imyeyu.api.modules.common.service.SmsService;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.utils.Regex;
|
||||
import com.imyeyu.utils.Text;
|
||||
import com.imyeyu.utils.Time;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2026-05-14 12:12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SmsServiceImplement implements SmsService {
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String env;
|
||||
|
||||
private final NotifyQueueConfig config;
|
||||
private final ObjectMapper jackson;
|
||||
|
||||
private final NotifyService notifyService;
|
||||
private final NotifyDetailService notifyDetailService;
|
||||
|
||||
@Override
|
||||
public String captchaCreate(Notify notify) {
|
||||
NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||
|
||||
NotifyDetail detail = notify.getDetailList().getFirst();
|
||||
|
||||
TimiException.requiredTrue(Regex.isMatch(Regex.MOBILE_PHONE, detail.getSendTo()), "invalid mobilePhone");
|
||||
|
||||
String code = Text.randomString("0123456789", 6);
|
||||
if (!env.equalsIgnoreCase("prod")) {
|
||||
code = "123456";
|
||||
}
|
||||
detail.setMsgType(NotifyDetail.MsgType.SMS);
|
||||
detail.setTemplateId(captchaConf.getTemplateId());
|
||||
detail.setArgs(jackson.valueToTree(List.of(code, captchaConf.getTtlMinute())));
|
||||
|
||||
notifyService.create(notify);
|
||||
return notifyDetailService.listByNotifyId(notify.getId()).getFirst().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NotifyDetail captchaVerify(String detailId, String captcha) {
|
||||
NotifyQueueConfig.Sms.Captcha captchaConf = config.getSms().getCaptcha();
|
||||
|
||||
NotifyDetail detail = notifyDetailService.get(detailId);
|
||||
if (Time.M * captchaConf.getTtlMinute() < Time.now() - detail.getSendAt()) {
|
||||
throw new TimiException(TimiCode.ARG_EXPIRED, "验证码过期");
|
||||
}
|
||||
if (detail.getArgs() instanceof ArrayNode array) {
|
||||
String dbCaptcha = array.get(captchaConf.getArgIndex()).asText();
|
||||
if (!dbCaptcha.equalsIgnoreCase(captcha)) {
|
||||
throw new TimiException(TimiCode.RESULT_BAD, "验证码错误");
|
||||
}
|
||||
} else {
|
||||
throw new TimiException(TimiCode.ERROR, "not array args");
|
||||
}
|
||||
detail.setNotify(notifyService.get(detail.getNotifyId()));
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.imyeyu.api.modules.common.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
///
|
||||
///
|
||||
/// @author 夜雨
|
||||
/// @since 2026-08-21 17:59
|
||||
@Data
|
||||
public class SmsCaptchaVerifyRequest {
|
||||
|
||||
private String detailId;
|
||||
|
||||
private String captcha;
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import com.imyeyu.api.annotation.RequireCorePermission;
|
||||
import com.imyeyu.api.bean.CorePermissionCode;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.common.service.SmsService;
|
||||
import com.imyeyu.api.modules.common.vo.SmsCaptchaVerifyRequest;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
import com.imyeyu.api.modules.user.service.UserService;
|
||||
@@ -50,6 +52,7 @@ import java.util.List;
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
private final SmsService smsService;
|
||||
private final UserService userService;
|
||||
private final UserLoginService userLoginService;
|
||||
private final AttachmentService attachmentService;
|
||||
@@ -133,6 +136,15 @@ public class UserController {
|
||||
return userLoginService.login(TimiSpring.getToken(), userLoginService.getRequireLoginUserId());
|
||||
}
|
||||
|
||||
@AOPLog
|
||||
@JsonView(ResponseView.Public.class)
|
||||
@RequestRateLimit
|
||||
@CaptchaValid
|
||||
@PostMapping("/login/sms")
|
||||
public LoginResponse loginBySms(@RequestBody SmsCaptchaVerifyRequest request) {
|
||||
return userLoginService.loginBySms(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新当前用户资料
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.imyeyu.api.modules.user.service;
|
||||
|
||||
import com.e2ins.ms.notify.vo.sms.CaptchaVerifyReq;
|
||||
import com.imyeyu.api.modules.common.vo.SmsCaptchaVerifyRequest;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
||||
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||
@@ -24,7 +24,7 @@ public interface UserLoginService {
|
||||
|
||||
LoginResponse login(String token, String userId);
|
||||
|
||||
LoginResponse loginBySms(CaptchaVerifyReq req);
|
||||
LoginResponse loginBySms(SmsCaptchaVerifyRequest request);
|
||||
|
||||
/**
|
||||
* 根据令牌获取用户
|
||||
|
||||
+12
-19
@@ -1,13 +1,13 @@
|
||||
package com.imyeyu.api.modules.user.service.implement;
|
||||
|
||||
import com.e2ins.ms.notify.SmsNotifyService;
|
||||
import com.e2ins.ms.notify.bean.NotifyDetail;
|
||||
import com.e2ins.ms.notify.vo.sms.CaptchaVerifyReq;
|
||||
import com.imyeyu.api.config.dbsource.TimiServerDBConfig;
|
||||
import com.imyeyu.api.modules.common.entity.Attachment;
|
||||
import com.imyeyu.api.modules.common.entity.NotifyDetail;
|
||||
import com.imyeyu.api.modules.common.entity.Setting;
|
||||
import com.imyeyu.api.modules.common.service.AttachmentService;
|
||||
import com.imyeyu.api.modules.common.service.SettingService;
|
||||
import com.imyeyu.api.modules.common.service.SmsService;
|
||||
import com.imyeyu.api.modules.common.vo.SmsCaptchaVerifyRequest;
|
||||
import com.imyeyu.api.modules.user.bean.BootstrapData;
|
||||
import com.imyeyu.api.modules.user.entity.User;
|
||||
import com.imyeyu.api.modules.user.service.UserLoginService;
|
||||
@@ -16,7 +16,6 @@ import com.imyeyu.api.modules.user.service.UserService;
|
||||
import com.imyeyu.api.modules.user.vo.LoginRequest;
|
||||
import com.imyeyu.api.modules.user.vo.LoginResponse;
|
||||
import com.imyeyu.java.TimiJava;
|
||||
import com.imyeyu.java.bean.timi.TimiCode;
|
||||
import com.imyeyu.java.bean.timi.TimiException;
|
||||
import com.imyeyu.spring.TimiSpring;
|
||||
import com.imyeyu.spring.util.Redis;
|
||||
@@ -30,7 +29,6 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@@ -47,10 +45,10 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
private static final String PHONE_VERIFY_KEY_PREFIX = "USER:PHONE:VERIFY:";
|
||||
private static final long PHONE_VERIFY_CODE_TTL = Time.M * 5;
|
||||
|
||||
private final SmsService smsService;
|
||||
private final UserService userService;
|
||||
private final SettingService settingService;
|
||||
private final UserRoleService userRoleService;
|
||||
private final SmsNotifyService smsNotifyService;
|
||||
private final AttachmentService attachmentService;
|
||||
|
||||
private final Redis<String, String> redisUserToken;
|
||||
@@ -104,20 +102,15 @@ public class UserLoginServiceImplement implements UserLoginService, TimiJava {
|
||||
|
||||
|
||||
@Override
|
||||
public LoginResponse loginBySms(CaptchaVerifyReq req) {
|
||||
try {
|
||||
NotifyDetail detail = smsNotifyService.captchaVerify(req);
|
||||
// 无报错即成功
|
||||
User user = userService.getByPhoneNo(detail.getSendTo());
|
||||
if (!user.isValidPhone()) {
|
||||
user.setPhoneNoVerifyAt(Time.now());
|
||||
userService.update(user);
|
||||
}
|
||||
return login(UUID.randomUUID().toString(), user.getId());
|
||||
} catch (IOException e) {
|
||||
log.error("login by sms error", e);
|
||||
throw new TimiException(TimiCode.ERROR, "验证短信失败");
|
||||
public LoginResponse loginBySms(SmsCaptchaVerifyRequest request) {
|
||||
NotifyDetail detail = smsService.captchaVerify(request.getDetailId(), request.getCaptcha());
|
||||
// 无报错即成功
|
||||
User user = userService.getByPhoneNo(detail.getSendTo());
|
||||
if (!user.isValidPhone()) {
|
||||
user.setPhoneNoVerifyAt(Time.now());
|
||||
userService.update(user);
|
||||
}
|
||||
return login(UUID.randomUUID().toString(), user.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user