CIA/e-voting-system/docker/create_active_election.sql
Alexis Bruneteau c6a0bb1654 feat: Complete frontend-backend API integration for voting system
This commit completes the voting system implementation with:

1. Frontend API Proxy Routes:
   - Created 9 Next.js API routes to proxy backend requests
   - Elections endpoints: /api/elections/*, /api/elections/{id}/*
   - Votes endpoints: /api/votes/*, /api/votes/submit/*, etc.
   - Auth endpoints: /api/auth/register/*, /api/auth/login/*, /api/auth/profile/*
   - Fixed Next.js 15.5 compatibility with Promise-based params

2. Backend Admin API:
   - Created /api/admin/fix-elgamal-keys endpoint
   - Created /api/admin/elections/elgamal-status endpoint
   - Created /api/admin/init-election-keys endpoint
   - All endpoints tested and working

3. Database Schema Fixes:
   - Fixed docker/create_active_election.sql to preserve ElGamal parameters
   - All elections now have elgamal_p=23, elgamal_g=5 set
   - Public keys generated for voting encryption

4. Documentation:
   - Added VOTING_SYSTEM_STATUS.md with complete status
   - Added FINAL_SETUP_STEPS.md with setup instructions
   - Added fix_elgamal_keys.py utility script

System Status:
 Backend: All 3 nodes operational with 12 elections
 Database: ElGamal parameters initialized
 Crypto: Public keys generated for active elections
 API: All endpoints verified working
 Frontend: Proxy routes created (ready for rebuild)

Next Step: docker compose up -d --build frontend

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 03:32:08 +01:00

42 lines
1.5 KiB
SQL

-- ================================================================
-- Ensure at least ONE active election exists for demo
-- ================================================================
-- Check if election 1 exists and update it to be active (from init.sql)
UPDATE elections
SET
is_active = TRUE,
start_date = DATE_SUB(NOW(), INTERVAL 1 HOUR),
end_date = DATE_ADD(NOW(), INTERVAL 7 DAY),
elgamal_p = 23,
elgamal_g = 5
WHERE id = 1;
-- If no active elections exist, create one
INSERT IGNORE INTO elections (id, name, description, start_date, end_date, elgamal_p, elgamal_g, is_active, results_published)
SELECT
1,
'Election Présidentielle 2025',
'Vote pour la présidence',
DATE_SUB(NOW(), INTERVAL 1 HOUR),
DATE_ADD(NOW(), INTERVAL 7 DAY),
23,
5,
TRUE,
FALSE
WHERE NOT EXISTS (SELECT 1 FROM elections WHERE id = 1);
-- Ensure election 1 has candidates (from init.sql)
INSERT IGNORE INTO candidates (id, election_id, name, description, `order`)
VALUES
(1, 1, 'Alice Dupont', 'Candidate pour le changement', 1),
(2, 1, 'Bob Martin', 'Candidate pour la stabilité', 2),
(3, 1, 'Charlie Leclerc', 'Candidate pour l''innovation', 3),
(4, 1, 'Diana Fontaine', 'Candidate pour l''environnement', 4);
-- Confirmation
SELECT 'Active elections configured' as status;
SELECT COUNT(*) as total_elections FROM elections;
SELECT COUNT(*) as active_elections FROM elections WHERE is_active = TRUE;
SELECT id, name, is_active, start_date, end_date FROM elections LIMIT 5;