Aktueller Stand
This commit is contained in:
10
app/api/settings/registration/route.ts
Normal file
10
app/api/settings/registration/route.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { prisma } from "../../../../lib/prisma";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const setting = await prisma.setting.findUnique({
|
||||||
|
where: { key: "registration_enabled" }
|
||||||
|
});
|
||||||
|
const registrationEnabled = setting?.value !== "false";
|
||||||
|
return NextResponse.json({ registrationEnabled });
|
||||||
|
}
|
||||||
@@ -3,12 +3,29 @@
|
|||||||
import { signIn } from "next-auth/react";
|
import { signIn } from "next-auth/react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function LoginPage() {
|
export default function LoginPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [showVerifyLink, setShowVerifyLink] = useState(false);
|
const [showVerifyLink, setShowVerifyLink] = useState(false);
|
||||||
|
const [registrationEnabled, setRegistrationEnabled] = useState<boolean | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadRegistration = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/settings/registration");
|
||||||
|
if (!response.ok) return;
|
||||||
|
const payload = await response.json();
|
||||||
|
setRegistrationEnabled(payload.registrationEnabled !== false);
|
||||||
|
} catch {
|
||||||
|
setRegistrationEnabled(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
loadRegistration();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -78,9 +95,14 @@ export default function LoginPage() {
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
{error && <p className="mt-3 text-sm text-red-600">{error}</p>}
|
{error && <p className="mt-3 text-sm text-red-600">{error}</p>}
|
||||||
<p className="mt-4 text-sm text-slate-600">
|
{registrationEnabled !== false && (
|
||||||
Kein Konto? <Link href="/register" className="text-brand-700">Registrieren</Link>
|
<p className="mt-4 text-sm text-slate-600">
|
||||||
</p>
|
Kein Konto?{" "}
|
||||||
|
<Link href="/register" className="text-brand-700">
|
||||||
|
Registrieren
|
||||||
|
</Link>
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
<p className="mt-2 text-sm text-slate-600">
|
<p className="mt-2 text-sm text-slate-600">
|
||||||
Passwort vergessen?{" "}
|
Passwort vergessen?{" "}
|
||||||
<Link href="/reset" className="text-brand-700">
|
<Link href="/reset" className="text-brand-700">
|
||||||
|
|||||||
@@ -2,11 +2,28 @@
|
|||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { signIn } from "next-auth/react";
|
import { signIn } from "next-auth/react";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export default function RegisterPage() {
|
export default function RegisterPage() {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [done, setDone] = useState(false);
|
const [done, setDone] = useState(false);
|
||||||
|
const [registrationEnabled, setRegistrationEnabled] = useState<boolean | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadRegistration = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/settings/registration");
|
||||||
|
if (!response.ok) return;
|
||||||
|
const payload = await response.json();
|
||||||
|
setRegistrationEnabled(payload.registrationEnabled !== false);
|
||||||
|
} catch {
|
||||||
|
setRegistrationEnabled(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
loadRegistration();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -45,33 +62,47 @@ export default function RegisterPage() {
|
|||||||
<p className="mt-1 text-sm text-slate-600">
|
<p className="mt-1 text-sm text-slate-600">
|
||||||
Erstelle ein Konto, um Termine vorzuschlagen und eigene Ansichten anzulegen.
|
Erstelle ein Konto, um Termine vorzuschlagen und eigene Ansichten anzulegen.
|
||||||
</p>
|
</p>
|
||||||
<form onSubmit={onSubmit} className="mt-4 space-y-3">
|
{registrationEnabled === false ? (
|
||||||
<input
|
<div className="mt-4 rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-700">
|
||||||
name="name"
|
Registrierung ist derzeit deaktiviert.
|
||||||
type="text"
|
</div>
|
||||||
placeholder="Name"
|
) : registrationEnabled === null ? (
|
||||||
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
<p className="mt-4 text-sm text-slate-600">
|
||||||
/>
|
Registrierung wird geladen...
|
||||||
<input
|
</p>
|
||||||
name="email"
|
) : (
|
||||||
type="email"
|
<>
|
||||||
placeholder="E-Mail"
|
<form onSubmit={onSubmit} className="mt-4 space-y-3">
|
||||||
required
|
<input
|
||||||
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
name="name"
|
||||||
/>
|
type="text"
|
||||||
<input
|
placeholder="Name"
|
||||||
name="password"
|
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
||||||
type="password"
|
/>
|
||||||
placeholder="Passwort"
|
<input
|
||||||
required
|
name="email"
|
||||||
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
type="email"
|
||||||
/>
|
placeholder="E-Mail"
|
||||||
<button type="submit" className="btn-accent w-full">
|
required
|
||||||
Konto anlegen
|
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
||||||
</button>
|
/>
|
||||||
</form>
|
<input
|
||||||
{done && <p className="mt-3 text-sm text-emerald-600">Account erstellt.</p>}
|
name="password"
|
||||||
{error && <p className="mt-3 text-sm text-red-600">{error}</p>}
|
type="password"
|
||||||
|
placeholder="Passwort"
|
||||||
|
required
|
||||||
|
className="w-full rounded-xl border border-slate-300 px-3 py-2"
|
||||||
|
/>
|
||||||
|
<button type="submit" className="btn-accent w-full">
|
||||||
|
Konto anlegen
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{done && (
|
||||||
|
<p className="mt-3 text-sm text-emerald-600">Account erstellt.</p>
|
||||||
|
)}
|
||||||
|
{error && <p className="mt-3 text-sm text-red-600">{error}</p>}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<p className="mt-4 text-sm text-slate-600">
|
<p className="mt-4 text-sm text-slate-600">
|
||||||
Schon registriert? <Link href="/login" className="text-brand-700">Login</Link>
|
Schon registriert? <Link href="/login" className="text-brand-700">Login</Link>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user