2024-04-15 03:16:57 +02:00
|
|
|
<template>
|
2024-06-16 05:14:13 +02:00
|
|
|
<div class="flex min-h-screen relative flex-col gap-10 justify-center py-12 px-8">
|
2024-08-28 00:23:29 +02:00
|
|
|
<img crossorigin="anonymous" src="https://cdn.versia.pub/branding/icon.svg" alt="Versia logo"
|
2024-06-16 05:14:13 +02:00
|
|
|
class="mx-auto hidden md:inline-block h-20 ring-1 ring-white/20 rounded" />
|
|
|
|
|
<div v-if="validUrlParameters" class="mx-auto w-full max-w-md">
|
|
|
|
|
<VeeForm class="flex flex-col gap-y-6" method="POST" :validation-schema="schema"
|
2024-06-27 04:55:07 +02:00
|
|
|
:action="redirectUrl.toString()">
|
2024-07-22 01:23:29 +02:00
|
|
|
<h1 class="font-bold text-2xl text-gray-50 text-center tracking-tight">Login to your account</h1>
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-20 03:40:13 +02:00
|
|
|
<div v-if="params.error" class="ring-1 ring-white/10 rounded p-4 bg-red-500 text-white">
|
2024-06-16 05:14:13 +02:00
|
|
|
<h2 class="font-bold text-lg">An error occured</h2>
|
2024-06-20 03:40:13 +02:00
|
|
|
<span class="text-sm">{{ params.error_description }}</span>
|
2024-06-16 05:14:13 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<VeeField name="identifier" as="div" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
|
|
|
|
<LabelAndError>
|
|
|
|
|
<Label for="identifier">Username or Email</Label>
|
|
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</LabelAndError>
|
|
|
|
|
<TextInput id="identifier" placeholder="joemama" autocomplete="email username" required
|
2024-06-16 08:34:35 +02:00
|
|
|
v-bind="field" :is-invalid="!!errorMessage" />
|
2024-06-21 04:09:09 +02:00
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-16 05:14:13 +02:00
|
|
|
<VeeField name="password" as="div" v-slot="{ errorMessage, field }" validate-on-change>
|
2024-06-21 04:09:09 +02:00
|
|
|
<Field>
|
|
|
|
|
<LabelAndError>
|
|
|
|
|
<Label for="password">Password</Label>
|
|
|
|
|
<FieldError v-if="errorMessage">{{ errorMessage }}</FieldError>
|
|
|
|
|
</LabelAndError>
|
|
|
|
|
<PasswordInput id="password" placeholder="hunter2" autocomplete="current-password" required
|
2024-06-16 05:14:13 +02:00
|
|
|
v-bind="field" :is-invalid="!!errorMessage" />
|
2024-06-21 04:09:09 +02:00
|
|
|
</Field>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeField>
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-16 05:14:13 +02:00
|
|
|
<div v-if="ssoConfig && ssoConfig.providers.length > 0" class="w-full space-y-3">
|
|
|
|
|
<div
|
2024-07-22 01:23:29 +02:00
|
|
|
class="flex items-center text-center w-full after:border-b after:border-dark-200 after:flex-1 after:ml-2 before:border-b before:border-dark-200 before:flex-1 before:mr-2">
|
|
|
|
|
<h2 class="text-sm text-gray-200 font-semibold">Or sign in with</h2>
|
2024-06-16 05:14:13 +02:00
|
|
|
</div>
|
|
|
|
|
<div class="grid md:grid-cols-2 md:[&:has(>:last-child:nth-child(1))]:grid-cols-1 gap-4 w-full">
|
2024-06-15 23:18:58 +02:00
|
|
|
<a v-for="provider of ssoConfig.providers" :key="provider.id"
|
2024-06-27 04:55:07 +02:00
|
|
|
:href="issuerRedirectUrl(provider.id)">
|
2024-06-28 02:09:05 +02:00
|
|
|
<Button theme="secondary" class="flex flex-row w-full items-center justify-center gap-3">
|
2024-06-15 23:18:58 +02:00
|
|
|
<img crossorigin="anonymous" :src="provider.icon" :alt="`${provider.name}'s logo'`"
|
|
|
|
|
class="w-6 h-6" />
|
|
|
|
|
<div class="flex flex-col gap-0 justify-center">
|
|
|
|
|
<h3 class="font-bold">{{ provider.name }}</h3>
|
|
|
|
|
</div>
|
2024-06-28 02:09:05 +02:00
|
|
|
</Button>
|
2024-06-15 23:18:58 +02:00
|
|
|
</a>
|
2024-04-22 09:38:51 +02:00
|
|
|
</div>
|
2024-06-15 23:18:58 +02:00
|
|
|
</div>
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-07-22 01:23:29 +02:00
|
|
|
<p class="text-xs text-gray-300">
|
2024-06-16 05:14:13 +02:00
|
|
|
You are signing in to <strong>{{ hostname }}</strong>. If you did not intend to sign in
|
|
|
|
|
here, please close this page.
|
|
|
|
|
</p>
|
|
|
|
|
|
2024-06-28 02:09:05 +02:00
|
|
|
<Button theme="primary" type="submit" class="w-full">Sign in</Button>
|
2024-06-15 23:18:58 +02:00
|
|
|
</VeeForm>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else class="mx-auto max-w-md">
|
2024-07-22 01:23:29 +02:00
|
|
|
<h1 class="text-2xl font-bold tracking-tight text-gray-50 sm:text-4xl">Invalid access
|
2024-06-15 23:18:58 +02:00
|
|
|
parameters
|
|
|
|
|
</h1>
|
2024-07-22 01:23:29 +02:00
|
|
|
<p class="mt-6 text-lg leading-8 text-gray-300">This page should be accessed
|
2024-06-15 23:18:58 +02:00
|
|
|
through a valid OAuth2 authorization request. Please use a <strong class="font-bold">Mastodon
|
|
|
|
|
API</strong> client to access this page.
|
|
|
|
|
</p>
|
2024-07-22 01:23:29 +02:00
|
|
|
<p class="mt-6 text-lg leading-8 text-gray-300">Here are some recommended clients:</p>
|
2024-06-15 23:18:58 +02:00
|
|
|
<ul class="w-full flex flex-col gap-3 mt-4">
|
|
|
|
|
<li v-for="client of useConfig().RECOMMENDED_CLIENTS" :key="client.name" class="w-full">
|
|
|
|
|
<a :href="client.link" target="_blank"
|
|
|
|
|
class="rounded-sm ring-2 ring-white/10 px-4 py-2 w-full flex flex-row gap-3 items-center">
|
|
|
|
|
<img crossorigin="anonymous" :src="client.icon" :alt="`${client.name}'s logo'`"
|
|
|
|
|
class="h-10 w-10" />
|
|
|
|
|
<div class="flex flex-col justify-between items-start">
|
2024-07-22 01:23:29 +02:00
|
|
|
<h2 class="font-bold text-gray-100">{{ client.name }}</h2>
|
2024-06-16 03:42:48 +02:00
|
|
|
<span class="underline text-primary-700">{{ client.link }}</span>
|
2024-06-15 23:18:58 +02:00
|
|
|
</div>
|
|
|
|
|
</a>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
2024-07-22 01:23:29 +02:00
|
|
|
<p class="mt-6 text-lg leading-8 text-gray-300">
|
2024-06-15 23:18:58 +02:00
|
|
|
Many other clients exist, but <strong class="font-bold">they have not been tested for
|
|
|
|
|
compatibility</strong>. Bug reports are nevertheless welcome.
|
|
|
|
|
</p>
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-07-22 01:23:29 +02:00
|
|
|
<p class="mt-6 text-lg leading-8 text-gray-300">
|
2024-08-28 00:23:29 +02:00
|
|
|
Found a problem? Report it on <a href="https://github.com/versia-pub/server/issues/new/choose"
|
2024-06-16 03:42:48 +02:00
|
|
|
target="_blank" class="underline text-primary-700">the issue tracker</a>.
|
2024-06-15 23:18:58 +02:00
|
|
|
</p>
|
|
|
|
|
</div>
|
2024-04-29 01:48:03 +02:00
|
|
|
</div>
|
2024-04-15 03:16:57 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2024-08-28 00:23:29 +02:00
|
|
|
import { Client } from "@versia/client";
|
2024-04-25 08:56:01 +02:00
|
|
|
import { toTypedSchema } from "@vee-validate/zod";
|
|
|
|
|
import { z } from "zod";
|
2024-06-21 04:09:09 +02:00
|
|
|
import FieldError from "~/components/inputs/field-error.vue";
|
|
|
|
|
import Field from "~/components/inputs/field.vue";
|
|
|
|
|
import LabelAndError from "~/components/inputs/label-and-error.vue";
|
|
|
|
|
import Label from "~/components/inputs/label.vue";
|
|
|
|
|
import PasswordInput from "~/components/inputs/password-input.vue";
|
|
|
|
|
import TextInput from "~/components/inputs/text-input.vue";
|
2024-06-28 02:09:05 +02:00
|
|
|
import Button from "~/packages/ui/components/buttons/button.vue";
|
2024-04-22 09:38:51 +02:00
|
|
|
|
2024-04-25 08:56:01 +02:00
|
|
|
const schema = toTypedSchema(
|
|
|
|
|
z.object({
|
2024-06-16 05:14:13 +02:00
|
|
|
identifier: z.string().min(3).or(z.string().email()),
|
2024-04-25 08:56:01 +02:00
|
|
|
password: z.string().min(3),
|
|
|
|
|
}),
|
|
|
|
|
);
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-16 05:14:13 +02:00
|
|
|
const hostname = useRequestURL().hostname;
|
2024-06-20 03:40:13 +02:00
|
|
|
const params = useUrlSearchParams();
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-20 03:40:13 +02:00
|
|
|
const validUrlParameters =
|
|
|
|
|
params.redirect_uri &&
|
|
|
|
|
params.response_type &&
|
|
|
|
|
params.client_id &&
|
|
|
|
|
params.scope;
|
2024-04-15 03:16:57 +02:00
|
|
|
|
2024-06-20 04:54:55 +02:00
|
|
|
const instance = useInstanceFromClient(
|
2024-08-28 00:23:29 +02:00
|
|
|
new Client(new URL(useBaseUrl().value)),
|
2024-06-20 04:54:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const ssoConfig = computed(() => instance.value?.sso);
|
2024-06-27 04:55:07 +02:00
|
|
|
|
|
|
|
|
const redirectUrl = new URL("/api/auth/login", useBaseUrl().value);
|
|
|
|
|
|
|
|
|
|
if (params.redirect_uri) {
|
|
|
|
|
redirectUrl.searchParams.set("redirect_uri", params.redirect_uri as string);
|
|
|
|
|
}
|
|
|
|
|
if (params.response_type) {
|
|
|
|
|
redirectUrl.searchParams.set(
|
|
|
|
|
"response_type",
|
|
|
|
|
params.response_type as string,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (params.client_id) {
|
|
|
|
|
redirectUrl.searchParams.set("client_id", params.client_id as string);
|
|
|
|
|
}
|
|
|
|
|
if (params.scope) {
|
|
|
|
|
redirectUrl.searchParams.set("scope", params.scope as string);
|
|
|
|
|
}
|
|
|
|
|
if (params.state) {
|
|
|
|
|
redirectUrl.searchParams.set("state", params.state as string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const issuerRedirectUrl = (issuerId: string) => {
|
|
|
|
|
const url = new URL("/oauth/sso", useBaseUrl().value);
|
|
|
|
|
params.redirect_uri &&
|
|
|
|
|
url.searchParams.set("redirect_uri", params.redirect_uri as string);
|
|
|
|
|
params.response_type &&
|
|
|
|
|
url.searchParams.set("response_type", params.response_type as string);
|
|
|
|
|
params.client_id &&
|
|
|
|
|
url.searchParams.set("client_id", params.client_id as string);
|
|
|
|
|
params.scope && url.searchParams.set("scope", params.scope as string);
|
|
|
|
|
params.state && url.searchParams.set("state", params.state as string);
|
|
|
|
|
url.searchParams.set("issuer", issuerId);
|
|
|
|
|
return url.toString();
|
|
|
|
|
};
|
2024-04-15 03:16:57 +02:00
|
|
|
</script>
|