Add password reset feature for admin users, enforce password change on login, and enhance session management
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
deleteUserAction,
|
||||
} from "@/app/actions/users";
|
||||
import { Flash } from "@/components/flash";
|
||||
import { ResetUserPassword } from "@/components/reset-user-password";
|
||||
import { requireAdminUser } from "@/lib/auth";
|
||||
import { db, initDatabase } from "@/lib/db";
|
||||
import { formatDate, queryMessage } from "@/lib/format";
|
||||
@@ -34,6 +35,9 @@ export default async function AdminUsersPage({
|
||||
)
|
||||
.all() as UserRow[];
|
||||
const adminCount = users.filter((u) => u.role === "admin").length;
|
||||
const currentAdminKeyCount = db
|
||||
.prepare("SELECT COUNT(*) AS count FROM webauthn_credentials WHERE user_id = ?")
|
||||
.get(currentUser.id) as { count: number };
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -93,11 +97,19 @@ export default async function AdminUsersPage({
|
||||
</td>
|
||||
<td>{formatDate(row.created_at.slice(0, 10))}</td>
|
||||
<td>
|
||||
{!isSelf && !lastAdmin && (
|
||||
<form action={deleteUserAction} className="inline-form">
|
||||
<input type="hidden" name="id" value={row.id} />
|
||||
<button className="link-button danger" type="submit">Löschen</button>
|
||||
</form>
|
||||
{!isSelf && (
|
||||
<div className="user-admin-actions">
|
||||
<ResetUserPassword
|
||||
userId={row.id}
|
||||
requiresYubiKey={currentAdminKeyCount.count > 0}
|
||||
/>
|
||||
{!lastAdmin && (
|
||||
<form action={deleteUserAction} className="inline-form">
|
||||
<input type="hidden" name="id" value={row.id} />
|
||||
<button className="link-button danger" type="submit">Löschen</button>
|
||||
</form>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user