aboutsummaryrefslogtreecommitdiff
path: root/src/components/password_reset/password_reset.js
diff options
context:
space:
mode:
authorShpuld Shpludson <shp@cock.li>2020-01-15 16:35:13 +0000
committerShpuld Shpludson <shp@cock.li>2020-01-15 16:35:13 +0000
commit3ab128e73924ce34d190ff609cb9b081cdffe402 (patch)
treebba013a7d61688b90c1f59a8f9fa6c3323b72a05 /src/components/password_reset/password_reset.js
parent7c26435e66fd7e142ea4b88fbe51eede32eeb5ce (diff)
parent7397636914a9d3e7fd30373034c25175273ab808 (diff)
Merge branch 'develop' into 'master'
`master` refresh with `develop` See merge request pleroma/pleroma-fe!1028
Diffstat (limited to 'src/components/password_reset/password_reset.js')
-rw-r--r--src/components/password_reset/password_reset.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/components/password_reset/password_reset.js b/src/components/password_reset/password_reset.js
new file mode 100644
index 00000000..62e74e30
--- /dev/null
+++ b/src/components/password_reset/password_reset.js
@@ -0,0 +1,68 @@
+import { mapState } from 'vuex'
+import passwordResetApi from '../../services/new_api/password_reset.js'
+
+const passwordReset = {
+ data: () => ({
+ user: {
+ email: ''
+ },
+ isPending: false,
+ success: false,
+ throttled: false,
+ error: null
+ }),
+ computed: {
+ ...mapState({
+ signedIn: (state) => !!state.users.currentUser,
+ instance: state => state.instance
+ }),
+ mailerEnabled () {
+ return this.instance.mailerEnabled
+ }
+ },
+ created () {
+ if (this.signedIn) {
+ this.$router.push({ name: 'root' })
+ }
+ },
+ props: {
+ passwordResetRequested: {
+ default: false,
+ type: Boolean
+ }
+ },
+ methods: {
+ dismissError () {
+ this.error = null
+ },
+ submit () {
+ this.isPending = true
+ const email = this.user.email
+ const instance = this.instance.server
+
+ passwordResetApi({ instance, email }).then(({ status }) => {
+ this.isPending = false
+ this.user.email = ''
+
+ if (status === 204) {
+ this.success = true
+ this.error = null
+ } else if (status === 404 || status === 400) {
+ this.error = this.$t('password_reset.not_found')
+ this.$nextTick(() => {
+ this.$refs.email.focus()
+ })
+ } else if (status === 429) {
+ this.throttled = true
+ this.error = this.$t('password_reset.too_many_requests')
+ }
+ }).catch(() => {
+ this.isPending = false
+ this.user.email = ''
+ this.error = this.$t('general.generic_error')
+ })
+ }
+ }
+}
+
+export default passwordReset