feat: 다수 기능 개선 - 순찰, 출근, 작업분석, 모바일 UI 등
- 순찰/점검 기능 개선 (zone-detail 페이지 추가) - 출근/근태 시스템 개선 (연차 조회, 근무현황) - 작업분석 대분류 그룹화 및 마이그레이션 스크립트 - 모바일 네비게이션 UI 추가 - NAS 배포 도구 및 문서 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
82
deploy/tkfb-package/api.hyungi.net/models/userModel.js
Normal file
82
deploy/tkfb-package/api.hyungi.net/models/userModel.js
Normal file
@@ -0,0 +1,82 @@
|
||||
const { getDb } = require('../dbPool');
|
||||
|
||||
// 사용자 조회
|
||||
const findByUsername = async (username) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
const [rows] = await db.query(
|
||||
`SELECT u.user_id, u.username, u.password, u.name, u.email,
|
||||
u.role_id, r.name as role_name,
|
||||
u._access_level_old as access_level, u.worker_id, u.is_active,
|
||||
u.last_login_at, u.password_changed_at, u.failed_login_attempts,
|
||||
u.locked_until, u.created_at, u.updated_at
|
||||
FROM users u
|
||||
LEFT JOIN roles r ON u.role_id = r.id
|
||||
WHERE u.username = ?`, [username]
|
||||
);
|
||||
return rows[0];
|
||||
} catch (err) {
|
||||
console.error('DB 오류 - 사용자 조회 실패:', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 로그인 실패 횟수를 1 증가시킵니다.
|
||||
* @param {number} userId - 사용자 ID
|
||||
*/
|
||||
const incrementFailedLoginAttempts = async (userId) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.query(
|
||||
'UPDATE users SET failed_login_attempts = failed_login_attempts + 1 WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('DB 오류 - 로그인 실패 횟수 증가 실패:', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 특정 사용자의 계정을 잠급니다.
|
||||
* @param {number} userId - 사용자 ID
|
||||
*/
|
||||
const lockUserAccount = async (userId) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.query(
|
||||
'UPDATE users SET locked_until = DATE_ADD(NOW(), INTERVAL 15 MINUTE) WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('DB 오류 - 계정 잠금 실패:', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 로그인 성공 시, 마지막 로그인 시간을 업데이트하고 실패 횟수와 잠금 상태를 초기화합니다.
|
||||
* @param {number} userId - 사용자 ID
|
||||
*/
|
||||
const resetLoginAttempts = async (userId) => {
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.query(
|
||||
'UPDATE users SET last_login_at = NOW(), failed_login_attempts = 0, locked_until = NULL WHERE user_id = ?',
|
||||
[userId]
|
||||
);
|
||||
} catch (err) {
|
||||
console.error('DB 오류 - 로그인 상태 초기화 실패:', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 명확한 내보내기
|
||||
module.exports = {
|
||||
findByUsername,
|
||||
incrementFailedLoginAttempts,
|
||||
lockUserAccount,
|
||||
resetLoginAttempts
|
||||
};
|
||||
Reference in New Issue
Block a user