Settings.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. io.getSocket((socket) => {
  42. _this.socket = socket;
  43. _this.socket.emit('users.findBySession', res => {
  44. if (res.status == 'success') { _this.user = res.data; } else {
  45. _this.$parent.isLoginActive = true;
  46. Toast.methods.addToast('Your are currently not signed in', 3000);
  47. }
  48. });
  49. });
  50. },
  51. methods: {
  52. changeEmail: function () {
  53. if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
  54. this.socket.emit('users.updateEmail', this.user.email.address, res => {
  55. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  56. else Toast.methods.addToast('Successfully changed email address', 4000);
  57. });
  58. },
  59. changeUsername: function () {
  60. if (!this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
  61. this.socket.emit('users.updateUsername', this.user.username, res => {
  62. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  63. else Toast.methods.addToast('Successfully changed username', 4000);
  64. });
  65. }
  66. },
  67. components: { MainHeader, MainFooter, LoginModal }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. .container {
  72. padding: 25px;
  73. }
  74. </style>