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

Merge pull request #4086 from weseek/fix/gw6934-redirect-path-when-token-is-null

Fix/gw6934 redirect path when token is null
cao 4 лет назад
Родитель
Сommit
b1c2e88951

+ 2 - 1
resource/locales/en_US/translation.json

@@ -855,6 +855,7 @@
     "new_password": "New Password",
     "confirm_new_password": "Confirm the new password",
     "email_is_required": "Email is required",
-    "success_to_send_email": "Success to send email"
+    "success_to_send_email": "Success to send email",
+    "incorrect_token_or_expired_url": "The token is incorrect or the URL has expired. Please resend a password reset request via the link below."
   }
 }

+ 2 - 1
resource/locales/ja_JP/translation.json

@@ -849,6 +849,7 @@
     "new_password": "新しいパスワード",
     "confirm_new_password": "新しいパスワードの確認",
     "email_is_required": "メールを入力してください",
-    "success_to_send_email": "メールを送信しました"
+    "success_to_send_email": "メールを送信しました",
+    "incorrect_token_or_expired_url":"トークンが正しくないか、URLの有効期限が切れています。 以下のリンクからパスワードリセットリクエストを再送信してください。"
   }
 }

+ 2 - 1
resource/locales/zh_CN/translation.json

@@ -860,6 +860,7 @@
     "new_password": "新密码",
     "confirm_new_password": "确认新密码",
     "email_is_required": "电子邮件是必需的",
-    "success_to_send_email": "我发了一封电子邮件"
+    "success_to_send_email": "我发了一封电子邮件",
+    "incorrect_token_or_expired_url":"令牌不正确或 URL 已过期。 请通过以下链接重新发送密码重置请求"
   }
 }

+ 3 - 1
src/server/middlewares/password-reset.js

@@ -11,9 +11,11 @@ module.exports = (crowi, app) => {
     const passwordResetOrder = await PasswordResetOrder.findOne({ token });
     // check the oneTimeToken is valid
     if (passwordResetOrder == null || passwordResetOrder.isExpired()) {
-      return res.redirect('/login');
+      return res.redirect('/forgot-password/error/password-reset-order');
     }
 
+    req.DataFromPasswordResetOrderMiddleware = passwordResetOrder;
+
     return next();
   };
 };

+ 10 - 1
src/server/routes/forgot-password.js

@@ -14,7 +14,9 @@ module.exports = function(crowi, app) {
   };
 
   actions.resetPassword = async function(req, res) {
-    return res.render('reset-password');
+
+    const { email } = req.DataFromPasswordResetOrderMiddleware;
+    return res.render('reset-password', { email });
   };
 
   async function sendPasswordResetEmail(email, url, i18n) {
@@ -50,6 +52,13 @@ module.exports = function(crowi, app) {
     }
   };
 
+  actions.error = function(req, res) {
+    const { reason } = req.params;
+
+    if (reason === 'password-reset-order') {
+      return res.render('forgot-password/error', { reason });
+    }
+  };
 
   return actions;
 };

+ 1 - 0
src/server/routes/index.js

@@ -180,6 +180,7 @@ module.exports = function(crowi, app) {
   app.get('/forgot-password', forgotPassword.forgotPassword);
   app.post('/_api/forgot-password', forgotPassword.api.post);
   app.get('/forgot-password/:token'      , passwordReset, forgotPassword.resetPassword);
+  app.get('/forgot-password/error/:reason'      , applicationInstalled, forgotPassword.error);
 
   app.get('/share/:linkId', page.showSharedPage);
 

+ 1 - 1
src/server/views/forgot-password.html

@@ -1,6 +1,6 @@
 {% extends './layout/layout.html' %}
 
-{% block html_title %}{{ customizeService.generateCustomTitleForFixedPageName(t('forgot_password')) }}{% endblock %}
+{% block html_title %}{{ customizeService.generateCustomTitleForFixedPageName(t('forgot_password.forgot_password')) }}{% endblock %}
 
 
 {#

+ 54 - 0
src/server/views/forgot-password/error.html

@@ -0,0 +1,54 @@
+{% extends '../layout/layout.html' %}
+
+{% block html_title %}{{ customizeService.generateCustomTitleForFixedPageName(t('forgot_password.reset_password')) }}{% endblock %}
+
+
+{#
+  # Remove default contents
+  #}
+ {% block html_head_loading_legacy %}
+ {% endblock %}
+ {% block html_head_loading_app %}
+ {% endblock %}
+ {% block layout_head_nav %}
+ {% endblock %}
+ {% block sidebar %}
+ {% endblock %}
+ {% block head_warn_alert_siteurl_undefined %}
+ {% endblock %}
+ {% block fixed-controls %}
+ {% endblock %}
+
+ {% block html_additional_headers %}
+   <script src="{{ webpack_asset('js/nologin.js') }}" defer></script>
+ {% endblock %}
+
+{% block layout_main %}
+
+  <div id="main" class="main">
+    <div id="content-main" class="content-main container-lg">
+      <div class="container">
+        <div class="row justify-content-md-center">
+          <div class="col-md-6 mt-5">
+            <div class="text-center">
+              <h1><i class="icon-lock-open large"></i></h1>
+              <h2 class="text-center">{{ t('forgot_password.reset_password') }}</h2>
+                {% if reason === 'password-reset-order' %}
+                <div>
+                  <div class="alert alert-warning mb-3">
+                    <h2>{{ t('forgot_password.incorrect_token_or_expired_url') }}</h2>
+                  </div>
+                  <a href="/forgot-password" class="link-switch">
+                    <i class="icon-key"></i> {{ t('forgot_password.forgot_password') }}
+                  </a>
+                </div>
+                {% endif %}
+            </div>
+          </div>
+        </div>
+      </div>
+
+    </div>
+  </div>
+
+{% endblock %}

+ 7 - 0
src/server/views/login/error.html

@@ -37,6 +37,13 @@
         <div class="alert alert-success">
           <h2>{{ t('login.Registration successful') }}</h2>
         </div>
+        {% elseif reason === 'password-reset-order' %}
+        <div class="alert alert-warning mb-3">
+          <h2>{{ t('forgot_password.incorrect_token_or_expired_url') }}</h2>
+        </div>
+          <a href="/forgot-password" class="link-switch">
+            <i class="icon-key"></i> {{ t('forgot_password.forgot_password') }}
+          </a>
         {% else %}
         <div class="alert alert-warning">
             <h2>{{ t('login.Sign in error') }}</h2>

+ 3 - 2
src/server/views/reset-password.html

@@ -1,6 +1,6 @@
 {% extends './layout/layout.html' %}
 
-{% block html_title %}{{ customizeService.generateCustomTitleForFixedPageName(t('forgot_password')) }}{% endblock %}
+{% block html_title %}{{ customizeService.generateCustomTitleForFixedPageName(t('forgot_password.reset_password')) }}{% endblock %}
 
 
 {#
@@ -33,7 +33,8 @@
             <div class="text-center">
               <h1><i class="icon-lock-open large"></i></h1>
               <h2 class="text-center">{{ t('forgot_password.reset_password') }}</h2>
-              <p>{{ t('forgot_password.password_reset_excecution_desc') }}</p>
+              <h5>{{ email }}</h5>
+              <p class="mt-4">{{ t('forgot_password.password_reset_excecution_desc') }}</p>
               <div id="password-reset-execution-form"></div>
             </div>
           </div>