Skip to content

Commit

Permalink
Improve timezone information in login notification (#6309)
Browse files Browse the repository at this point in the history
/area core
/kind improvement

Fixes #6256 

```release-note
格式化新设备登录邮件通知内的登录时间为系统时区
```
  • Loading branch information
ShiinaKin committed Jul 17, 2024
1 parent 3c6df3b commit 2a807b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package run.halo.app.security.device;

import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.lang.NonNull;
Expand All @@ -25,6 +27,8 @@
@RequiredArgsConstructor
public class NewDeviceLoginListener implements ApplicationListener<NewDeviceLoginEvent> {
static final String REASON_TYPE = "new-device-login";
private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss O").withZone(ZoneOffset.systemDefault());
private final NotificationCenter notificationCenter;
private final NotificationReasonEmitter notificationReasonEmitter;

Expand All @@ -43,7 +47,8 @@ Mono<Void> sendNewDeviceNotification(Device device) {
attributes.put("os", device.getStatus().getOs());
attributes.put("browser", device.getStatus().getBrowser());
attributes.put("ipAddress", device.getSpec().getIpAddress());
attributes.put("loginTime", device.getSpec().getLastAuthenticatedTime());
attributes.put("loginTime",
DATE_TIME_FORMATTER.format(device.getSpec().getLastAuthenticatedTime()));
builder.attributes(attributes)
.author(UserIdentity.of(device.getSpec().getPrincipalName()))
.subject(Reason.Subject.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ spec:
[(${subscriber.displayName})] 你好:
你的 [(${site.title})] 账号被用于在 [(${os})] 的 [(${browser})] 上登录。
时间:[(${loginTime})]
时间:[(${loginTime})]
IP 地址:[(${ipAddress})]
如果你知悉上述信息,请忽略此电子邮件。
如果你最近没有使用你的 Halo 账号登录并相信有人可能访问了你的账户,请尽快重设你的密码。
Expand All @@ -180,8 +180,8 @@ spec:
<div class="body">
<p th:text="|你的 ${site.title} 账号被用于在 ${os} 的 ${browser} 上登录:|"></p>
<div class="device-info">
<p th:text="|时间: ${loginTime}|"></p>
<p th:text="|IP 地址: ${ipAddress}|"></p>
<p th:text="|时间: ${loginTime}|"></p>
<p th:text="|IP 地址: ${ipAddress}|"></p>
</div>
<p>如果你知悉上述信息,请忽略此电子邮件。</p>
<p th:text="|如果你最近没有使用你的 ${site.title} 账号登录并相信有人可能访问了你的账户,请尽快重设你的密码。|"></p>
Expand Down

0 comments on commit 2a807b7

Please sign in to comment.