forked from administration/panel
feat: look up user by email
parent
5c78020a3e
commit
3a2e886803
|
@ -2,14 +2,35 @@
|
|||
|
||||
import { Button } from "@/components/ui/button";
|
||||
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 { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function Inspect() {
|
||||
const [id, setId] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
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) => () =>
|
||||
router.push(`/panel/inspect/${type}/${id}`);
|
||||
|
||||
|
@ -70,6 +91,23 @@ export default function Inspect() {
|
|||
Message
|
||||
</Button>
|
||||
</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>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ type Permission =
|
|||
| "chat_message"
|
||||
| `accounts${
|
||||
| ""
|
||||
| `/fetch${"" | "/by-id"}`
|
||||
| `/fetch${"" | "/by-id" | "/by-email"}`
|
||||
| "/update/email"
|
||||
| "/disable"
|
||||
| "/restore"
|
||||
|
@ -101,6 +101,7 @@ const PermissionSets = {
|
|||
"users/update/badges",
|
||||
|
||||
"accounts/fetch/by-id",
|
||||
"accounts/fetch/by-email",
|
||||
"accounts/disable",
|
||||
"accounts/restore",
|
||||
"accounts/deletion/queue",
|
||||
|
|
|
@ -28,6 +28,7 @@ import {
|
|||
User,
|
||||
} from "revolt-api";
|
||||
import { checkPermission } from "./accessPermissions";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function sendAlert(userId: string, content: string) {
|
||||
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) {
|
||||
if (RESTRICT_ACCESS_LIST.includes(userId)) throw "restricted access";
|
||||
|
||||
|
|
Loading…
Reference in New Issue