Settings.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <main-header></main-header>
  3. <div class="container">
  4. <!--Implement Validation-->
  5. <label class="label">Username</label>
  6. <div class="control is-grouped">
  7. <p class="control is-expanded has-icon has-icon-right">
  8. <input class="input" type="text" placeholder="Change username" v-model="user.username">
  9. <!--Remove validation if it's their own without changing-->
  10. </p>
  11. <p class="control">
  12. <button class="button is-success" @click="changeUsername()">Save Changes</button>
  13. </p>
  14. </div>
  15. <label class="label">Email</label>
  16. <div class="control is-grouped" v-if="user.email">
  17. <p class="control is-expanded has-icon has-icon-right">
  18. <input class="input" type="text" placeholder="Change email address" v-model="user.email.address">
  19. <!--Remove validation if it's their own without changing-->
  20. </p>
  21. <p class="control is-expanded">
  22. <button class="button is-success" @click="changeEmail()">Save Changes</button>
  23. </p>
  24. </div>
  25. <label class="label" v-if="user.password">Change Password</label>
  26. <div class="control is-grouped" v-if="user.password">
  27. <p class="control is-expanded has-icon has-icon-right">
  28. <input class="input" type="password" placeholder="Change password" v-model="newPassword">
  29. </p>
  30. <p class="control is-expanded">
  31. <button class="button is-success" @click="changePassword()">Change password</button>
  32. </p>
  33. </div>
  34. </div>
  35. <main-footer></main-footer>
  36. </template>
  37. <script>
  38. import { Toast } from 'vue-roaster';
  39. import MainHeader from '../MainHeader.vue';
  40. import MainFooter from '../MainFooter.vue';
  41. import LoginModal from '../Modals/Login.vue'
  42. import io from '../../io'
  43. export default {
  44. data() {
  45. return {
  46. user: {},
  47. newPassword: ''
  48. }
  49. },
  50. ready: function() {
  51. let _this = this;
  52. io.getSocket((socket) => {
  53. _this.socket = socket;
  54. _this.socket.emit('users.findBySession', res => {
  55. if (res.status == 'success') { _this.user = res.data; } else {
  56. _this.$parent.isLoginActive = true;
  57. Toast.methods.addToast('Your are currently not signed in', 3000);
  58. }
  59. });
  60. _this.socket.on('event:user.username.changed', username => {
  61. _this.$parent.username = username;
  62. });
  63. });
  64. },
  65. methods: {
  66. changeEmail: function () {
  67. if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
  68. this.socket.emit('users.updateEmail', this.user.email.address, res => {
  69. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  70. else Toast.methods.addToast('Successfully changed email address', 4000);
  71. });
  72. },
  73. changeUsername: function () {
  74. let _this = this;
  75. if (!_this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
  76. _this.socket.emit('users.updateUsername', _this.user.username, res => {
  77. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  78. else Toast.methods.addToast('Successfully changed username', 4000);
  79. });
  80. },
  81. changePassword: function () {
  82. let _this = this;
  83. if (!_this.newPassword) return Toast.methods.addToast('New password cannot be empty', 8000);
  84. _this.socket.emit('users.updatePassword', _this.newPassword, res => {
  85. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  86. else Toast.methods.addToast('Successfully changed password', 4000);
  87. });
  88. }
  89. },
  90. components: { MainHeader, MainFooter, LoginModal }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .container {
  95. padding: 25px;
  96. }
  97. </style>