|
|
@@ -9,8 +9,10 @@ import com.nexo.common.core.web.controller.BaseController;
|
|
|
import com.nexo.common.mail.config.properties.MailProperties;
|
|
|
import com.nexo.common.mail.utils.MailUtils;
|
|
|
import com.nexo.common.redis.utils.RedisUtils;
|
|
|
+import com.nexo.system.api.RemoteConfigService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.validation.constraints.NotBlank;
|
|
|
import java.time.Duration;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 邮件功能
|
|
|
@@ -33,6 +36,9 @@ public class SysEmailController extends BaseController {
|
|
|
|
|
|
private final MailProperties mailProperties;
|
|
|
|
|
|
+ @DubboReference
|
|
|
+ private final RemoteConfigService remoteConfigService;
|
|
|
+
|
|
|
/**
|
|
|
* 邮箱验证码
|
|
|
*
|
|
|
@@ -46,13 +52,25 @@ public class SysEmailController extends BaseController {
|
|
|
String key = CacheConstants.CAPTCHA_CODE_KEY + email;
|
|
|
String code = RandomUtil.randomNumbers(4);
|
|
|
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
|
|
+ String string = UUID.randomUUID().toString();
|
|
|
+ RedisUtils.setCacheObject(string, key, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
|
|
try {
|
|
|
- MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。");
|
|
|
+ String template = remoteConfigService.getConfigKey("auth_code_template");
|
|
|
+ if (template == null || template.isEmpty()) {
|
|
|
+ log.error("验证码模板配置为空");
|
|
|
+ return R.fail("验证码模板配置不存在");
|
|
|
+ }
|
|
|
+ String content = template.replace("{CODE}", code).replace("{EXPIRE}", String.valueOf(Constants.CAPTCHA_EXPIRATION));
|
|
|
+
|
|
|
+ MailUtils.sendHtml(email, "易盟数科邮箱验证", content);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ log.error("验证码模板格式错误 => {}", e.getMessage(), e);
|
|
|
+ return R.fail("验证码模板格式错误");
|
|
|
} catch (Exception e) {
|
|
|
- log.error("验证码短信发送异常 => {}", e.getMessage());
|
|
|
- return R.fail(e.getMessage());
|
|
|
+ log.error("验证码邮件发送异常 => {}", e.getMessage(), e);
|
|
|
+ return R.fail("验证码发送失败,请稍后重试");
|
|
|
}
|
|
|
- return R.ok();
|
|
|
+ return R.ok(string);
|
|
|
}
|
|
|
|
|
|
}
|