Settings.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. <label class="label" v-if="user.password">Change Password</label>
  26. <div class="control is-grouped" v-if="user.password">
  27. <p class="control is-expanded has-icon has-icon-right">
  28. <input class="input" type="password" placeholder="Change password" v-model="newPassword">
  29. </p>
  30. <p class="control is-expanded">
  31. <button class="button is-success" @click="changePassword()">Change password</button>
  32. </p>
  33. </div>
  34. <label class="label" v-if="!user.password">Add password</label>
  35. <div class="control is-grouped" v-if="!user.password">
  36. <button class="button is-success" @click="requestPassword()" v-if="passwordStep === 1">Request password email</button><br>
  37. <p class="control is-expanded has-icon has-icon-right" v-if="passwordStep === 2">
  38. <input class="input" type="text" placeholder="Code" v-model="passwordCode">
  39. </p>
  40. <p class="control is-expanded" v-if="passwordStep === 2">
  41. <button class="button is-success" @click="verifyCode()">Verify code</button>
  42. </p>
  43. <p class="control is-expanded has-icon has-icon-right" v-if="passwordStep === 3">
  44. <input class="input" type="password" placeholder="New password" v-model="setNewPassword">
  45. </p>
  46. <p class="control is-expanded" v-if="passwordStep === 3">
  47. <button class="button is-success" @click="setPassword()">Set password</button>
  48. </p>
  49. </div>
  50. <a href="#" v-if="passwordStep === 1 && !user.password" @click="passwordStep = 2">Skip this step</a>
  51. <a class="button is-github" v-if="!user.github" :href='$parent.serverDomain + "/auth/github/link"'>
  52. <div class='icon'>
  53. <img class='invert' src='/assets/social/github.svg'/>
  54. </div>
  55. &nbsp; Link GitHub to account
  56. </a>
  57. <button class="button is-danger" @click="unlinkPassword()" v-if="user.password && user.github">Remove logging in with password</button>
  58. <button class="button is-danger" @click="unlinkGitHub()" v-if="user.password && user.github">Remove logging in with GitHub</button>
  59. </div>
  60. <main-footer></main-footer>
  61. </template>
  62. <script>
  63. import { Toast } from 'vue-roaster';
  64. import MainHeader from '../MainHeader.vue';
  65. import MainFooter from '../MainFooter.vue';
  66. import LoginModal from '../Modals/Login.vue'
  67. import io from '../../io'
  68. export default {
  69. data() {
  70. return {
  71. user: {},
  72. newPassword: '',
  73. setNewPassword: '',
  74. passwordStep: 1,
  75. passwordCode: ''
  76. }
  77. },
  78. ready: function() {
  79. let _this = this;
  80. io.getSocket((socket) => {
  81. _this.socket = socket;
  82. _this.socket.emit('users.findBySession', res => {
  83. if (res.status == 'success') { _this.user = res.data; } else {
  84. _this.$parent.isLoginActive = true;
  85. Toast.methods.addToast('Your are currently not signed in', 3000);
  86. }
  87. });
  88. _this.socket.on('event:user.username.changed', username => {
  89. _this.$parent.username = username;
  90. });
  91. });
  92. },
  93. methods: {
  94. changeEmail: function () {
  95. if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
  96. this.socket.emit('users.updateEmail', this.user.email.address, res => {
  97. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  98. else Toast.methods.addToast('Successfully changed email address', 4000);
  99. });
  100. },
  101. changeUsername: function () {
  102. let _this = this;
  103. if (!_this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
  104. _this.socket.emit('users.updateUsername', _this.user.username, res => {
  105. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  106. else Toast.methods.addToast('Successfully changed username', 4000);
  107. });
  108. },
  109. changePassword: function () {
  110. let _this = this;
  111. if (!_this.newPassword) return Toast.methods.addToast('New password cannot be empty', 8000);
  112. _this.socket.emit('users.updatePassword', _this.newPassword, res => {
  113. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  114. else Toast.methods.addToast('Successfully changed password', 4000);
  115. });
  116. },
  117. requestPassword: function() {
  118. this.socket.emit('users.requestPassword', res => {
  119. Toast.methods.addToast(res.message, 8000);
  120. if (res.status === 'success') {
  121. this.passwordStep = 2;
  122. }
  123. });
  124. },
  125. verifyCode: function () {
  126. if (!this.passwordCode) return Toast.methods.addToast('Code cannot be empty', 8000);
  127. this.socket.emit('users.verifyPasswordCode', this.passwordCode, res => {
  128. Toast.methods.addToast(res.message, 8000);
  129. if (res.status === 'success') {
  130. this.passwordStep = 3;
  131. }
  132. });
  133. },
  134. setPassword: function () {
  135. if (!this.setNewPassword) return Toast.methods.addToast('Password cannot be empty', 8000);
  136. this.socket.emit('users.changePasswordWithCode', this.passwordCode, this.setNewPassword, res => {
  137. Toast.methods.addToast(res.message, 8000);
  138. });
  139. },
  140. unlinkPassword: function () {
  141. this.socket.emit('users.unlinkPassword', res => {
  142. Toast.methods.addToast(res.message, 8000);
  143. });
  144. },
  145. unlinkGitHub: function () {
  146. this.socket.emit('users.unlinkGitHub', res => {
  147. Toast.methods.addToast(res.message, 8000);
  148. });
  149. }
  150. },
  151. components: { MainHeader, MainFooter, LoginModal }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .container {
  156. padding: 25px;
  157. }
  158. </style>