ResetPassword.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div>
  3. <metadata title="Reset password" />
  4. <main-header />
  5. <div class="container">
  6. <!--Implement Validation-->
  7. <h1>Step {{ step }}</h1>
  8. <label v-if="step === 1" class="label">Email Address</label>
  9. <div v-if="step === 1" class="control is-grouped">
  10. <p class="control is-expanded has-icon has-icon-right">
  11. <input
  12. v-model="email"
  13. class="input"
  14. type="email"
  15. placeholder="The email address associated with your account"
  16. />
  17. </p>
  18. <p class="control">
  19. <button class="button is-success" @click="submitEmail()">
  20. Request
  21. </button>
  22. <button
  23. v-if="step === 1"
  24. class="button is-default skip-step"
  25. @click="step = 2"
  26. >
  27. Skip this step
  28. </button>
  29. </p>
  30. </div>
  31. <label v-if="step === 2" class="label">Reset Code</label>
  32. <div v-if="step === 2" class="control is-grouped">
  33. <p class="control is-expanded has-icon has-icon-right">
  34. <input
  35. v-model="code"
  36. class="input"
  37. type="text"
  38. placeholder="The reset code that was sent to your account's email address"
  39. />
  40. </p>
  41. <p class="control">
  42. <button class="button is-success" v-on:click="verifyCode()">
  43. Verify reset code
  44. </button>
  45. </p>
  46. </div>
  47. <label v-if="step === 3" class="label">Change password</label>
  48. <div v-if="step === 3" class="control is-grouped">
  49. <p class="control is-expanded has-icon has-icon-right">
  50. <input
  51. v-model="newPassword"
  52. class="input"
  53. type="password"
  54. placeholder="New password"
  55. />
  56. </p>
  57. <p class="control">
  58. <button class="button is-success" @click="changePassword()">
  59. Change password
  60. </button>
  61. </p>
  62. </div>
  63. </div>
  64. <main-footer />
  65. </div>
  66. </template>
  67. <script>
  68. import { Toast } from "vue-roaster";
  69. import MainHeader from "../MainHeader.vue";
  70. import MainFooter from "../MainFooter.vue";
  71. import io from "../../io";
  72. export default {
  73. components: { MainHeader, MainFooter },
  74. data() {
  75. return {
  76. email: "",
  77. code: "",
  78. newPassword: "",
  79. step: 1
  80. };
  81. },
  82. mounted() {
  83. io.getSocket(socket => {
  84. this.socket = socket;
  85. });
  86. },
  87. methods: {
  88. submitEmail() {
  89. if (!this.email)
  90. return Toast.methods.addToast("Email cannot be empty", 8000);
  91. return this.socket.emit(
  92. "users.requestPasswordReset",
  93. this.email,
  94. res => {
  95. Toast.methods.addToast(res.message, 8000);
  96. if (res.status === "success") {
  97. this.step = 2;
  98. }
  99. }
  100. );
  101. },
  102. verifyCode() {
  103. if (!this.code)
  104. return Toast.methods.addToast("Code cannot be empty", 8000);
  105. return this.socket.emit(
  106. "users.verifyPasswordResetCode",
  107. this.code,
  108. res => {
  109. Toast.methods.addToast(res.message, 8000);
  110. if (res.status === "success") {
  111. this.step = 3;
  112. }
  113. }
  114. );
  115. },
  116. changePassword() {
  117. if (!this.newPassword)
  118. return Toast.methods.addToast("Password cannot be empty", 8000);
  119. return this.socket.emit(
  120. "users.changePasswordWithResetCode",
  121. this.code,
  122. this.newPassword,
  123. res => {
  124. Toast.methods.addToast(res.message, 8000);
  125. if (res.status === "success") {
  126. this.$router.go("/login");
  127. }
  128. }
  129. );
  130. }
  131. }
  132. };
  133. </script>
  134. <style lang="scss" scoped>
  135. @import "styles/global.scss";
  136. .container {
  137. padding: 25px;
  138. }
  139. .skip-step {
  140. background-color: #7e7e7e;
  141. color: $white;
  142. }
  143. </style>