Automatische Registrierung
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { addNotification } from "#components/Notifications/shared.js";
|
||||
import { loginClient } from "#lib/login.js";
|
||||
import EmbeddedLoginModule from "./EmbeddedLoginModule.svelte"
|
||||
import EmbeddedRegisterModule from "./EmbeddedRegisterModule.svelte"
|
||||
@@ -17,7 +18,13 @@
|
||||
<EmbeddedLoginModule onLogin={onLogin} bind:email bind:password {navigate} />
|
||||
{:else if route == "signup"}
|
||||
<EmbeddedRegisterModule bind:email onRegister={(response) => {
|
||||
email = response.email
|
||||
navigate("verify")
|
||||
addNotification({
|
||||
message: "Registrierung erfolgreich",
|
||||
subtext: "Ein Passwort wurde an ihre Email Adresse gesendet, sie werden nun automatisch weitergeleitet..",
|
||||
type: "success",
|
||||
timeout: 6000,
|
||||
dismissable: true
|
||||
})
|
||||
onLogin(response)
|
||||
}} {navigate} />
|
||||
{/if}
|
||||
@@ -1,36 +1,22 @@
|
||||
<script lang="ts">
|
||||
import { loginClient } from "#lib/login.js";
|
||||
import { addNotification } from "@ibcornelsen/ui";
|
||||
import { api } from "astro-typesafe-api/client";
|
||||
|
||||
export let navigate: (target: string) => void;
|
||||
export let onRegister: (response: { email: string }) => void;
|
||||
export let onRegister: (response: Awaited<ReturnType<typeof loginClient>>) => void;
|
||||
export let email: string;
|
||||
|
||||
let repeatEmail: string;
|
||||
|
||||
async function signup(e: SubmitEvent) {
|
||||
e.preventDefault()
|
||||
|
||||
if (email !== repeatEmail) {
|
||||
addNotification({
|
||||
message: "Die eingegebenen Email Adressen stimmen nicht überein.",
|
||||
dismissable: true,
|
||||
timeout: 3000,
|
||||
type: "error"
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await api.user.autocreate.PUT.fetch({
|
||||
const { id, password } = await api.user.autocreate.PUT.fetch({
|
||||
email,
|
||||
});
|
||||
|
||||
onRegister({
|
||||
email,
|
||||
})
|
||||
|
||||
navigate("login")
|
||||
const response = await loginClient(email, password)
|
||||
onRegister(response);
|
||||
} catch (e) {
|
||||
addNotification({
|
||||
message: "Ups...",
|
||||
@@ -60,18 +46,6 @@
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Email erneut eingeben</h4>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="max.mustermann@email.de"
|
||||
name="repeat-email"
|
||||
class="px-2.5 py-1.5 rounded-lg border bg-gray-50"
|
||||
bind:value={repeatEmail}
|
||||
on:keyup={() => (repeatEmail = repeatEmail.toLowerCase())}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<button class="button" type="submit">Registrieren</button>
|
||||
<div class="flex flex-row justify-between" style="margin-top: 10px">
|
||||
<button on:click={() => navigate("login")}>Einloggen</button>
|
||||
|
||||
@@ -13,7 +13,9 @@ export const PUT = defineApiRoute({
|
||||
email: z.string().email(),
|
||||
}),
|
||||
output: z.object({
|
||||
id: IDWithPrefix
|
||||
email: z.string().email(),
|
||||
id: IDWithPrefix,
|
||||
password: z.string().min(8).max(100)
|
||||
}),
|
||||
async fetch(input) {
|
||||
let { email } = input;
|
||||
@@ -56,6 +58,6 @@ export const PUT = defineApiRoute({
|
||||
|
||||
await sendAutoRegisterMail(user, password)
|
||||
|
||||
return { id }
|
||||
return { id, email: user.email, password }
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user