123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <script setup lang="ts">
- import { defineAsyncComponent, ref } from "vue";
- import { useRoute } from "vue-router";
- import Toast from "toasters";
- import { storeToRefs } from "pinia";
- import { useConfigStore } from "@/stores/config";
- import { useUserAuthStore } from "@/stores/userAuth";
- import { useModalsStore } from "@/stores/modals";
- const Modal = defineAsyncComponent(() => import("@/components/Modal.vue"));
- const route = useRoute();
- const email = ref("");
- const password = ref({
- value: "",
- visible: false
- });
- const passwordElement = ref();
- const configStore = useConfigStore();
- const { githubAuthentication, oidcAuthentication, registrationDisabled } =
- storeToRefs(configStore);
- const { login } = useUserAuthStore();
- const { openModal, closeCurrentModal } = useModalsStore();
- const submitModal = () => {
- if (!email.value || !password.value.value) return;
- login({
- email: email.value,
- password: password.value.value
- })
- .then((res: any) => {
- if (res.status === "success") window.location.reload();
- })
- .catch(err => new Toast(err.message));
- };
- const checkForAutofill = (type, event) => {
- if (
- event.target.value !== "" &&
- event.inputType === undefined &&
- event.data === undefined &&
- event.dataTransfer === undefined &&
- event.isComposing === undefined
- )
- submitModal();
- };
- const togglePasswordVisibility = () => {
- if (passwordElement.value.type === "password") {
- passwordElement.value.type = "text";
- password.value.visible = true;
- } else {
- passwordElement.value.type = "password";
- password.value.visible = false;
- }
- };
- const changeToRegisterModal = () => {
- closeCurrentModal();
- openModal("register");
- };
- const githubRedirect = () => {
- localStorage.setItem("github_redirect", route.path);
- };
- const oidcRedirect = () => {
- localStorage.setItem("oidc_redirect", route.path);
- };
- </script>
- <template>
- <div>
- <modal
- title="Login"
- class="login-modal"
- :size="'slim'"
- @closed="closeCurrentModal()"
- >
- <template #body>
- <form>
- <!-- email address -->
- <p class="control">
- <label class="label">Username/Email</label>
- <input
- v-model="email"
- class="input"
- type="email"
- autocomplete="username"
- placeholder="Username/Email..."
- @input="checkForAutofill('email', $event)"
- @keyup.enter="submitModal()"
- />
- </p>
- <!-- password -->
- <p class="control">
- <label class="label">Password</label>
- </p>
- <div id="password-visibility-container">
- <input
- v-model="password.value"
- class="input"
- type="password"
- autocomplete="current-password"
- ref="passwordElement"
- placeholder="Password..."
- @input="checkForAutofill('password', $event)"
- @keyup.enter="submitModal()"
- />
- <a @click="togglePasswordVisibility()">
- <i class="material-icons">
- {{
- !password.visible
- ? "visibility"
- : "visibility_off"
- }}
- </i>
- </a>
- </div>
- <p
- v-if="configStore.mailEnabled"
- class="content-box-optional-helper"
- >
- <router-link
- id="forgot-password"
- to="/reset_password"
- @click="closeCurrentModal()"
- >
- Forgot password?
- </router-link>
- </p>
- <br />
- <p>
- By logging in you agree to our
- <router-link to="/terms" @click="closeCurrentModal()">
- Terms of Service
- </router-link>
- and
- <router-link to="/privacy" @click="closeCurrentModal()">
- Privacy Policy</router-link
- >.
- </p>
- </form>
- </template>
- <template #footer>
- <div id="actions">
- <button class="button is-primary" @click="submitModal()">
- Login
- </button>
- <a
- v-if="githubAuthentication"
- class="button is-github"
- :href="configStore.urls.api + '/auth/github/authorize'"
- @click="githubRedirect()"
- >
- <div class="icon">
- <img
- class="invert"
- src="/assets/social/github.svg"
- />
- </div>
- Login with GitHub
- </a>
- <a
- v-if="oidcAuthentication"
- class="button is-oidc"
- :href="configStore.urls.api + '/auth/oidc/authorize'"
- @click="oidcRedirect()"
- >
- <div class="icon">
- <img
- class="invert"
- src="/assets/social/github.svg"
- />
- </div>
- Login with OIDC
- </a>
- </div>
- <p
- v-if="!registrationDisabled"
- class="content-box-optional-helper"
- >
- <a @click="changeToRegisterModal()">
- Don't have an account?
- </a>
- </p>
- </template>
- </modal>
- </div>
- </template>
- <style lang="less" scoped>
- .night-mode {
- .modal-card,
- .modal-card-head,
- .modal-card-body,
- .modal-card-foot {
- background-color: var(--dark-grey-3);
- }
- .label,
- p:not(.help) {
- color: var(--light-grey-2);
- }
- }
- .modal-card-foot {
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
- .content-box-optional-helper {
- margin-top: 0;
- }
- }
- .button.is-github {
- background-color: var(--dark-grey-2);
- color: var(--white) !important;
- }
- .is-github:focus {
- background-color: var(--dark-grey-4);
- }
- .is-primary:focus {
- background-color: var(--primary-color) !important;
- }
- .invert {
- filter: brightness(5);
- }
- </style>
|