logo

pleroma-fe

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

security_tab.js (4664B)


  1. import ProgressButton from 'src/components/progress_button/progress_button.vue'
  2. import Checkbox from 'src/components/checkbox/checkbox.vue'
  3. import Mfa from './mfa.vue'
  4. import localeService from 'src/services/locale/locale.service.js'
  5. const SecurityTab = {
  6. data () {
  7. return {
  8. newEmail: '',
  9. changeEmailError: false,
  10. changeEmailPassword: '',
  11. changedEmail: false,
  12. deletingAccount: false,
  13. deleteAccountConfirmPasswordInput: '',
  14. deleteAccountError: false,
  15. changePasswordInputs: ['', '', ''],
  16. changedPassword: false,
  17. changePasswordError: false,
  18. moveAccountTarget: '',
  19. moveAccountPassword: '',
  20. movedAccount: false,
  21. moveAccountError: false,
  22. aliases: [],
  23. listAliasesError: false,
  24. addAliasTarget: '',
  25. addedAlias: false,
  26. addAliasError: false
  27. }
  28. },
  29. created () {
  30. this.$store.dispatch('fetchTokens')
  31. this.fetchAliases()
  32. },
  33. components: {
  34. ProgressButton,
  35. Mfa,
  36. Checkbox
  37. },
  38. computed: {
  39. user () {
  40. return this.$store.state.users.currentUser
  41. },
  42. pleromaBackend () {
  43. return this.$store.state.instance.pleromaBackend
  44. },
  45. oauthTokens () {
  46. return this.$store.state.oauthTokens.tokens.map(oauthToken => {
  47. return {
  48. id: oauthToken.id,
  49. appName: oauthToken.app_name,
  50. validUntil: new Date(oauthToken.valid_until).toLocaleDateString(localeService.internalToBrowserLocale(this.$i18n.locale))
  51. }
  52. })
  53. }
  54. },
  55. methods: {
  56. confirmDelete () {
  57. this.deletingAccount = true
  58. },
  59. deleteAccount () {
  60. this.$store.state.api.backendInteractor.deleteAccount({ password: this.deleteAccountConfirmPasswordInput })
  61. .then((res) => {
  62. if (res.status === 'success') {
  63. this.$store.dispatch('logout')
  64. this.$router.push({ name: 'root' })
  65. } else {
  66. this.deleteAccountError = res.error
  67. }
  68. })
  69. },
  70. changePassword () {
  71. const params = {
  72. password: this.changePasswordInputs[0],
  73. newPassword: this.changePasswordInputs[1],
  74. newPasswordConfirmation: this.changePasswordInputs[2]
  75. }
  76. this.$store.state.api.backendInteractor.changePassword(params)
  77. .then((res) => {
  78. if (res.status === 'success') {
  79. this.changedPassword = true
  80. this.changePasswordError = false
  81. this.logout()
  82. } else {
  83. this.changedPassword = false
  84. this.changePasswordError = res.error
  85. }
  86. })
  87. },
  88. changeEmail () {
  89. const params = {
  90. email: this.newEmail,
  91. password: this.changeEmailPassword
  92. }
  93. this.$store.state.api.backendInteractor.changeEmail(params)
  94. .then((res) => {
  95. if (res.status === 'success') {
  96. this.changedEmail = true
  97. this.changeEmailError = false
  98. } else {
  99. this.changedEmail = false
  100. this.changeEmailError = res.error
  101. }
  102. })
  103. },
  104. moveAccount () {
  105. const params = {
  106. targetAccount: this.moveAccountTarget,
  107. password: this.moveAccountPassword
  108. }
  109. this.$store.state.api.backendInteractor.moveAccount(params)
  110. .then((res) => {
  111. if (res.status === 'success') {
  112. this.movedAccount = true
  113. this.moveAccountError = false
  114. } else {
  115. this.movedAccount = false
  116. this.moveAccountError = res.error
  117. }
  118. })
  119. },
  120. removeAlias (alias) {
  121. this.$store.state.api.backendInteractor.deleteAlias({ alias })
  122. .then(() => this.fetchAliases())
  123. },
  124. addAlias () {
  125. this.$store.state.api.backendInteractor.addAlias({ alias: this.addAliasTarget })
  126. .then((res) => {
  127. this.addedAlias = true
  128. this.addAliasError = false
  129. this.addAliasTarget = ''
  130. })
  131. .catch((error) => {
  132. this.addedAlias = false
  133. this.addAliasError = error
  134. })
  135. .then(() => this.fetchAliases())
  136. },
  137. fetchAliases () {
  138. this.$store.state.api.backendInteractor.listAliases()
  139. .then((res) => {
  140. this.aliases = res.aliases
  141. this.listAliasesError = false
  142. })
  143. .catch((error) => {
  144. this.listAliasesError = error.error
  145. })
  146. },
  147. logout () {
  148. this.$store.dispatch('logout')
  149. this.$router.replace('/')
  150. },
  151. revokeToken (id) {
  152. if (window.confirm(`${this.$i18n.t('settings.revoke_token')}?`)) {
  153. this.$store.dispatch('revokeToken', id)
  154. }
  155. }
  156. }
  157. }
  158. export default SecurityTab