Skip to content

Commit

Permalink
feat: log reset password code if didn't config smtp.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Dec 19, 2019
1 parent 6aa31fb commit a0d4c74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/main/java/run/halo/app/service/impl/AdminServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ public void sendResetPasswordCode(ResetPasswordParam param) {
throw new ServiceException("已经获取过验证码,不能重复获取");
});

Boolean emailEnabled = optionService.getByPropertyOrDefault(EmailProperties.ENABLED, Boolean.class, false);

if (!emailEnabled) {
throw new ServiceException("未启用 SMTP 服务");
}

if (!userService.verifyUser(param.getUsername(), param.getEmail())) {
throw new ServiceException("用户名或者邮箱验证错误");
}
Expand All @@ -226,12 +220,18 @@ public void sendResetPasswordCode(ResetPasswordParam param) {

log.info("Get reset password code:{}", code);

// Cache code.
cacheStore.putAny("code", code, 5, TimeUnit.MINUTES);

Boolean emailEnabled = optionService.getByPropertyOrDefault(EmailProperties.ENABLED, Boolean.class, false);

if (!emailEnabled) {
throw new ServiceException("未启用 SMTP 服务,无法发送邮件,但是你可以通过系统日志找到验证码");
}

// Send email to administrator.
String content = "您正在进行密码重置操作,如不是本人操作,请尽快做好相应措施。密码重置验证码如下(五分钟有效):\n" + code;
mailService.sendMail(param.getEmail(), "找回密码验证码", content);

// Cache code.
cacheStore.putAny("code", code, 5, TimeUnit.MINUTES);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/run/halo/app/utils/MarkdownUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class MarkdownUtils {
.set(TocExtension.LEVELS, 255)
.set(TablesExtension.WITH_CAPTION, false)
.set(TablesExtension.COLUMN_SPANS, false)
.set(TablesExtension.MIN_SEPARATOR_DASHES,1)
.set(TablesExtension.MIN_SEPARATOR_DASHES, 1)
.set(TablesExtension.MIN_HEADER_ROWS, 1)
.set(TablesExtension.MAX_HEADER_ROWS, 1)
.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
Expand Down

0 comments on commit a0d4c74

Please sign in to comment.