fix: Login 500, DB schema sync, Dashboard missing data, Major Refactoring
This commit is contained in:
@@ -7,7 +7,7 @@ const { getDb } = require('../dbPool');
|
||||
const recordLoginHistory = async (userId, success, ipAddress, userAgent, failureReason = null) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.execute(
|
||||
await db.query(
|
||||
`INSERT INTO login_logs (user_id, login_time, ip_address, user_agent, login_status, failure_reason)
|
||||
VALUES (?, NOW(), ?, ?, ?, ?)`,
|
||||
[userId, ipAddress || 'unknown', userAgent || 'unknown', success ? 'success' : 'failed', failureReason]
|
||||
@@ -40,14 +40,14 @@ const loginService = async (username, password, ipAddress, userAgent) => {
|
||||
const isValid = await bcrypt.compare(password, user.password);
|
||||
if (!isValid) {
|
||||
console.log(`[로그인 실패] 비밀번호 불일치: ${username}`);
|
||||
|
||||
|
||||
// 모델 함수를 사용하여 로그인 실패 처리
|
||||
await userModel.incrementFailedLoginAttempts(user.user_id);
|
||||
|
||||
if (user.failed_login_attempts >= 4) {
|
||||
await userModel.lockUserAccount(user.user_id);
|
||||
}
|
||||
|
||||
|
||||
await recordLoginHistory(user.user_id, false, ipAddress, userAgent, 'invalid_password');
|
||||
return { success: false, status: 401, error: '아이디 또는 비밀번호가 올바르지 않습니다.' };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user