Settings.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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="password">Change Password</label>
  26. <div class="control is-grouped" v-if="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="!password">Add password</label>
  35. <div class="control is-grouped" v-if="!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 && !password" @click="passwordStep = 2">Skip this step</a>
  51. <a class="button is-github" v-if="!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="password && github">Remove logging in with password</button>
  58. <button class="button is-danger" @click="unlinkGitHub()" v-if="password && 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. password: false,
  74. github: false,
  75. setNewPassword: '',
  76. passwordStep: 1,
  77. passwordCode: ''
  78. }
  79. },
  80. ready: function() {
  81. let _this = this;
  82. io.getSocket(socket => {
  83. _this.socket = socket;
  84. _this.socket.emit('users.findBySession', res => {
  85. if (res.status == 'success') {
  86. _this.user = res.data;
  87. _this.password = _this.user.password;
  88. _this.github = _this.user.github;
  89. } else {
  90. _this.$parent.isLoginActive = true;
  91. Toast.methods.addToast('Your are currently not signed in', 3000);
  92. }
  93. });
  94. _this.socket.on('event:user.username.changed', username => {
  95. _this.$parent.username = username;
  96. });
  97. _this.socket.on('event:user.linkPassword', () => {console.log(1);
  98. _this.password = true;
  99. });
  100. _this.socket.on('event:user.linkGitHub', () => {console.log(2);
  101. _this.github = true;
  102. });
  103. _this.socket.on('event:user.unlinkPassword', () => {console.log(3);
  104. _this.password = false;
  105. });
  106. _this.socket.on('event:user.unlinkGitHub', () => {console.log(4);
  107. _this.github = false;
  108. });
  109. });
  110. },
  111. methods: {
  112. changeEmail: function () {
  113. if (!this.user.email.address) return Toast.methods.addToast('Email cannot be empty', 8000);
  114. this.socket.emit('users.updateEmail', this.$parent.userId, this.user.email.address, res => {
  115. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  116. else Toast.methods.addToast('Successfully changed email address', 4000);
  117. });
  118. },
  119. changeUsername: function () {
  120. let _this = this;
  121. if (!_this.user.username) return Toast.methods.addToast('Username cannot be empty', 8000);
  122. _this.socket.emit('users.updateUsername', this.$parent.userId, _this.user.username, res => {
  123. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  124. else Toast.methods.addToast('Successfully changed username', 4000);
  125. });
  126. },
  127. changePassword: function () {
  128. let _this = this;
  129. if (!_this.newPassword) return Toast.methods.addToast('New password cannot be empty', 8000);
  130. _this.socket.emit('users.updatePassword', _this.newPassword, res => {
  131. if (res.status !== 'success') Toast.methods.addToast(res.message, 8000);
  132. else Toast.methods.addToast('Successfully changed password', 4000);
  133. });
  134. },
  135. requestPassword: function() {
  136. this.socket.emit('users.requestPassword', res => {
  137. Toast.methods.addToast(res.message, 8000);
  138. if (res.status === 'success') {
  139. this.passwordStep = 2;
  140. }
  141. });
  142. },
  143. verifyCode: function () {
  144. if (!this.passwordCode) return Toast.methods.addToast('Code cannot be empty', 8000);
  145. this.socket.emit('users.verifyPasswordCode', this.passwordCode, res => {
  146. Toast.methods.addToast(res.message, 8000);
  147. if (res.status === 'success') {
  148. this.passwordStep = 3;
  149. }
  150. });
  151. },
  152. setPassword: function () {
  153. if (!this.setNewPassword) return Toast.methods.addToast('Password cannot be empty', 8000);
  154. this.socket.emit('users.changePasswordWithCode', this.passwordCode, this.setNewPassword, res => {
  155. Toast.methods.addToast(res.message, 8000);
  156. });
  157. },
  158. unlinkPassword: function () {
  159. this.socket.emit('users.unlinkPassword', res => {
  160. Toast.methods.addToast(res.message, 8000);
  161. });
  162. },
  163. unlinkGitHub: function () {
  164. this.socket.emit('users.unlinkGitHub', res => {
  165. Toast.methods.addToast(res.message, 8000);
  166. });
  167. }
  168. },
  169. components: { MainHeader, MainFooter, LoginModal }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .container {
  174. padding: 25px;
  175. }
  176. a { color: #029ce3 !important; }
  177. </style>