ResetPassword.vue 3.6 KB

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