2024-11-23 14:25:41 +01:00
|
|
|
<template>
|
|
|
|
<div class="grow flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
|
|
|
<div class="max-w-md w-full space-y-8 pb-20">
|
|
|
|
<div class="flex flex-col items-center gap-4">
|
2025-04-24 16:49:14 +02:00
|
|
|
<AppLogo />
|
2024-11-23 14:25:41 +01:00
|
|
|
<h2 class="text-center text-4xl font-extrabold text-gray-900">Einrichtung</h2>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="verification == 'loading'" class="flex flex-col gap-2 items-center">
|
|
|
|
<p class="w-fit">Einladungslink wird verifiziert</p>
|
|
|
|
<Spinner class="my-auto" />
|
|
|
|
</div>
|
|
|
|
<div v-else-if="verification == 'failed'" class="flex flex-col gap-2 items-center">
|
|
|
|
<p class="w-fit">Einladungslink nicht gültig - Melde dich bei einem Admin.</p>
|
|
|
|
</div>
|
|
|
|
<form v-else class="flex flex-col gap-2" @submit.prevent="invite">
|
2025-05-06 08:38:28 +02:00
|
|
|
<div class="w-full flex flex-row gap-2 justify-center">
|
|
|
|
<p
|
|
|
|
class="w-1/2 p-0.5 pl-0 rounded-lg py-2.5 text-sm text-center font-medium leading-5 outline-hidden cursor-pointer"
|
|
|
|
:class="
|
|
|
|
tab == 'totp' ? 'bg-red-200 shadow-sm border-b-2 border-primary rounded-b-none' : ' hover:bg-red-200'
|
|
|
|
"
|
|
|
|
@click="tab = 'totp'"
|
|
|
|
>
|
|
|
|
TOTP
|
|
|
|
</p>
|
|
|
|
<p
|
|
|
|
class="w-1/2 p-0.5 rounded-lg py-2.5 text-sm text-center font-medium leading-5 outline-hidden cursor-pointer"
|
|
|
|
:class="
|
|
|
|
tab == 'password' ? 'bg-red-200 shadow-sm border-b-2 border-primary rounded-b-none' : 'hover:bg-red-200'
|
|
|
|
"
|
|
|
|
@click="tab = 'password'"
|
|
|
|
>
|
|
|
|
Passwort
|
|
|
|
</p>
|
|
|
|
</div>
|
2024-11-23 14:25:41 +01:00
|
|
|
<p class="text-center">Dein Nutzername: {{ username }}</p>
|
|
|
|
|
2025-05-06 08:38:28 +02:00
|
|
|
<div v-if="tab == 'totp'" class="flex flex-col gap-2">
|
|
|
|
<img :src="image" alt="totp" class="w-56 h-56 self-center" />
|
2024-11-23 14:25:41 +01:00
|
|
|
|
2025-05-06 08:38:28 +02:00
|
|
|
<TextCopy :copyText="otp" />
|
2024-11-23 14:25:41 +01:00
|
|
|
|
2025-05-06 08:38:28 +02:00
|
|
|
<div class="-space-y-px">
|
|
|
|
<div>
|
|
|
|
<input id="totp" name="totp" type="text" required placeholder="TOTP" />
|
|
|
|
</div>
|
2024-11-23 14:25:41 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2025-05-06 08:38:28 +02:00
|
|
|
<div v-else>
|
|
|
|
<input
|
|
|
|
id="password"
|
|
|
|
name="password"
|
|
|
|
type="password"
|
|
|
|
required
|
|
|
|
placeholder="Passwort"
|
|
|
|
class="rounded-b-none!"
|
|
|
|
autocomplete="new-password"
|
2025-05-06 09:02:55 +02:00
|
|
|
:class="notMatching ? 'border-red-600!' : ''"
|
2025-05-06 08:38:28 +02:00
|
|
|
/>
|
|
|
|
<input
|
2025-05-06 09:02:55 +02:00
|
|
|
id="password_rep"
|
|
|
|
name="password_rep"
|
2025-05-06 08:38:28 +02:00
|
|
|
type="password"
|
|
|
|
required
|
|
|
|
placeholder="Passwort wiederholen"
|
|
|
|
class="rounded-t-none!"
|
|
|
|
autocomplete="new-password"
|
2025-05-06 09:02:55 +02:00
|
|
|
:class="notMatching ? 'border-red-600!' : ''"
|
2025-05-06 08:38:28 +02:00
|
|
|
/>
|
2025-05-06 09:02:55 +02:00
|
|
|
<p v-if="notMatching">Passwörter stimmen nicht überein</p>
|
2025-05-06 08:38:28 +02:00
|
|
|
</div>
|
2024-11-23 14:25:41 +01:00
|
|
|
|
|
|
|
<div class="flex flex-row gap-2">
|
|
|
|
<button type="submit" primary :disabled="inviteStatus == 'loading' || inviteStatus == 'success'">
|
|
|
|
Einladung fertigstellen
|
|
|
|
</button>
|
|
|
|
<Spinner v-if="inviteStatus == 'loading'" class="my-auto" />
|
|
|
|
<SuccessCheckmark v-else-if="inviteStatus == 'success'" />
|
|
|
|
<FailureXMark v-else-if="inviteStatus == 'failed'" />
|
|
|
|
</div>
|
|
|
|
<p v-if="inviteError" class="text-center">{{ inviteError }}</p>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<FormBottomBar />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import Spinner from "@/components/Spinner.vue";
|
|
|
|
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
|
|
|
import FailureXMark from "@/components/FailureXMark.vue";
|
|
|
|
import FormBottomBar from "@/components/FormBottomBar.vue";
|
|
|
|
import TextCopy from "@/components/TextCopy.vue";
|
2025-04-24 16:49:14 +02:00
|
|
|
import AppLogo from "@/components/AppLogo.vue";
|
2025-05-06 08:38:28 +02:00
|
|
|
import { hashString } from "@/helpers/crypto";
|
2024-11-23 14:25:41 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
token: String,
|
|
|
|
mail: String,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2025-05-06 08:38:28 +02:00
|
|
|
tab: "totp",
|
2024-11-23 14:25:41 +01:00
|
|
|
verification: "loading" as "success" | "loading" | "failed",
|
|
|
|
image: undefined as undefined | string,
|
|
|
|
otp: undefined as undefined | string,
|
|
|
|
username: "" as string,
|
|
|
|
inviteStatus: undefined as undefined | "loading" | "success" | "failed",
|
|
|
|
inviteError: "" as string,
|
2025-05-06 09:02:55 +02:00
|
|
|
notMatching: false as boolean,
|
2024-11-23 14:25:41 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.$http
|
|
|
|
.post(`/invite/verify`, {
|
|
|
|
token: this.token,
|
|
|
|
mail: this.mail,
|
|
|
|
})
|
|
|
|
.then((result) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.verification = "success";
|
|
|
|
this.image = result.data.dataUrl;
|
|
|
|
this.otp = result.data.otp;
|
|
|
|
this.username = result.data.username;
|
|
|
|
}, 1000);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.verification = "failed";
|
|
|
|
}, 1000);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
2025-05-06 08:38:28 +02:00
|
|
|
async invite(e: any) {
|
|
|
|
let secret = "";
|
|
|
|
if (this.tab == "totp") secret = this.totp(e);
|
|
|
|
else secret = await this.password(e);
|
|
|
|
|
2025-05-06 09:02:55 +02:00
|
|
|
if (secret == "") return;
|
|
|
|
|
2024-11-23 14:25:41 +01:00
|
|
|
this.inviteStatus = "loading";
|
|
|
|
this.inviteError = "";
|
|
|
|
this.$http
|
|
|
|
.put(`/invite`, {
|
|
|
|
token: this.token,
|
|
|
|
mail: this.mail,
|
2025-05-06 08:38:28 +02:00
|
|
|
secret: secret,
|
|
|
|
routine: this.tab,
|
2024-11-23 14:25:41 +01:00
|
|
|
})
|
|
|
|
.then((result) => {
|
|
|
|
this.inviteStatus = "success";
|
|
|
|
localStorage.setItem("accessToken", result.data.accessToken);
|
|
|
|
localStorage.setItem("refreshToken", result.data.refreshToken);
|
2025-07-24 08:51:36 +02:00
|
|
|
localStorage.setItem("routine", this.tab);
|
|
|
|
localStorage.setItem("username", this.username);
|
2024-11-23 14:25:41 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
this.$router.push(`/admin`);
|
|
|
|
}, 1000);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.inviteStatus = "failed";
|
|
|
|
this.inviteError = err.response.data;
|
|
|
|
});
|
|
|
|
},
|
2025-05-06 08:38:28 +02:00
|
|
|
totp(e: any) {
|
|
|
|
let formData = e.target.elements;
|
|
|
|
return formData.totp.value;
|
|
|
|
},
|
|
|
|
async password(e: any) {
|
|
|
|
let formData = e.target.elements;
|
2025-05-06 09:02:55 +02:00
|
|
|
|
|
|
|
let new_pw = await hashString(formData.password.value);
|
|
|
|
let new_rep = await hashString(formData.password_rep.value);
|
|
|
|
if (new_pw != new_rep) {
|
|
|
|
this.notMatching = true;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
this.notMatching = false;
|
|
|
|
|
2025-05-06 08:38:28 +02:00
|
|
|
return await hashString(formData.password.value);
|
|
|
|
},
|
2024-11-23 14:25:41 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|