Просмотр исходного кода

attach the expiration date to the email (passwordReset)

Shun Miyazawa 4 лет назад
Родитель
Сommit
ca291921fd

+ 2 - 0
packages/app/resource/locales/en_US/notifications/passwordReset.txt

@@ -7,4 +7,6 @@ To reset your password, click on the link below.
 
 {{ url }}
 
+This link will expire in 1 hour at  {{ expiredAt }}.
+
 If you did not request a password reset, you can safely ignore this email.

+ 2 - 0
packages/app/resource/locales/ja_JP/notifications/passwordReset.txt

@@ -7,4 +7,6 @@
 
 {{ url }}
 
+このリンクは1時間後の {{ expiredAt }} に失効します
+
 もしこのリクエストに心当たりがない場合は、このメールを無視してください。

+ 2 - 0
packages/app/resource/locales/zh_CN/notifications/passwordReset.txt

@@ -7,4 +7,6 @@
 
 {{ url }}
 
+这个链接将在1小时后即{{ expiredAt }}失效。
+
 如果您没有要求重置密码,则可以放心地忽略此电子邮件。

+ 5 - 2
packages/app/src/server/routes/apiv3/forgot-password.js

@@ -1,3 +1,4 @@
+import { format } from 'date-fns';
 import rateLimit from 'express-rate-limit';
 
 import PasswordResetOrder from '~/server/models/password-reset-order';
@@ -45,7 +46,7 @@ module.exports = (crowi) => {
 
   const checkPassportStrategyMiddleware = checkForgotPasswordEnabledMiddlewareFactory(crowi, true);
 
-  async function sendPasswordResetEmail(txtFileName, i18n, email, url) {
+  async function sendPasswordResetEmail(txtFileName, i18n, email, url, expiredAt) {
     return mailService.send({
       to: email,
       subject: txtFileName,
@@ -54,6 +55,7 @@ module.exports = (crowi) => {
         appTitle: appService.getAppTitle(),
         email,
         url,
+        expiredAt,
       },
     });
   }
@@ -76,7 +78,8 @@ module.exports = (crowi) => {
       const passwordResetOrderData = await PasswordResetOrder.createPasswordResetOrder(email);
       const url = new URL(`/forgot-password/${passwordResetOrderData.token}`, appUrl);
       const oneTimeUrl = url.href;
-      await sendPasswordResetEmail('passwordReset', i18n, email, oneTimeUrl);
+      const expiredAt = format(passwordResetOrderData.expiredAt, 'yyyy/MM/dd HH:mm');
+      await sendPasswordResetEmail('passwordReset', i18n, email, oneTimeUrl, expiredAt);
       return res.apiv3();
     }
     catch (err) {