Settings.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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">
  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. </div>
  26. <main-footer></main-footer>
  27. </template>
  28. <script>
  29. import { Toast } from 'vue-roaster';
  30. import MainHeader from '../MainHeader.vue';
  31. import MainFooter from '../MainFooter.vue';
  32. import LoginModal from '../Modals/Login.vue'
  33. export default {
  34. data() {
  35. return {
  36. user: {}
  37. }
  38. },
  39. ready: function() {
  40. let _this = this;
  41. let socketInterval = setInterval(() => {
  42. if (!!_this.$parent.socket) {
  43. _this.socket = _this.$parent.socket;
  44. _this.socket.emit('users.findBySession', res => {
  45. if (res.status == 'success') { _this.user = res.data; } else {
  46. _this.$parent.isLoginActive = true;
  47. Toast.methods.addToast('Your are currently not signed in', 3000);
  48. }
  49. });
  50. clearInterval(socketInterval);
  51. }
  52. }, 100);
  53. },
  54. methods: {
  55. changeEmail: function () {
  56. if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
  57. this.socket.emit('users.updateEmail', this.user.email.address, res => {
  58. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  59. else Toast.methods.addToast('Successfully changed email address', 4000);
  60. });
  61. },
  62. changeUsername: function () {
  63. if (!this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
  64. this.socket.emit('users.updateUsername', this.user.username, res => {
  65. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  66. else Toast.methods.addToast('Successfully changed username', 4000);
  67. });
  68. }
  69. },
  70. components: { MainHeader, MainFooter, LoginModal }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .container {
  75. padding: 25px;
  76. }
  77. </style>