Guest User

Untitled

a guest
Aug 9th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <template>
  2. <div>
  3. <h3 class="title">LOGIN</h3>
  4. <form method="POST" @submit="authenticateLogin($event)">
  5. <p v-show="showMessageError.error" class="is-size-6 has-text-danger">{{ showMessageError.message }}</p>
  6. <b-field label="Username">
  7. <b-input v-model="username" type="text" required/>
  8. </b-field>
  9. <b-field label="Password">
  10. <b-input v-model="password" type="password" required password-reveal/>
  11. </b-field>
  12. <b-field>
  13. <div class="control">
  14. <button
  15. type="submit"
  16. class="button is-primary">Log In</button>
  17. </div>
  18. </b-field>
  19. <a href="#" @click="isForgotPasswordModalActive = true">Forgot password?</a>
  20. </form>
  21.  
  22. <b-modal :active.sync="isForgotPasswordModalActive">
  23. <form class="card">
  24. <header class="card-header">
  25. <div class="card-header-title">Reset password</div>
  26. </header>
  27. <div class="card-content">
  28. <div class="content">
  29. <div>Forgot your password? No problem. Enter your email address and we'll send you a reset code.</div>
  30. <b-field label="Email">
  31. <b-input v-model="email" type="email" required/>
  32. </b-field>
  33. </div>
  34. </div>
  35. <footer class="card-footer">
  36. <a class="card-footer-item" @click="isForgotPasswordModalActive = false">Cancel</a>
  37. <a class="card-footer-item" type="submit" @click="resetPassword">Reset password</a>
  38. </footer>
  39. </form>
  40. </b-modal>
  41. </div>
  42. </template>
  43.  
  44.  
  45. <script>
  46. import { loadUserData } from "~/assets/utils.js";
  47.  
  48. export default {
  49. data() {
  50. return {
  51. loginError: false,
  52. username: "",
  53. password: "",
  54. email: "",
  55. showMessageError: {
  56. error: true,
  57. message: "",
  58. authResponse: null
  59. },
  60. isForgotPasswordModalActive: false
  61. };
  62. },
  63. mounted() {
  64. if (this.$route.query.email_confirmed == 1) {
  65. this.$snackbar.open("Email address verified");
  66. }
  67. },
  68. methods: {
  69. async authenticateLogin(event) {
  70. event.preventDefault();
  71. this.loginError = false;
  72.  
  73. try {
  74. this.authResponse = await this.$axios.$post("/authenticate/", {
  75. username: this.username,
  76. password: this.password
  77. });
  78.  
  79. await this.$store.commit("user/authenticated", {
  80. userId: this.authResponse.user_profile_id,
  81. language: this.authResponse.language,
  82. token: this.authResponse.token
  83. });
  84.  
  85. await loadUserData(this.$store.commit, this.$axios);
  86.  
  87. this.$router.push(
  88. this.$store.state.userStats.hasCampaignData
  89. ? "/dashboard"
  90. : "/onboarding/bitcointalk"
  91. );
  92. } catch (error) {
  93. const errorCode = error.response.data.error_code;
  94. this.displayErrorMessage(errorCode);
  95. }
  96. },
  97. displayErrorMessage(error) {
  98. this.showMessageError.error = true;
  99. if (error === "wrong_credentials") {
  100. this.showMessageError.message = "Incorrect username or password.";
  101. } else if (error === "email_verification_required") {
  102. this.showMessageError.message =
  103. "Your email address has not been verified. Please check your email account.";
  104. }
  105. },
  106. async resetPassword() {
  107. const authResponse = await this.$axios.$post("/manage/reset-password/", {
  108. action: "request",
  109. email: this.email
  110. });
  111. if (authResponse.success === true) {
  112. this.isForgotPasswordModalActive = false;
  113. }
  114. }
  115. }
  116. };
  117. </script>
  118.  
  119. <style scoped>
  120. form > a {
  121. text-decoration: underline;
  122. }
  123. </style>
Add Comment
Please, Sign In to add comment