diff --git a/server/auth.js b/server/auth.js index bf0d6ad..0d7a8c1 100644 --- a/server/auth.js +++ b/server/auth.js @@ -1,34 +1,25 @@ const argon2 = require('argon2'); -const speakeasy = require('speakeasy'); +const crypto = require('crypto'); // Generate Admin Credentials const createAdmin = async (password) => { const accessKey = crypto.randomBytes(16).toString('hex'); const hash = await argon2.hash(password); - const totpSecret = speakeasy.generateSecret({ length: 20 }); - return { - accessKey, - hash, - totpSecret: totpSecret.base32 - }; + return { accessKey, hash }; }; // Verify Admin Login -const verifyAdmin = async (accessKey, password, token) => { - const { rows: [admin] } = await db.query( - 'SELECT * FROM admins WHERE access_key = $1', +const verifyAdmin = async (accessKey, password) => { + const admins = await db.query( + 'SELECT * FROM admins WHERE access_key = ?', [accessKey] ); + const admin = admins[0]; if (!admin || !await argon2.verify(admin.argon2_hash, password)) { return false; } - return speakeasy.totp.verify({ - secret: admin.totp_secret, - encoding: 'base32', - token, - window: 1 - }); + return true; }; module.exports = { createAdmin, verifyAdmin }; \ No newline at end of file diff --git a/server/controllers/adminController.js b/server/controllers/adminController.js index 02f1fd5..95bc081 100644 --- a/server/controllers/adminController.js +++ b/server/controllers/adminController.js @@ -35,7 +35,7 @@ exports.publishResult = async (data, authorization) => { // publish result using team id await db.query(` INSERT INTO results (team_id, result_date, result, announcement_time) - VALUES (?, ?, ?, COALESCE(?, '00:00:00')) + VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE result = VALUES(result), announcement_time = VALUES(announcement_time) diff --git a/server/controllers/resultController.js b/server/controllers/resultController.js index f989bc8..1ec540e 100644 --- a/server/controllers/resultController.js +++ b/server/controllers/resultController.js @@ -11,6 +11,8 @@ exports.getMonthlyResults = async (req, res) => { FROM results r JOIN teams t ON r.team_id = t.id WHERE t.name = ? AND DATE_FORMAT(r.result_date, '%Y-%m') = ? + AND (r.result_date < CURDATE() + OR (r.result_date = CURDATE() AND r.announcement_time <= CURTIME())) `, [team.toUpperCase(), month]); if (results.length === 0) { return res.status(404).json({ message: 'No results found for this team in the specified month.' }); @@ -32,6 +34,8 @@ exports.getDailyResults = async (req, res) => { FROM results r JOIN teams t ON r.team_id = t.id WHERE r.result_date = ? + AND (r.result_date < CURDATE() + OR (r.result_date = CURDATE() AND r.announcement_time <= CURTIME())) `, [date]); if (results.length === 0) { return res.status(404).json({ message: 'No results found for the specified date.' }); diff --git a/server/routes/public.js b/server/routes/public.js index 68e25c6..9cfe1f8 100644 --- a/server/routes/public.js +++ b/server/routes/public.js @@ -18,6 +18,8 @@ router.get('/results', async (req, res) => { FROM results r JOIN teams t ON r.team_id = t.id WHERE t.name = ? AND r.result_date = ? + AND (r.result_date < CURDATE() + OR (r.result_date = CURDATE() AND r.announcement_time <= CURTIME())) `, [team.toUpperCase(), date]); if (!result) return res.status(404).json({ error: 'Result not found' }); @@ -43,6 +45,8 @@ router.get('/today', async (req, res) => { FROM results r JOIN teams t ON r.team_id = t.id WHERE r.result_date = ? + AND (r.result_date < CURDATE() + OR (r.result_date = CURDATE() AND r.announcement_time <= CURTIME())) `, [today]); cache.set(cacheKey, results);