ResetPassword.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. const _this = this;
  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. .container {
  136. padding: 25px;
  137. }
  138. .skip-step {
  139. background-color: #7e7e7e;
  140. color: #fff;
  141. }
  142. </style>