ResetPassword.vue 3.3 KB

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