Settings.vue 5.3 KB

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