feat: toast notifications, canvas captcha, super admin, mobile fixes
- Toast system (ToastProvider + useToast): right-top colored toasts replace alert for publish success/error; CSS + layout mount - Captcha as canvas image (noise + distortion) in NewPost/ReplyList/ register modal — blocks bots, click to refresh - Super admin: first registered user cannot be demoted (isFirstUser by created_at, DB-agnostic) - Admins can delete others' posts/replies (UI buttons shown for admin) - Mobile: post-actions wrap + compact, feed excerpt 2.5 lines - Fix: missing sun icon in Icons (dark mode toggle showed nothing) - Feed long posts: gradient fade mask instead of line-clamp
This commit is contained in:
1 parent
e860978aef
commit
b2368f68df
12 files changed
+262
-31
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// PUT /api/users/[id] (更新资料), PUT /api/users/[id]/role (改角色)
|
||||
import pool from '@/lib/db';
|
||||
import { getUser, requireAdmin } from '@/lib/auth';
|
||||
import { getUser, requireAdmin, isFirstUser } from '@/lib/auth';
|
||||
|
||||
export async function PUT(req, { params }) {
|
||||
const { id } = params;
|
||||
@@ -22,6 +22,10 @@ export async function PUT(req, { params }) {
|
||||
if (id === user.id) {
|
||||
return Response.json({ error: '不能修改自己的角色' }, { status: 400 });
|
||||
}
|
||||
// 超级管理员(第一个用户)不能被降级
|
||||
if (role !== 'admin' && await isFirstUser(id)) {
|
||||
return Response.json({ error: '不能降级超级管理员' }, { status: 403 });
|
||||
}
|
||||
try {
|
||||
await pool.query('UPDATE users SET role = $1 WHERE id = $2', [role, id]);
|
||||
return Response.json({ success: true });
|
||||
|
||||
Reference in new issue
Block a user