Merge pull request #184 from linkwarden/dev

added the ability to disable registration
This commit is contained in:
Daniel 2023-09-28 19:08:43 +03:30 committed by GitHub
commit ea7f08aba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 132 additions and 115 deletions

View File

@ -7,6 +7,7 @@ NEXTAUTH_URL=http://localhost:3000
PAGINATION_TAKE_COUNT=
STORAGE_FOLDER=
AUTOSCROLL_TIMEOUT=
NEXT_PUBLIC_DISABLE_REGISTRATION=
# AWS S3 Settings
SPACES_KEY=

View File

@ -20,6 +20,10 @@ export default async function Index(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
if (process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true") {
return res.status(400).json({ response: "Registration is disabled." });
}
const body: User = req.body;
const checkHasEmptyFields = emailEnabled

View File

@ -97,15 +97,17 @@ export default function Login() {
className=" w-full text-center"
loading={submitLoader}
/>
<div className="flex items-baseline gap-1 justify-center">
<p className="w-fit text-gray-500 dark:text-gray-400">New here?</p>
<Link
href={"/register"}
className="block text-black dark:text-white font-semibold"
>
Sign Up
</Link>
</div>
{process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? undefined : (
<div className="flex items-baseline gap-1 justify-center">
<p className="w-fit text-gray-500 dark:text-gray-400">New here?</p>
<Link
href={"/register"}
className="block text-black dark:text-white font-semibold"
>
Sign Up
</Link>
</div>
)}
</div>
</CenteredForm>
);

View File

@ -99,134 +99,143 @@ export default function Register() {
: "Create a new account"
}
>
<div className="p-4 flex flex-col gap-3 justify-between sm:w-[30rem] w-80 bg-slate-50 dark:bg-neutral-800 rounded-2xl shadow-md border border-sky-100 dark:border-neutral-700">
<p className="text-2xl text-black dark:text-white text-center font-bold">
Enter your details
</p>
<div>
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Display Name
{process.env.NEXT_PUBLIC_DISABLE_REGISTRATION === "true" ? (
<div className="p-4 flex flex-col gap-3 justify-between sm:w-[30rem] w-80 bg-slate-50 dark:bg-neutral-800 rounded-2xl shadow-md border border-sky-100 dark:border-neutral-700">
<p>
Registration is disabled for this instance, please contact the admin
in case of any issues.
</p>
<TextInput
placeholder="Johnny"
value={form.name}
className="bg-white"
onChange={(e) => setForm({ ...form, name: e.target.value })}
/>
</div>
{emailEnabled ? undefined : (
) : (
<div className="p-4 flex flex-col gap-3 justify-between sm:w-[30rem] w-80 bg-slate-50 dark:bg-neutral-800 rounded-2xl shadow-md border border-sky-100 dark:border-neutral-700">
<p className="text-2xl text-black dark:text-white text-center font-bold">
Enter your details
</p>
<div>
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Username
Display Name
</p>
<TextInput
placeholder="john"
value={form.username}
placeholder="Johnny"
value={form.name}
className="bg-white"
onChange={(e) => setForm({ ...form, username: e.target.value })}
onChange={(e) => setForm({ ...form, name: e.target.value })}
/>
</div>
)}
{emailEnabled ? (
<div>
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Email
{emailEnabled ? undefined : (
<div>
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Username
</p>
<TextInput
placeholder="john"
value={form.username}
className="bg-white"
onChange={(e) => setForm({ ...form, username: e.target.value })}
/>
</div>
)}
{emailEnabled ? (
<div>
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Email
</p>
<TextInput
type="email"
placeholder="johnny@example.com"
value={form.email}
className="bg-white"
onChange={(e) => setForm({ ...form, email: e.target.value })}
/>
</div>
) : undefined}
<div className="w-full">
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Password
</p>
<TextInput
type="email"
placeholder="johnny@example.com"
value={form.email}
type="password"
placeholder="••••••••••••••"
value={form.password}
className="bg-white"
onChange={(e) => setForm({ ...form, email: e.target.value })}
onChange={(e) => setForm({ ...form, password: e.target.value })}
/>
</div>
) : undefined}
<div className="w-full">
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Password
</p>
<TextInput
type="password"
placeholder="••••••••••••••"
value={form.password}
className="bg-white"
onChange={(e) => setForm({ ...form, password: e.target.value })}
/>
</div>
<div className="w-full">
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Confirm Password
</p>
<TextInput
type="password"
placeholder="••••••••••••••"
value={form.passwordConfirmation}
className="bg-white"
onChange={(e) =>
setForm({ ...form, passwordConfirmation: e.target.value })
}
/>
</div>
{process.env.NEXT_PUBLIC_STRIPE_IS_ACTIVE ? (
<div>
<p className="text-xs text-gray-500 dark:text-gray-400">
By signing up, you agree to our{" "}
<Link
href="https://linkwarden.app/tos"
className="font-semibold underline"
>
Terms of Service
</Link>{" "}
and{" "}
<Link
href="https://linkwarden.app/privacy-policy"
className="font-semibold underline"
>
Privacy Policy
</Link>
.
</p>
<p className="text-xs text-gray-500 dark:text-gray-400">
Need help?{" "}
<Link
href="mailto:support@linkwarden.app"
className="font-semibold underline"
>
Get in touch
</Link>
.
<div className="w-full">
<p className="text-sm text-black dark:text-white w-fit font-semibold mb-1">
Confirm Password
</p>
<TextInput
type="password"
placeholder="••••••••••••••"
value={form.passwordConfirmation}
className="bg-white"
onChange={(e) =>
setForm({ ...form, passwordConfirmation: e.target.value })
}
/>
</div>
) : undefined}
<SubmitButton
onClick={registerUser}
label="Sign Up"
className="mt-2 w-full text-center"
loading={submitLoader}
/>
<div className="flex items-baseline gap-1 justify-center">
<p className="w-fit text-gray-500 dark:text-gray-400">
Already have an account?
</p>
<Link
href={"/login"}
className="block text-black dark:text-white font-bold"
>
Login
</Link>
{process.env.NEXT_PUBLIC_STRIPE_IS_ACTIVE ? (
<div>
<p className="text-xs text-gray-500 dark:text-gray-400">
By signing up, you agree to our{" "}
<Link
href="https://linkwarden.app/tos"
className="font-semibold underline"
>
Terms of Service
</Link>{" "}
and{" "}
<Link
href="https://linkwarden.app/privacy-policy"
className="font-semibold underline"
>
Privacy Policy
</Link>
.
</p>
<p className="text-xs text-gray-500 dark:text-gray-400">
Need help?{" "}
<Link
href="mailto:support@linkwarden.app"
className="font-semibold underline"
>
Get in touch
</Link>
.
</p>
</div>
) : undefined}
<SubmitButton
onClick={registerUser}
label="Sign Up"
className="mt-2 w-full text-center"
loading={submitLoader}
/>
<div className="flex items-baseline gap-1 justify-center">
<p className="w-fit text-gray-500 dark:text-gray-400">
Already have an account?
</p>
<Link
href={"/login"}
className="block text-black dark:text-white font-bold"
>
Login
</Link>
</div>
</div>
</div>
)}
</CenteredForm>
);
}

View File

@ -4,6 +4,7 @@ declare global {
NEXTAUTH_SECRET: string;
DATABASE_URL: string;
NEXTAUTH_URL: string;
NEXT_PUBLIC_DISABLE_REGISTRATION?: string;
PAGINATION_TAKE_COUNT?: string;
STORAGE_FOLDER?: string;
AUTOSCROLL_TIMEOUT?: string;