Login.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="modal is-active">
  3. <div class="modal-background"></div>
  4. <div class="modal-card">
  5. <header class="modal-card-head">
  6. <p class="modal-card-title">Login</p>
  7. <button class="delete" v-on:click="closeCurrentModal()"></button>
  8. </header>
  9. <section class="modal-card-body">
  10. <!-- validation to check if exists http://bulma.io/documentation/elements/form/ -->
  11. <label class="label">Email</label>
  12. <p class="control">
  13. <input class="input" type="text" placeholder="Email..." v-model="email" />
  14. </p>
  15. <label class="label">Password</label>
  16. <p class="control">
  17. <input
  18. class="input"
  19. type="password"
  20. placeholder="Password..."
  21. v-model="password"
  22. v-on:keypress="$parent.submitOnEnter(submitModal, $event)"
  23. />
  24. </p>
  25. <p>
  26. By logging in/registering you agree to our
  27. <router-link to="/terms">Terms of Service</router-link>&nbsp;and
  28. <router-link to="/privacy">Privacy Policy</router-link>.
  29. </p>
  30. </section>
  31. <footer class="modal-card-foot">
  32. <a class="button is-primary" href="#" v-on:click="submitModal('login')">Submit</a>
  33. <a
  34. class="button is-github"
  35. :href="$parent.serverDomain + '/auth/github/authorize'"
  36. v-on:click="githubRedirect()"
  37. >
  38. <div class="icon">
  39. <img class="invert" src="/assets/social/github.svg" />
  40. </div>&nbsp;&nbsp;Login with GitHub
  41. </a>
  42. <a href="/reset_password" v-on:click="resetPassword()">Forgot password?</a>
  43. </footer>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { mapActions } from "vuex";
  49. import { Toast } from "vue-roaster";
  50. export default {
  51. data: function() {
  52. return {
  53. email: "",
  54. password: ""
  55. };
  56. },
  57. methods: {
  58. submitModal: function() {
  59. this.login({
  60. email: this.email,
  61. password: this.password
  62. })
  63. .then(res => {
  64. if (res.status == "success") location.reload();
  65. })
  66. .catch(err => Toast.methods.addToast(err.message, 5000));
  67. },
  68. resetPassword: function() {
  69. this.toggleModal({ sector: "header", modal: "login" });
  70. this.$router.go("/reset_password");
  71. },
  72. githubRedirect: function() {
  73. localStorage.setItem("github_redirect", this.$route.path);
  74. },
  75. ...mapActions("modals", ["toggleModal", "closeCurrentModal"]),
  76. ...mapActions("user/auth", ["login"])
  77. }
  78. };
  79. </script>
  80. <style lang='scss' scoped>
  81. .button.is-github {
  82. background-color: #333;
  83. color: #fff !important;
  84. }
  85. .is-github:focus {
  86. background-color: #1a1a1a;
  87. }
  88. .is-primary:focus {
  89. background-color: #029ce3 !important;
  90. }
  91. .invert {
  92. filter: brightness(5);
  93. }
  94. a {
  95. color: #029ce3;
  96. }
  97. </style>