SettingsAccount.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class='route_container'>
  3. <div class='h1'>Account settings</div>
  4. <p>
  5. <div class='h3'>Change your password</div>
  6. <p class='p--condensed'>
  7. For security, enter your current password
  8. </p>
  9. <fancy-input
  10. placeholder='Current password'
  11. v-model='password.current'
  12. :error='password.errors["current password"]'
  13. type='password'
  14. ></fancy-input>
  15. <fancy-input
  16. placeholder='New password'
  17. v-model='password.new'
  18. :error='password.errors["new password"]'
  19. type='password'
  20. ></fancy-input>
  21. <loading-button
  22. class='button button--green'
  23. @click='savePassword'
  24. :loading='password.loading'
  25. >Change password</loading-button>
  26. </p>
  27. <p>
  28. <div class='h3 h3--margin_top'>Delete your account</div>
  29. <p class='p--condensed'>
  30. Once this is done, your account <strong>cannot</strong> be restored <br/>
  31. Your current posts however will be retained
  32. </p>
  33. <loading-button
  34. class='button button--red'
  35. :loading='deleteAccountLoading'
  36. @click='deleteAccount'
  37. >Delete my account</loading-button>
  38. </p>
  39. </div>
  40. </template>
  41. <script>
  42. import FancyInput from '../FancyInput'
  43. import LoadingButton from '../LoadingButton'
  44. import AjaxErrorHandler from '../../assets/js/errorHandler'
  45. export default {
  46. name: 'settingsAccount',
  47. components: {
  48. FancyInput,
  49. LoadingButton
  50. },
  51. data () {
  52. return {
  53. password: {
  54. loading: false,
  55. current: '',
  56. new: '',
  57. errors: {
  58. 'new password': '',
  59. 'current password': ''
  60. }
  61. },
  62. deleteAccountLoading: false
  63. }
  64. },
  65. computed: {},
  66. methods: {
  67. savePassword () {
  68. this.password.errors['current password'] = ''
  69. this.password.errors['new password'] = ''
  70. if(!this.password.current.length) {
  71. this.password.errors['current password'] = 'Cannot be blank'
  72. return
  73. }
  74. if(!this.password.new.length) {
  75. this.password.errors['new password'] = 'Cannot be blank'
  76. return
  77. }
  78. this.password.loading = true
  79. this.axios
  80. .put('/api/v1/user/' + this.$store.state.username, {
  81. currentPassword: this.password.current,
  82. newPassword: this.password.new
  83. })
  84. .then(_ => {
  85. this.password.loading = false
  86. this.password.current = ''
  87. this.password.new = ''
  88. })
  89. .catch(e => {
  90. this.password.loading = false
  91. console.log(e)
  92. AjaxErrorHandler(this.$store)(e, error => {
  93. if(error.path === 'hash') {
  94. this.password.errors['new password'] = error.message
  95. }
  96. })
  97. })
  98. },
  99. deleteAccount () {
  100. this.deleteAccountLoading = true
  101. this.axios
  102. .delete('/api/v1/user/' + this.$store.state.username)
  103. .then(_ => {
  104. this.deleteAccountLoading = false
  105. this.$store.commit('setUsername', null)
  106. this.$router.push('/')
  107. })
  108. .catch(e => {
  109. this.deleteAccountLoading = false
  110. AjaxErrorHandler(this.$store)(e)
  111. })
  112. }
  113. },
  114. mounted () {
  115. this.$store.dispatch('setTitle', 'account settings')
  116. }
  117. }
  118. </script>
  119. <style lang='scss' scoped>
  120. @import '../../assets/scss/variables.scss';
  121. </style>