Add files via upload
This commit is contained in:
parent
59b2fd19c9
commit
8baa7c2c55
2 changed files with 77 additions and 99 deletions
|
|
@ -76,7 +76,7 @@ export const root = new Elysia().use(userService).get(
|
||||||
// fallback: treat as normal user if role missing
|
// fallback: treat as normal user if role missing
|
||||||
user = { ...verifiedUser, id: verifiedUser.id, role: "user" };
|
user = { ...verifiedUser, id: verifiedUser.id, role: "user" };
|
||||||
} else {
|
} else {
|
||||||
user = verifiedUser as ({ id: string; role: string } & JWTPayloadSpec);
|
user = verifiedUser as { id: string; role: string } & JWTPayloadSpec;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,8 +266,8 @@ export const user = new Elysia()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
db.exec("ROLLBACK");
|
db.exec("ROLLBACK");
|
||||||
} catch (rollbackErr) {
|
} catch {
|
||||||
console.warn("[user/register] ROLLBACK failed:", rollbackErr);
|
// ignore rollback errors
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
@ -357,9 +357,7 @@ export const user = new Elysia()
|
||||||
.post(
|
.post(
|
||||||
"/login",
|
"/login",
|
||||||
async function handler({ body, set, redirect, jwt, cookie: { auth } }) {
|
async function handler({ body, set, redirect, jwt, cookie: { auth } }) {
|
||||||
const existingUser = db.query("SELECT * FROM users WHERE email = ?").as(User).get(
|
const existingUser = db.query("SELECT * FROM users WHERE email = ?").as(User).get(body.email);
|
||||||
body.email,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
set.status = 403;
|
set.status = 403;
|
||||||
|
|
@ -535,11 +533,7 @@ export const user = new Elysia()
|
||||||
</label>
|
</label>
|
||||||
<label class="flex flex-col gap-1">
|
<label class="flex flex-col gap-1">
|
||||||
Role
|
Role
|
||||||
<select
|
<select name="newUserRole" class="rounded-sm bg-neutral-800 p-3" required>
|
||||||
name="newUserRole"
|
|
||||||
class="rounded-sm bg-neutral-800 p-3"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="user">Normal user</option>
|
<option value="user">Normal user</option>
|
||||||
<option value="admin">Admin</option>
|
<option value="admin">Admin</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
@ -583,15 +577,8 @@ export const user = new Elysia()
|
||||||
<td>
|
<td>
|
||||||
<div class="flex items-center gap-6">
|
<div class="flex items-center gap-6">
|
||||||
{/* Edit / details icon */}
|
{/* Edit / details icon */}
|
||||||
<form
|
<form method="get" action={`${WEBROOT}/account/edit-user`}>
|
||||||
method="get"
|
<input type="hidden" name="userId" value={String(u.id)} />
|
||||||
action={`${WEBROOT}/account/edit-user`}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
type="hidden"
|
|
||||||
name="userId"
|
|
||||||
value={String(u.id)}
|
|
||||||
/>
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class={`
|
class={`
|
||||||
|
|
@ -684,9 +671,7 @@ export const user = new Elysia()
|
||||||
if (!tokenUser) {
|
if (!tokenUser) {
|
||||||
return redirect(`${WEBROOT}/login`, 302);
|
return redirect(`${WEBROOT}/login`, 302);
|
||||||
}
|
}
|
||||||
const existingUser = db.query("SELECT * FROM users WHERE id = ?").as(User).get(
|
const existingUser = db.query("SELECT * FROM users WHERE id = ?").as(User).get(tokenUser.id);
|
||||||
tokenUser.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!existingUser) {
|
if (!existingUser) {
|
||||||
if (auth?.value) {
|
if (auth?.value) {
|
||||||
|
|
@ -875,11 +860,7 @@ export const user = new Elysia()
|
||||||
</label>
|
</label>
|
||||||
<label class="flex flex-col gap-1">
|
<label class="flex flex-col gap-1">
|
||||||
Role
|
Role
|
||||||
<select
|
<select name="role" class="rounded-sm bg-neutral-800 p-3 capitalize" required>
|
||||||
name="role"
|
|
||||||
class="rounded-sm bg-neutral-800 p-3 capitalize"
|
|
||||||
required
|
|
||||||
>
|
|
||||||
<option value="user" selected={targetUser.role === "user"}>
|
<option value="user" selected={targetUser.role === "user"}>
|
||||||
Normal user
|
Normal user
|
||||||
</option>
|
</option>
|
||||||
|
|
@ -900,10 +881,7 @@ export const user = new Elysia()
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="flex flex-row gap-4">
|
<div class="flex flex-row gap-4">
|
||||||
<a
|
<a href={`${WEBROOT}/account`} class="w-full btn-secondary text-center">
|
||||||
href={`${WEBROOT}/account`}
|
|
||||||
class="w-full btn-secondary text-center"
|
|
||||||
>
|
|
||||||
Cancel
|
Cancel
|
||||||
</a>
|
</a>
|
||||||
<button type="submit" class="w-full btn-primary">
|
<button type="submit" class="w-full btn-primary">
|
||||||
|
|
@ -984,9 +962,10 @@ export const user = new Elysia()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields.length > 0) {
|
if (fields.length > 0) {
|
||||||
db.query(
|
db.query(`UPDATE users SET ${fields.map((f) => `${f}=?`).join(", ")} WHERE id=?`).run(
|
||||||
`UPDATE users SET ${fields.map((f) => `${f}=?`).join(", ")} WHERE id=?`,
|
...values,
|
||||||
).run(...values, targetId);
|
targetId,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect(`${WEBROOT}/account`, 302);
|
return redirect(`${WEBROOT}/account`, 302);
|
||||||
|
|
@ -1078,4 +1057,3 @@ export const user = new Elysia()
|
||||||
cookie: "session",
|
cookie: "session",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue