From 8ee5abb1a532bcfb9c70f1dad8cdeefcaf31e59c Mon Sep 17 00:00:00 2001
From: Eugenij <eugenijm@protonmail.com>
Date: Thu, 5 Sep 2019 11:23:28 +0000
Subject: Password reset page

---
 src/components/password_reset/password_reset.vue | 116 +++++++++++++++++++++++
 1 file changed, 116 insertions(+)
 create mode 100644 src/components/password_reset/password_reset.vue

(limited to 'src/components/password_reset/password_reset.vue')

diff --git a/src/components/password_reset/password_reset.vue b/src/components/password_reset/password_reset.vue
new file mode 100644
index 00000000..00474e95
--- /dev/null
+++ b/src/components/password_reset/password_reset.vue
@@ -0,0 +1,116 @@
+<template>
+  <div class="settings panel panel-default">
+    <div class="panel-heading">
+      {{ $t('password_reset.password_reset') }}
+    </div>
+    <div class="panel-body">
+      <form
+        class="password-reset-form"
+        @submit.prevent="submit"
+      >
+        <div class="container">
+          <div v-if="!mailerEnabled">
+            <p>
+              {{ $t('password_reset.password_reset_disabled') }}
+            </p>
+          </div>
+          <div v-else-if="success || throttled">
+            <p v-if="success">
+              {{ $t('password_reset.check_email') }}
+            </p>
+            <div class="form-group text-center">
+              <router-link :to="{name: 'root'}">
+                {{ $t('password_reset.return_home') }}
+              </router-link>
+            </div>
+          </div>
+          <div v-else>
+            <p>
+              {{ $t('password_reset.instruction') }}
+            </p>
+            <div class="form-group">
+              <input
+                ref="email"
+                v-model="user.email"
+                :disabled="isPending"
+                :placeholder="$t('password_reset.placeholder')"
+                class="form-control"
+                type="input"
+              >
+            </div>
+            <div class="form-group">
+              <button
+                :disabled="isPending"
+                type="submit"
+                class="btn btn-default btn-block"
+              >
+                {{ $t('general.submit') }}
+              </button>
+            </div>
+          </div>
+          <p
+            v-if="error"
+            class="alert error notice-dismissible"
+          >
+            <span>{{ error }}</span>
+            <a
+              class="button-icon dismiss"
+              @click.prevent="dismissError()"
+            >
+              <i class="icon-cancel" />
+            </a>
+          </p>
+        </div>
+      </form>
+    </div>
+  </div>
+</template>
+
+<script src="./password_reset.js"></script>
+<style lang="scss">
+@import '../../_variables.scss';
+
+.password-reset-form {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  margin: 0.6em;
+
+  .container {
+    display: flex;
+    flex: 1 0;
+    flex-direction: column;
+    margin-top: 0.6em;
+    max-width: 18rem;
+  }
+
+  .form-group {
+    display: flex;
+    flex-direction: column;
+    margin-bottom: 1em;
+    padding: 0.3em 0.0em 0.3em;
+    line-height: 24px;
+  }
+
+  .error {
+    text-align: center;
+    animation-name: shakeError;
+    animation-duration: 0.4s;
+    animation-timing-function: ease-in-out;
+  }
+
+  .alert {
+    padding: 0.5em;
+    margin: 0.3em 0.0em 1em;
+  }
+
+  .notice-dismissible {
+    padding-right: 2rem;
+  }
+
+  .icon-cancel {
+    cursor: pointer;
+  }
+}
+
+</style>
-- 
cgit v1.2.3-70-g09d2


From 37be781312c6e3139a7b158835a51b141fd94e70 Mon Sep 17 00:00:00 2001
From: Maxim Filippov <colixer@gmail.com>
Date: Wed, 16 Oct 2019 10:00:26 +0000
Subject: Require password reset

---
 src/boot/routes.js                               |  2 +-
 src/components/login_form/login_form.js          |  2 ++
 src/components/password_reset/password_reset.js  |  6 ++++++
 src/components/password_reset/password_reset.vue | 16 +++++++++++++++-
 src/i18n/en.json                                 |  4 +++-
 5 files changed, 27 insertions(+), 3 deletions(-)

(limited to 'src/components/password_reset/password_reset.vue')

diff --git a/src/boot/routes.js b/src/boot/routes.js
index cd02711c..5670236c 100644
--- a/src/boot/routes.js
+++ b/src/boot/routes.js
@@ -47,7 +47,7 @@ export default (store) => {
     { name: 'dms', path: '/users/:username/dms', component: DMs, beforeEnter: validateAuthenticatedRoute },
     { name: 'settings', path: '/settings', component: Settings },
     { name: 'registration', path: '/registration', component: Registration },
-    { name: 'password-reset', path: '/password-reset', component: PasswordReset },
+    { name: 'password-reset', path: '/password-reset', component: PasswordReset, props: true },
     { name: 'registration-token', path: '/registration/:token', component: Registration },
     { name: 'friend-requests', path: '/friend-requests', component: FollowRequests, beforeEnter: validateAuthenticatedRoute },
     { name: 'user-settings', path: '/user-settings', component: UserSettings, beforeEnter: validateAuthenticatedRoute },
diff --git a/src/components/login_form/login_form.js b/src/components/login_form/login_form.js
index 10f52fe2..0b574a04 100644
--- a/src/components/login_form/login_form.js
+++ b/src/components/login_form/login_form.js
@@ -59,6 +59,8 @@ const LoginForm = {
           if (result.error) {
             if (result.error === 'mfa_required') {
               this.requireMFA({ app: app, settings: result })
+            } else if (result.identifier === 'password_reset_required') {
+              this.$router.push({ name: 'password-reset', params: { passwordResetRequested: true } })
             } else {
               this.error = result.error
               this.focusOnPasswordInput()
diff --git a/src/components/password_reset/password_reset.js b/src/components/password_reset/password_reset.js
index fa71e07a..62e74e30 100644
--- a/src/components/password_reset/password_reset.js
+++ b/src/components/password_reset/password_reset.js
@@ -25,6 +25,12 @@ const passwordReset = {
       this.$router.push({ name: 'root' })
     }
   },
+  props: {
+    passwordResetRequested: {
+      default: false,
+      type: Boolean
+    }
+  },
   methods: {
     dismissError () {
       this.error = null
diff --git a/src/components/password_reset/password_reset.vue b/src/components/password_reset/password_reset.vue
index 00474e95..713c9dce 100644
--- a/src/components/password_reset/password_reset.vue
+++ b/src/components/password_reset/password_reset.vue
@@ -10,7 +10,10 @@
       >
         <div class="container">
           <div v-if="!mailerEnabled">
-            <p>
+            <p v-if="passwordResetRequested">
+              {{ $t('password_reset.password_reset_required_but_mailer_is_disabled') }}
+            </p>
+            <p v-else>
               {{ $t('password_reset.password_reset_disabled') }}
             </p>
           </div>
@@ -25,6 +28,12 @@
             </div>
           </div>
           <div v-else>
+            <p
+              v-if="passwordResetRequested"
+              class="password-reset-required error"
+            >
+              {{ $t('password_reset.password_reset_required') }}
+            </p>
             <p>
               {{ $t('password_reset.instruction') }}
             </p>
@@ -104,6 +113,11 @@
     margin: 0.3em 0.0em 1em;
   }
 
+  .password-reset-required {
+    background-color: var(--alertError, $fallback--alertError);
+    padding: 10px 0;
+  }
+
   .notice-dismissible {
     padding-right: 2rem;
   }
diff --git a/src/i18n/en.json b/src/i18n/en.json
index b58112e3..d11b2d14 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -632,6 +632,8 @@
     "return_home": "Return to the home page",
     "not_found": "We couldn't find that email or username.",
     "too_many_requests": "You have reached the limit of attempts, try again later.",
-    "password_reset_disabled": "Password reset is disabled. Please contact your instance administrator."
+    "password_reset_disabled": "Password reset is disabled. Please contact your instance administrator.",
+    "password_reset_required": "You must reset your password to log in.",
+    "password_reset_required_but_mailer_is_disabled": "You must reset your password, but password reset is disabled. Please contact your instance administrator."
   }
 }
-- 
cgit v1.2.3-70-g09d2

