Login.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <div>
  3. <metadata title="Login" v-if="isPage" />
  4. <div class="modal is-active">
  5. <div class="modal-background" @click="closeLoginModal()" />
  6. <div class="modal-card">
  7. <header class="modal-card-head">
  8. <p class="modal-card-title">Login</p>
  9. <button
  10. v-if="!isPage"
  11. class="delete"
  12. @click="closeLoginModal()"
  13. />
  14. </header>
  15. <section class="modal-card-body">
  16. <form>
  17. <!-- email address -->
  18. <p class="control">
  19. <label class="label">Email</label>
  20. <input
  21. v-model="email"
  22. class="input"
  23. type="email"
  24. placeholder="Email..."
  25. />
  26. </p>
  27. <!-- password -->
  28. <p class="control">
  29. <label class="label">Password</label>
  30. </p>
  31. <div id="password-container">
  32. <input
  33. v-model="password.value"
  34. class="input"
  35. type="password"
  36. ref="password"
  37. placeholder="Password..."
  38. @keypress="
  39. $parent.submitOnEnter(submitModal, $event)
  40. "
  41. />
  42. <a @click="togglePasswordVisibility()">
  43. <i class="material-icons">
  44. {{
  45. !password.visible
  46. ? "visibility"
  47. : "visibility_off"
  48. }}
  49. </i>
  50. </a>
  51. </div>
  52. <p class="content-box-optional-helper">
  53. <router-link
  54. id="forgot-password"
  55. href="#"
  56. to="/reset_password"
  57. @click.native="closeLoginModal()"
  58. >
  59. Forgot password?
  60. </router-link>
  61. </p>
  62. <br />
  63. <p>
  64. By logging in you agree to our
  65. <router-link
  66. to="/terms"
  67. @click.native="closeLoginModal()"
  68. >
  69. Terms of Service
  70. </router-link>
  71. &nbsp;and
  72. <router-link
  73. to="/privacy"
  74. @click.native="closeLoginModal()"
  75. >
  76. Privacy Policy </router-link
  77. >.
  78. </p>
  79. </form>
  80. </section>
  81. <footer class="modal-card-foot">
  82. <div id="actions">
  83. <a
  84. class="button is-primary"
  85. href="#"
  86. @click="submitModal()"
  87. >Login</a
  88. >
  89. <a
  90. class="button is-github"
  91. :href="apiDomain + '/auth/github/authorize'"
  92. @click="githubRedirect()"
  93. >
  94. <div class="icon">
  95. <img
  96. class="invert"
  97. src="/assets/social/github.svg"
  98. />
  99. </div>
  100. &nbsp;&nbsp;Login with GitHub
  101. </a>
  102. </div>
  103. <p class="content-box-optional-helper">
  104. <router-link to="/register" v-if="isPage">
  105. Don't have an account?
  106. </router-link>
  107. <a v-else href="#" @click="changeToRegisterModal()">
  108. Don't have an account?
  109. </a>
  110. </p>
  111. </footer>
  112. </div>
  113. </div>
  114. </div>
  115. </template>
  116. <script>
  117. import { mapActions } from "vuex";
  118. import Toast from "toasters";
  119. export default {
  120. data() {
  121. return {
  122. email: "",
  123. password: {
  124. value: "",
  125. visible: false
  126. },
  127. apiDomain: "",
  128. isPage: false
  129. };
  130. },
  131. async mounted() {
  132. this.apiDomain = await lofig.get("apiDomain");
  133. if (this.$route.path === "/login") this.isPage = true;
  134. },
  135. methods: {
  136. submitModal() {
  137. this.login({
  138. email: this.email,
  139. password: this.password.value
  140. })
  141. .then(res => {
  142. if (res.status === "success") window.location.reload();
  143. })
  144. .catch(err => new Toast(err.message));
  145. },
  146. togglePasswordVisibility() {
  147. if (this.$refs.password.type === "password") {
  148. this.$refs.password.type = "text";
  149. this.password.visible = true;
  150. } else {
  151. this.$refs.password.type = "password";
  152. this.password.visible = false;
  153. }
  154. },
  155. changeToRegisterModal() {
  156. if (!this.isPage) {
  157. this.closeLoginModal();
  158. this.openModal("register");
  159. }
  160. },
  161. closeLoginModal() {
  162. if (!this.isPage) this.closeModal("login");
  163. },
  164. githubRedirect() {
  165. if (!this.isPage)
  166. localStorage.setItem("github_redirect", this.$route.path);
  167. },
  168. ...mapActions("modalVisibility", ["closeModal", "openModal"]),
  169. ...mapActions("user/auth", ["login"])
  170. }
  171. };
  172. </script>
  173. <style lang="scss" scoped>
  174. .night-mode {
  175. .modal-card,
  176. .modal-card-head,
  177. .modal-card-body,
  178. .modal-card-foot {
  179. background-color: var(--dark-grey-3);
  180. }
  181. .label,
  182. p:not(.help) {
  183. color: var(--light-grey-2);
  184. }
  185. }
  186. #password-container {
  187. display: flex;
  188. align-items: center;
  189. a {
  190. width: 0;
  191. margin-left: -30px;
  192. z-index: 0;
  193. top: 2px;
  194. position: relative;
  195. color: var(--light-grey-1);
  196. }
  197. }
  198. .modal-card-foot {
  199. display: flex;
  200. justify-content: space-between;
  201. flex-wrap: wrap;
  202. .content-box-optional-helper {
  203. margin-top: 0;
  204. }
  205. }
  206. .button.is-github {
  207. background-color: var(--dark-grey-2);
  208. color: var(--white) !important;
  209. }
  210. .is-github:focus {
  211. background-color: var(--dark-grey-4);
  212. }
  213. .is-primary:focus {
  214. background-color: var(--primary-color) !important;
  215. }
  216. .invert {
  217. filter: brightness(5);
  218. }
  219. </style>