logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

password_reset.js (1552B)


  1. import { mapState } from 'vuex'
  2. import passwordResetApi from '../../services/new_api/password_reset.js'
  3. import { library } from '@fortawesome/fontawesome-svg-core'
  4. import {
  5. faTimes
  6. } from '@fortawesome/free-solid-svg-icons'
  7. library.add(
  8. faTimes
  9. )
  10. const passwordReset = {
  11. data: () => ({
  12. user: {
  13. email: ''
  14. },
  15. isPending: false,
  16. success: false,
  17. throttled: false,
  18. error: null
  19. }),
  20. computed: {
  21. ...mapState({
  22. signedIn: (state) => !!state.users.currentUser,
  23. instance: state => state.instance
  24. }),
  25. mailerEnabled () {
  26. return this.instance.mailerEnabled
  27. }
  28. },
  29. created () {
  30. if (this.signedIn) {
  31. this.$router.push({ name: 'root' })
  32. }
  33. },
  34. props: {
  35. passwordResetRequested: {
  36. default: false,
  37. type: Boolean
  38. }
  39. },
  40. methods: {
  41. dismissError () {
  42. this.error = null
  43. },
  44. submit () {
  45. this.isPending = true
  46. const email = this.user.email
  47. const instance = this.instance.server
  48. passwordResetApi({ instance, email }).then(({ status }) => {
  49. this.isPending = false
  50. this.user.email = ''
  51. if (status === 204) {
  52. this.success = true
  53. this.error = null
  54. } else if (status === 429) {
  55. this.throttled = true
  56. this.error = this.$t('password_reset.too_many_requests')
  57. }
  58. }).catch(() => {
  59. this.isPending = false
  60. this.user.email = ''
  61. this.error = this.$t('general.generic_error')
  62. })
  63. }
  64. }
  65. }
  66. export default passwordReset