Merge branch 'feat/dark-mode' into feat/dark-mode
This commit is contained in:
@@ -31,10 +31,10 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
.status(401)
|
||||
.json({ response: "You don't have access to this collection." });
|
||||
|
||||
const { file, contentType } = await readFile({
|
||||
filePath: `archives/${collectionId}/${linkId}`,
|
||||
});
|
||||
res.setHeader("Content-Type", contentType).status(200);
|
||||
const { file, contentType, status } = await readFile(
|
||||
`archives/${collectionId}/${linkId}`
|
||||
);
|
||||
res.setHeader("Content-Type", contentType).status(status as number);
|
||||
|
||||
return res.send(file);
|
||||
}
|
||||
|
||||
+18
-13
@@ -13,7 +13,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (!userId || !username)
|
||||
return res
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setHeader("Content-Type", "text/html")
|
||||
.status(401)
|
||||
.send("You must be logged in.");
|
||||
else if (session?.user?.isSubscriber === false)
|
||||
@@ -24,7 +24,7 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
if (!queryId)
|
||||
return res
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setHeader("Content-Type", "text/html")
|
||||
.status(401)
|
||||
.send("Invalid parameters.");
|
||||
|
||||
@@ -33,23 +33,28 @@ export default async function Index(req: NextApiRequest, res: NextApiResponse) {
|
||||
where: {
|
||||
id: queryId,
|
||||
},
|
||||
include: {
|
||||
whitelistedUsers: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (
|
||||
targetUser?.isPrivate &&
|
||||
!targetUser.whitelistedUsers.includes(username)
|
||||
) {
|
||||
const whitelistedUsernames = targetUser?.whitelistedUsers.map(
|
||||
(whitelistedUsername) => whitelistedUsername.username
|
||||
);
|
||||
|
||||
if (targetUser?.isPrivate && !whitelistedUsernames?.includes(username)) {
|
||||
return res
|
||||
.setHeader("Content-Type", "text/plain")
|
||||
.setHeader("Content-Type", "text/html")
|
||||
.send("This profile is private.");
|
||||
}
|
||||
}
|
||||
|
||||
const { file, contentType } = await readFile({
|
||||
filePath: `uploads/avatar/${queryId}.jpg`,
|
||||
});
|
||||
const { file, contentType, status } = await readFile(
|
||||
`uploads/avatar/${queryId}.jpg`
|
||||
);
|
||||
|
||||
res.setHeader("Content-Type", contentType);
|
||||
|
||||
return res.send(file);
|
||||
return res
|
||||
.setHeader("Content-Type", contentType)
|
||||
.status(status as number)
|
||||
.send(file);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getServerSession } from "next-auth/next";
|
||||
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
||||
import getData from "@/lib/api/controllers/data/getData";
|
||||
import postData from "@/lib/api/controllers/data/postData";
|
||||
|
||||
export default async function users(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getServerSession(req, res, authOptions);
|
||||
|
||||
if (!session?.user.id) {
|
||||
return res.status(401).json({ response: "You must be logged in." });
|
||||
} else if (session?.user?.isSubscriber === false)
|
||||
res.status(401).json({
|
||||
response:
|
||||
"You are not a subscriber, feel free to reach out to us at support@linkwarden.app in case of any issues.",
|
||||
});
|
||||
|
||||
if (req.method === "GET") {
|
||||
const data = await getData(session.user.id);
|
||||
if (data.status === 200)
|
||||
return res
|
||||
.setHeader("Content-Type", "application/json")
|
||||
.setHeader("Content-Disposition", "attachment; filename=backup.json")
|
||||
.status(data.status)
|
||||
.json(data.response);
|
||||
} else if (req.method === "POST") {
|
||||
console.log(JSON.parse(req.body));
|
||||
const data = await postData(session.user.id, JSON.parse(req.body));
|
||||
return res.status(data.status).json({ response: data.response });
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export default function EmailConfirmaion() {
|
||||
<hr className="my-5" />
|
||||
|
||||
<p className="text-sm text-gray-500 ">
|
||||
If you didn't recieve anything, go to the{" "}
|
||||
If you didn't receive anything, go to the{" "}
|
||||
<Link href="/forgot" className="font-bold">
|
||||
Password Recovery
|
||||
</Link>{" "}
|
||||
|
||||
+10
-11
@@ -3,7 +3,7 @@ import { useState } from "react";
|
||||
import { toast } from "react-hot-toast";
|
||||
import SubmitButton from "@/components/SubmitButton";
|
||||
import { signIn } from "next-auth/react";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/router";
|
||||
import CenteredForm from "@/layouts/CenteredForm";
|
||||
|
||||
const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER;
|
||||
@@ -18,6 +18,7 @@ type FormData = {
|
||||
|
||||
export default function Register() {
|
||||
const [submitLoader, setSubmitLoader] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const [form, setForm] = useState<FormData>({
|
||||
name: "",
|
||||
@@ -28,7 +29,7 @@ export default function Register() {
|
||||
});
|
||||
|
||||
async function registerUser() {
|
||||
const checkHasEmptyFields = () => {
|
||||
const checkFields = () => {
|
||||
if (emailEnabled) {
|
||||
return (
|
||||
form.name !== "" &&
|
||||
@@ -46,14 +47,7 @@ export default function Register() {
|
||||
}
|
||||
};
|
||||
|
||||
const sendConfirmation = async () => {
|
||||
await signIn("email", {
|
||||
email: form.email,
|
||||
callbackUrl: "/",
|
||||
});
|
||||
};
|
||||
|
||||
if (checkHasEmptyFields()) {
|
||||
if (checkFields()) {
|
||||
if (form.password !== form.passwordConfirmation)
|
||||
return toast.error("Passwords do not match.");
|
||||
else if (form.password.length < 8)
|
||||
@@ -78,7 +72,12 @@ export default function Register() {
|
||||
setSubmitLoader(false);
|
||||
|
||||
if (response.ok) {
|
||||
if (form.email) await sendConfirmation();
|
||||
if (form.email && emailEnabled)
|
||||
await signIn("email", {
|
||||
email: form.email,
|
||||
callbackUrl: "/",
|
||||
});
|
||||
else if (!emailEnabled) router.push("/login");
|
||||
|
||||
toast.success("User Created!");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user