The Great Refactoring

This commit is contained in:
2026-06-06 10:27:33 +02:00
parent f543405964
commit 06f862c68a
16 changed files with 2168 additions and 2055 deletions
@@ -228,7 +228,7 @@ export const resendOTP = async (req, res) => {
} catch (error) {
if (['ERR_USER_NOT_FOUND', 'ERR_ALREADY_VERIFIED', 'ERR_COOLDOWN_ACTIVE'].includes(error.code)) {
const statusCode = error.code === 'ERR_COOLDOWN_ACTIVE' ? 429 : 400;
return res.status(error.code).json({
return res.status(statusCode).json({
error: error.code
});
}
@@ -253,6 +253,8 @@ export const requestPasswordReset = async (req, res) => {
});
}
await authService.requestPasswordReset(email);
// Auch wenn die E-Mail nicht existiert, geben wir oft ein Success zurück,
// damit Angreifer nicht testen können, welche E-Mails registriert sind.
// In unserem Service werfen wir aber ERR_USER_NOT_FOUND. Wir fangen das unten ab.
@@ -37,11 +37,12 @@ export const getSectorsList = async(req, res) => {
ORDER BY created_at ASC
`, [accountId]);
// Daten platzhalter
const mapSectorData = (sector) => ({
...sector,
online_players: Math.floor(Math.random() * 150) + 10,
planets_count: 1337
planets_count: (Math.floor(Math.random() * 150) + 10) * 12
});
@@ -482,7 +482,7 @@ export const requestPasswordReset = async (email) => {
const lastOtpResult = await client.query(`
SELECT created_at FROM auth_otps WHERE account_id = $1 AND type = 'password_reset' ORDER BY created_at DESC LIMIT 1`,
[account.id]
[accountResult.id]
);
if (lastOtpResult.rows.length > 0) {
@@ -508,7 +508,7 @@ export const requestPasswordReset = async (email) => {
await client.query(`
INSERT INTO auth_otps (account_id, otp_code, type, expires_at)
VALUES ($1, $2m 'password_reset' NOW() + INTERVAL '15 minutes')`,
VALUES ($1, $2, 'password_reset', NOW() + INTERVAL '15 minutes')`,
[account.id, resetCode]
);
@@ -550,7 +550,7 @@ export const resetPassword = async (email, otpCode, newPassword) => {
await client.query('BEGIN');
const accountResult = await client.query(
'SELECT id FROM lobby_accounts WHERE email = $1'
'SELECT id FROM lobby_accounts WHERE email = $1',
[lowerCaseEmail]
);
@@ -564,8 +564,8 @@ export const resetPassword = async (email, otpCode, newPassword) => {
const otpResult = await client.query(`
SELECT id, expires_at FROM auth_otps
WHERE account_id = $1, otp_code = $2, AND type = 'password_reset'`,
[account.id, otpCo0de]
WHERE account_id = $1 AND otp_code = $2 AND type = 'password_reset'`,
[account.id, otpCode]
);
if (otpResult.rows.length === 0) {