Settings.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div v-if="isLoggedIn">
  3. <main-header></main-header>
  4. <div class="container">
  5. <!--Implement Validation-->
  6. <label class="label">Username</label>
  7. <div class="control is-grouped">
  8. <p class="control is-expanded has-icon has-icon-right">
  9. <input class="input is-success" type="text" placeholder="Change username" v-model="user.username">
  10. <!--Remove validation if it's their own without changing-->
  11. <i class="fa fa-check"></i>
  12. <span class="help is-success">This username is available</span>
  13. </p>
  14. <p class="control">
  15. <button class="button is-success" @click="changeUsername()">Save Changes</button>
  16. </p>
  17. </div>
  18. <label class="label">Email</label>
  19. <div class="control is-grouped">
  20. <p class="control is-expanded has-icon has-icon-right">
  21. <input class="input is-danger" type="text" placeholder="Change email address" v-model="user.email.address">
  22. <!--Remove validation if it's their own without changing-->
  23. <i class="fa fa-warning"></i>
  24. <span class="help is-danger">This email is invalid</span>
  25. </p>
  26. <p class="control is-expanded">
  27. <button class="button is-success" @click="changeEmail()">Save Changes</button>
  28. </p>
  29. </div>
  30. <label class="label">Change Password</label>
  31. <div class="control is-grouped">
  32. <p class="control is-expanded has-icon has-icon-right">
  33. <input class="input is-danger" type="text" placeholder="Enter current password" v-model="currentPassword">
  34. <!-- Check if correct -->
  35. <i class="fa fa-warning"></i>
  36. <span class="help is-danger">This password is invalid</span>
  37. </p>
  38. <p class="control is-expanded has-icon has-icon-right">
  39. <input class="input is-danger" type="text" placeholder="Enter new password" v-model="newPassword">
  40. <!--Check if longer than x chars, has x, x and x. Kris likes x too ;)-->
  41. <i class="fa fa-warning"></i>
  42. <span class="help is-danger">This password is invalid</span>
  43. </p>
  44. <p class="control is-expanded">
  45. <button class="button is-success" @click="changePassword()">Save Changes</button>
  46. </p>
  47. </div>
  48. </div>
  49. <main-footer></main-footer>
  50. </div>
  51. </template>
  52. <script>
  53. import { Toast } from 'vue-roaster';
  54. import MainHeader from '../MainHeader.vue';
  55. import MainFooter from '../MainFooter.vue';
  56. import LoginModal from '../Modals/Login.vue'
  57. export default {
  58. data() {
  59. return {
  60. currentPassword: '',
  61. newPassword: '',
  62. user: {},
  63. isLoggedIn: false,
  64. }
  65. },
  66. ready: function() {
  67. let _this = this;
  68. let socketInterval = setInterval(() => {
  69. if (!!_this.$parent.socket) {
  70. _this.socket = _this.$parent.socket;
  71. _this.socket.emit('users.findBySession', res => {
  72. if (res.status == 'success') { _this.user = res.data; _this.isLoggedIn = true; } else {
  73. _this.$parent.isLoginActive = true;
  74. Toast.methods.addToast('Your are currently not signed in', 3000);
  75. }
  76. });
  77. clearInterval(socketInterval);
  78. }
  79. }, 100);
  80. },
  81. methods: {
  82. changePassword: function () {
  83. if (this.currentPassword == "" || this.newPassword == "") return Toast.methods.addToast('Current password field is incorrect', 2000);
  84. this.socket.emit('users.update', this.user._id, 'services.password.password', this.user.password, res => {
  85. if (res.status == 'error') Toast.methods.addToast(res.message, 2000);
  86. else Toast.methods.addToast('Successfully changed password', 2000);
  87. });
  88. },
  89. changeEmail: function () {
  90. if (this.user.email == "") return Toast.methods.addToast('Field cannot be empty', 2000);
  91. this.socket.emit('users.update', this.user._id, 'email.address', this.user.email, res => {
  92. if (res.status == 'error') Toast.methods.addToast(res.message, 2000);
  93. else Toast.methods.addToast('Successfully changed email address', 2000);
  94. });
  95. },
  96. // Will be added shortly:
  97. // changeAvatar() {
  98. // let files = document.getElementById("avatar").files;
  99. // if (files === undefined || files === null) return Materialize.toast(this.getFromLang("error.profilePictureNotSupported"), 4000);
  100. // if (files.length !== 1) return Materialize.toast(this.getFromLang("error.profilePictureOnlyOneFileAllowed"), 4000);
  101. // if (files[0].size >= 2097152) return Materialize.toast(this.getFromLang("error.tooBigProfileImage"), 4000);
  102. // if (files[0].type.indexOf("image/") == -1) return Materialize.toast(this.getFromLang("error.notAnImage"), 4000);
  103. // let local = this;
  104. // fetch(window.location.protocol + '//' + window.location.hostname + ':8081' + '/auth/update/avatar', {
  105. // method: 'POST',
  106. // body: new FormData($('#updateAvatar')[0])
  107. // }).then(response => {
  108. // return response.json()
  109. // }).then(body => {
  110. // if (body.status == 'error') Materialize.toast(body.message, 4000);
  111. // else Materialize.toast(local.getFromLang("settings.profilePictureUpdated"), 4000);
  112. // console.log(body);
  113. // });
  114. // },
  115. changeUsername: function () {
  116. if (this.user.username == "") return Toast.methods.addToast('Field cannot be empty', 2000);
  117. this.socket.emit('users.update', this.user._id, 'username', this.user.username, res => {
  118. if (res.status == 'error') Toast.methods.addToast(res.message, 2000);
  119. else Toast.methods.addToast('Successfully changed username', 2000);
  120. });
  121. }
  122. },
  123. components: { MainHeader, MainFooter, LoginModal }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .container {
  128. padding: 25px;
  129. }
  130. </style>