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 Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
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>) => {
|
||||
event.preventDefault();
|
||||
@@ -78,9 +95,14 @@ export default function LoginPage() {
|
||||
</button>
|
||||
</form>
|
||||
{error && <p className="mt-3 text-sm text-red-600">{error}</p>}
|
||||
{registrationEnabled !== false && (
|
||||
<p className="mt-4 text-sm text-slate-600">
|
||||
Kein Konto? <Link href="/register" className="text-brand-700">Registrieren</Link>
|
||||
Kein Konto?{" "}
|
||||
<Link href="/register" className="text-brand-700">
|
||||
Registrieren
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
<p className="mt-2 text-sm text-slate-600">
|
||||
Passwort vergessen?{" "}
|
||||
<Link href="/reset" className="text-brand-700">
|
||||
|
||||
@@ -2,11 +2,28 @@
|
||||
|
||||
import Link from "next/link";
|
||||
import { signIn } from "next-auth/react";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function RegisterPage() {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
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>) => {
|
||||
event.preventDefault();
|
||||
@@ -45,6 +62,16 @@ export default function RegisterPage() {
|
||||
<p className="mt-1 text-sm text-slate-600">
|
||||
Erstelle ein Konto, um Termine vorzuschlagen und eigene Ansichten anzulegen.
|
||||
</p>
|
||||
{registrationEnabled === false ? (
|
||||
<div className="mt-4 rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-sm text-slate-700">
|
||||
Registrierung ist derzeit deaktiviert.
|
||||
</div>
|
||||
) : registrationEnabled === null ? (
|
||||
<p className="mt-4 text-sm text-slate-600">
|
||||
Registrierung wird geladen...
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<form onSubmit={onSubmit} className="mt-4 space-y-3">
|
||||
<input
|
||||
name="name"
|
||||
@@ -70,8 +97,12 @@ export default function RegisterPage() {
|
||||
Konto anlegen
|
||||
</button>
|
||||
</form>
|
||||
{done && <p className="mt-3 text-sm text-emerald-600">Account erstellt.</p>}
|
||||
{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">
|
||||
Schon registriert? <Link href="/login" className="text-brand-700">Login</Link>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user