mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-31 06:59:33 +02:00
fix update server admin email cause create new user closes #443
This commit is contained in:
parent
1d105fc5be
commit
6204fa0ade
3 changed files with 22 additions and 30 deletions
|
@ -29,7 +29,7 @@ export async function setupServerAdmin() {
|
||||||
const [existing] = await trx
|
const [existing] = await trx
|
||||||
.select()
|
.select()
|
||||||
.from(users)
|
.from(users)
|
||||||
.where(eq(users.email, email));
|
.where(eq(users.serverAdmin, true));
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
const passwordChanged = !(await verifyPassword(
|
const passwordChanged = !(await verifyPassword(
|
||||||
|
@ -46,41 +46,33 @@ export async function setupServerAdmin() {
|
||||||
// this isn't using the transaction, but it's probably fine
|
// this isn't using the transaction, but it's probably fine
|
||||||
await invalidateAllSessions(existing.userId);
|
await invalidateAllSessions(existing.userId);
|
||||||
|
|
||||||
logger.info(`Server admin (${email}) password updated`);
|
logger.info(`Server admin password updated`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existing.serverAdmin) {
|
if (existing.email !== email) {
|
||||||
logger.info(`Server admin (${email}) already exists`)
|
await trx
|
||||||
return;
|
.update(users)
|
||||||
|
.set({ email })
|
||||||
|
.where(eq(users.userId, existing.userId));
|
||||||
|
|
||||||
|
logger.info(`Server admin email updated`);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const userId = generateId(15);
|
||||||
|
|
||||||
await trx.update(users).set({ serverAdmin: false });
|
await trx.update(users).set({ serverAdmin: false });
|
||||||
|
|
||||||
await trx
|
await db.insert(users).values({
|
||||||
.update(users)
|
userId: userId,
|
||||||
.set({
|
email: email,
|
||||||
serverAdmin: true
|
passwordHash,
|
||||||
})
|
dateCreated: moment().toISOString(),
|
||||||
.where(eq(users.email, email));
|
serverAdmin: true,
|
||||||
|
emailVerified: true
|
||||||
|
});
|
||||||
|
|
||||||
logger.info(`Server admin (${email}) set`);
|
logger.info(`Server admin created`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = generateId(15);
|
|
||||||
|
|
||||||
await trx.update(users).set({ serverAdmin: false });
|
|
||||||
|
|
||||||
await db.insert(users).values({
|
|
||||||
userId: userId,
|
|
||||||
email: email,
|
|
||||||
passwordHash,
|
|
||||||
dateCreated: moment().toISOString(),
|
|
||||||
serverAdmin: true,
|
|
||||||
emailVerified: true
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.info(`Server admin (${email}) created`);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error(e);
|
logger.error(e);
|
||||||
trx.rollback();
|
trx.rollback();
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default function CopyTextBox({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`relative w-full border rounded-md ${!outline ? "bg-muted" : "bg-card"}`}
|
className={`relative w-full border-2 rounded-md ${!outline ? "bg-muted" : "bg-card"}`}
|
||||||
>
|
>
|
||||||
<pre
|
<pre
|
||||||
ref={textRef}
|
ref={textRef}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority";
|
||||||
import { cn } from "@app/lib/cn";
|
import { cn } from "@app/lib/cn";
|
||||||
|
|
||||||
const alertVariants = cva(
|
const alertVariants = cva(
|
||||||
"relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
|
"relative w-full rounded-lg border-2 p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue