forked from administration/panel
feat: look up user by email
parent
6ac8f771f8
commit
5cc8b6b71d
|
@ -2,14 +2,35 @@
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { toast } from "@/components/ui/use-toast";
|
||||||
|
import { lookupEmail } from "@/lib/actions";
|
||||||
import { API_URL } from "@/lib/constants";
|
import { API_URL } from "@/lib/constants";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function Inspect() {
|
export default function Inspect() {
|
||||||
const [id, setId] = useState("");
|
const [id, setId] = useState("");
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
const searchEmail = async () => {
|
||||||
|
try {
|
||||||
|
const result = await lookupEmail(email);
|
||||||
|
if (!result) toast({
|
||||||
|
title: "Not found",
|
||||||
|
description: "There doesn't seem to be any user with this email.",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
else router.push(`/panel/inspect/account/${result}`);
|
||||||
|
} catch(e) {
|
||||||
|
toast({
|
||||||
|
title: "Failed to look up",
|
||||||
|
description: String(e),
|
||||||
|
variant: "destructive",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const createHandler = (type: string) => () =>
|
const createHandler = (type: string) => () =>
|
||||||
router.push(`/panel/inspect/${type}/${id}`);
|
router.push(`/panel/inspect/${type}/${id}`);
|
||||||
|
|
||||||
|
@ -70,6 +91,23 @@ export default function Inspect() {
|
||||||
Message
|
Message
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
<hr />
|
||||||
|
<div className="flex gap-2 justify-between">
|
||||||
|
<Input
|
||||||
|
placeholder="Enter an email..."
|
||||||
|
value={email}
|
||||||
|
onChange={(e) => setEmail(e.currentTarget.value)}
|
||||||
|
onKeyDown={(e) => e.key == "Enter" && email && searchEmail()}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
className="flex"
|
||||||
|
variant="outline"
|
||||||
|
disabled={!email}
|
||||||
|
onClick={searchEmail}
|
||||||
|
>
|
||||||
|
Lookup
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ type Permission =
|
||||||
| "chat_message"
|
| "chat_message"
|
||||||
| `accounts${
|
| `accounts${
|
||||||
| ""
|
| ""
|
||||||
| `/fetch${"" | "/by-id"}`
|
| `/fetch${"" | "/by-id" | "/by-email"}`
|
||||||
| "/update/email"
|
| "/update/email"
|
||||||
| "/disable"
|
| "/disable"
|
||||||
| "/restore"
|
| "/restore"
|
||||||
|
@ -101,6 +101,7 @@ const PermissionSets = {
|
||||||
"users/update/badges",
|
"users/update/badges",
|
||||||
|
|
||||||
"accounts/fetch/by-id",
|
"accounts/fetch/by-id",
|
||||||
|
"accounts/fetch/by-email",
|
||||||
"accounts/disable",
|
"accounts/disable",
|
||||||
"accounts/restore",
|
"accounts/restore",
|
||||||
"accounts/deletion/queue",
|
"accounts/deletion/queue",
|
||||||
|
|
|
@ -28,6 +28,7 @@ import {
|
||||||
User,
|
User,
|
||||||
} from "revolt-api";
|
} from "revolt-api";
|
||||||
import { checkPermission } from "./accessPermissions";
|
import { checkPermission } from "./accessPermissions";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export async function sendAlert(userId: string, content: string) {
|
export async function sendAlert(userId: string, content: string) {
|
||||||
await checkPermission("users/create/alert", userId, { content });
|
await checkPermission("users/create/alert", userId, { content });
|
||||||
|
@ -249,6 +250,22 @@ export async function verifyAccountEmail(userId: string) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function lookupEmail(email: string): Promise<string | false> {
|
||||||
|
await checkPermission("accounts/fetch/by-email", email);
|
||||||
|
|
||||||
|
const accounts = mongo()
|
||||||
|
.db("revolt")
|
||||||
|
.collection<Account>("accounts");
|
||||||
|
|
||||||
|
let result = await accounts.findOne({ email: email });
|
||||||
|
if (result) return result._id;
|
||||||
|
|
||||||
|
result = await accounts.findOne({ email_normalised: email });
|
||||||
|
if (result) return result._id;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
export async function suspendUser(userId: string) {
|
export async function suspendUser(userId: string) {
|
||||||
if (RESTRICT_ACCESS_LIST.includes(userId)) throw "restricted access";
|
if (RESTRICT_ACCESS_LIST.includes(userId)) throw "restricted access";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue