fix: Login 500, DB schema sync, Dashboard missing data, Major Refactoring
This commit is contained in:
@@ -2,16 +2,16 @@ const { getDb } = require('../dbPool');
|
||||
|
||||
// 사용자 조회
|
||||
const findByUsername = async (username) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
const [rows] = await db.query(
|
||||
'SELECT user_id, username, password, name, email, role, access_level, worker_id, is_active, last_login_at, password_changed_at, failed_login_attempts, locked_until, created_at, updated_at FROM users WHERE username = ?', [username]
|
||||
);
|
||||
return rows[0];
|
||||
} catch (err) {
|
||||
console.error('DB 오류 - 사용자 조회 실패:', err);
|
||||
throw err;
|
||||
}
|
||||
try {
|
||||
const db = await getDb();
|
||||
const [rows] = await db.query(
|
||||
'SELECT user_id, username, password, name, email, role, access_level, worker_id, is_active, last_login_at, password_changed_at, failed_login_attempts, locked_until, created_at, updated_at FROM users WHERE username = ?', [username]
|
||||
);
|
||||
return rows[0];
|
||||
} catch (err) {
|
||||
console.error('DB 오류 - 사용자 조회 실패:', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -21,7 +21,7 @@ const findByUsername = async (username) => {
|
||||
const incrementFailedLoginAttempts = async (userId) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.execute(
|
||||
await db.query(
|
||||
'UPDATE users SET failed_login_attempts = failed_login_attempts + 1 WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
@@ -38,7 +38,7 @@ const incrementFailedLoginAttempts = async (userId) => {
|
||||
const lockUserAccount = async (userId) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.execute(
|
||||
await db.query(
|
||||
'UPDATE users SET locked_until = DATE_ADD(NOW(), INTERVAL 15 MINUTE) WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
@@ -55,7 +55,7 @@ const lockUserAccount = async (userId) => {
|
||||
const resetLoginAttempts = async (userId) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.execute(
|
||||
await db.query(
|
||||
'UPDATE users SET last_login_at = NOW(), failed_login_attempts = 0, locked_until = NULL WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
@@ -68,8 +68,8 @@ const resetLoginAttempts = async (userId) => {
|
||||
|
||||
// 명확한 내보내기
|
||||
module.exports = {
|
||||
findByUsername,
|
||||
incrementFailedLoginAttempts,
|
||||
lockUserAccount,
|
||||
resetLoginAttempts
|
||||
findByUsername,
|
||||
incrementFailedLoginAttempts,
|
||||
lockUserAccount,
|
||||
resetLoginAttempts
|
||||
};
|
||||
Reference in New Issue
Block a user