ResetPassword.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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: function() {
  82. let _this = this;
  83. io.getSocket(socket => {
  84. _this.socket = socket;
  85. });
  86. },
  87. methods: {
  88. submitEmail: function() {
  89. if (!this.email)
  90. return Toast.methods.addToast("Email cannot be empty", 8000);
  91. this.socket.emit("users.requestPasswordReset", this.email, res => {
  92. Toast.methods.addToast(res.message, 8000);
  93. if (res.status === "success") {
  94. this.step = 2;
  95. }
  96. });
  97. },
  98. verifyCode: function() {
  99. if (!this.code)
  100. return Toast.methods.addToast("Code cannot be empty", 8000);
  101. this.socket.emit(
  102. "users.verifyPasswordResetCode",
  103. this.code,
  104. res => {
  105. Toast.methods.addToast(res.message, 8000);
  106. if (res.status === "success") {
  107. this.step = 3;
  108. }
  109. }
  110. );
  111. },
  112. changePassword: function() {
  113. if (!this.newPassword)
  114. return Toast.methods.addToast("Password cannot be empty", 8000);
  115. this.socket.emit(
  116. "users.changePasswordWithResetCode",
  117. this.code,
  118. this.newPassword,
  119. res => {
  120. Toast.methods.addToast(res.message, 8000);
  121. if (res.status === "success") {
  122. this.$router.go("/login");
  123. }
  124. }
  125. );
  126. }
  127. }
  128. };
  129. </script>
  130. <style lang="scss" scoped>
  131. .container {
  132. padding: 25px;
  133. }
  134. .skip-step {
  135. background-color: #7e7e7e;
  136. color: #fff;
  137. }
  138. </style>