mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-05-13 01:32:40 +02:00
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:
parent
0c8ce22cc1
commit
f46c6ad9d4
8 changed files with 1129 additions and 133 deletions
|
|
@ -1,15 +1,33 @@
|
|||
import { Router, Request, Response } from 'express';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { userQueries } from '../models';
|
||||
import { userQueries, systemSettingsQueries } from '../models';
|
||||
import { generateToken } from '../middleware/auth';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// Check if registration is enabled (public endpoint for login page)
|
||||
router.get('/registration-status', async (_req: Request, res: Response) => {
|
||||
try {
|
||||
const enabled = await systemSettingsQueries.get('registration_enabled');
|
||||
res.json({ registration_enabled: enabled !== 'false' });
|
||||
} catch (error) {
|
||||
console.error('Error checking registration status:', error);
|
||||
res.json({ registration_enabled: true }); // Default to true on error
|
||||
}
|
||||
});
|
||||
|
||||
// Register new user
|
||||
router.post('/register', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const { email, password } = req.body;
|
||||
|
||||
// Check if registration is enabled
|
||||
const registrationEnabled = await systemSettingsQueries.get('registration_enabled');
|
||||
if (registrationEnabled === 'false') {
|
||||
res.status(403).json({ error: 'Registration is currently disabled' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!email || !password) {
|
||||
res.status(400).json({ error: 'Email and password are required' });
|
||||
return;
|
||||
|
|
@ -36,6 +54,13 @@ router.post('/register', async (req: Request, res: Response) => {
|
|||
const passwordHash = await bcrypt.hash(password, saltRounds);
|
||||
|
||||
const user = await userQueries.create(email, passwordHash);
|
||||
|
||||
// Make first user an admin
|
||||
const allUsers = await userQueries.findAll();
|
||||
if (allUsers.length === 1) {
|
||||
await userQueries.setAdmin(user.id, true);
|
||||
}
|
||||
|
||||
const token = generateToken(user.id);
|
||||
|
||||
res.status(201).json({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue