Add settings page with profile, notifications, and admin sections

- Add sidebar navigation to settings page
- Add profile section for name management and password change
- Add admin section for user management and registration toggle
- Add profile API endpoints (GET/PUT /profile, PUT /profile/password)
- Add admin API endpoints (users CRUD, system settings)
- Add system_settings table for registration control
- Add name and is_admin columns to users table
- First registered user automatically becomes admin
- Check registration status on register/login page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-21 07:58:11 -05:00
parent 0c8ce22cc1
commit f46c6ad9d4
8 changed files with 1129 additions and 133 deletions

View file

@ -5,12 +5,25 @@ CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
name VARCHAR(255),
is_admin BOOLEAN DEFAULT false,
telegram_bot_token VARCHAR(255),
telegram_chat_id VARCHAR(255),
discord_webhook_url TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- System settings table
CREATE TABLE IF NOT EXISTS system_settings (
key VARCHAR(255) PRIMARY KEY,
value TEXT NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Default system settings
INSERT INTO system_settings (key, value) VALUES ('registration_enabled', 'true')
ON CONFLICT (key) DO NOTHING;
-- Migration: Add notification columns to users if they don't exist
DO $$
BEGIN
@ -24,6 +37,25 @@ BEGIN
END IF;
END $$;
-- Migration: Add profile columns to users if they don't exist
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'name'
) THEN
ALTER TABLE users ADD COLUMN name VARCHAR(255);
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'is_admin'
) THEN
ALTER TABLE users ADD COLUMN is_admin BOOLEAN DEFAULT false;
-- Make the first user an admin
UPDATE users SET is_admin = true WHERE id = (SELECT MIN(id) FROM users);
END IF;
END $$;
-- Products table
CREATE TABLE IF NOT EXISTS products (
id SERIAL PRIMARY KEY,