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" 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. </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. import io from '../../io'
  34. export default {
  35. data() {
  36. return {
  37. user: {}
  38. }
  39. },
  40. ready: function() {
  41. let _this = this;
  42. io.getSocket((socket) => {
  43. _this.socket = 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. _this.socket.on('event:user.username.changed', username => {
  51. _this.$parent.username = username;
  52. });
  53. });
  54. },
  55. methods: {
  56. changeEmail: function () {
  57. if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
  58. this.socket.emit('users.updateEmail', this.user.email.address, res => {
  59. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  60. else Toast.methods.addToast('Successfully changed email address', 4000);
  61. });
  62. },
  63. changeUsername: function () {
  64. let _this = this;
  65. if (!_this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
  66. _this.socket.emit('users.updateUsername', _this.user.username, res => {
  67. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  68. else Toast.methods.addToast('Successfully changed username', 4000);
  69. });
  70. }
  71. },
  72. components: { MainHeader, MainFooter, LoginModal }
  73. }
  74. </script>
  75. <style lang="scss" scoped>
  76. .container {
  77. padding: 25px;
  78. }
  79. </style>