Settings.vue 5.2 KB

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