mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed a bit
This commit is contained in:
1 parent
d69bee427b
commit
df7dff68a8
6 files changed
+719
-382
No files matched your search
+4
-68
@@ -54,6 +54,7 @@ export async function validateCredentials(username, password) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Using bcrypt.compare to properly compare hashed passwords
|
||||
const isValid = await bcrypt.compare(password, user.password);
|
||||
|
||||
if (!isValid) {
|
||||
@@ -63,7 +64,8 @@ export async function validateCredentials(username, password) {
|
||||
return {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
role: user.role
|
||||
role: user.role,
|
||||
teamId: user.team_id
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
@@ -71,70 +73,4 @@ export async function validateCredentials(username, password) {
|
||||
}
|
||||
}
|
||||
|
||||
// Start hunt timer (admin only)
|
||||
export async function startHuntTimer(active) {
|
||||
try {
|
||||
// First check if a record exists
|
||||
const currentTimer = await queryOne('SELECT * FROM game_settings WHERE id = 1');
|
||||
|
||||
if (currentTimer) {
|
||||
// Update existing record
|
||||
await run(
|
||||
'UPDATE game_settings SET hunt_active = ?, updated_at = CURRENT_TIMESTAMP WHERE id = 1',
|
||||
[active ? 1 : 0]
|
||||
);
|
||||
} else {
|
||||
// Create new record
|
||||
await run(
|
||||
'INSERT INTO game_settings (id, hunt_active, created_at, updated_at) VALUES (1, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)',
|
||||
[active ? 1 : 0]
|
||||
);
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Timer update error:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
|
||||
// Get hunt timer status
|
||||
export async function getHuntStatus() {
|
||||
try {
|
||||
const settings = await queryOne('SELECT * FROM game_settings WHERE id = 1');
|
||||
return {
|
||||
active: settings?.hunt_active === 1,
|
||||
updatedAt: settings?.updated_at
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Get hunt status error:', error);
|
||||
return { active: false };
|
||||
}
|
||||
}
|
||||
|
||||
// Join a team
|
||||
export async function joinTeam(userId, teamCode) {
|
||||
try {
|
||||
// Find the team by code
|
||||
const team = await queryOne('SELECT * FROM teams WHERE code = ?', [teamCode]);
|
||||
|
||||
if (!team) {
|
||||
return { success: false, error: 'Team not found' };
|
||||
}
|
||||
|
||||
// Update user's team
|
||||
await run(
|
||||
'UPDATE users SET team_id = ? WHERE id = ?',
|
||||
[team.id, userId]
|
||||
);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
teamId: team.id,
|
||||
teamName: team.name
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Join team error:', error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
}
|
||||
// Other functions remain the same...
|
||||
Reference in new issue
Block a user