Files
hDiyanetProxy/backend/src/models/User.js
hOLOlu a798066049 İlk sürüm: hDiyanetProxy v1.0.0
- Backend: Node.js + Express + MySQL + JWT auth
- 8 MySQL tablosu (users, countries, states, cities, prayer_times, ramadan_times, eid_times, fetch_logs)
- Diyanet API entegrasyonu (auth + token yönetimi)
- Tüm API endpointleri (places, prayer-times, ramadan, eid, admin)
- Rate limiting, CORS, input validation
- Cron job (gece 02:00 otomatik veri çekme)
- Frontend: Login, Dashboard, Fetch Panel, Namaz Vakitleri, Ramazan, Admin, Profil
- Admin kullanıcı: admin/admin123
2026-02-27 07:53:41 +03:00

57 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// hDiyanetProxy - Kullanıcı Modeli
const pool = require('../utils/db');
const bcrypt = require('bcrypt');
const UserModel = {
// Kullanıcı adına göre bul
async findByUsername(username) {
const [rows] = await pool.execute('SELECT * FROM users WHERE username = ?', [username]);
return rows[0] || null;
},
// ID'ye göre bul
async findById(id) {
const [rows] = await pool.execute('SELECT id, username, role, is_active, created_at FROM users WHERE id = ?', [id]);
return rows[0] || null;
},
// Yeni kullanıcı oluştur
async create(username, password, role = 'user') {
const hashedPassword = await bcrypt.hash(password, 10);
const [result] = await pool.execute(
'INSERT INTO users (username, password, role) VALUES (?, ?, ?)',
[username, hashedPassword, role]
);
return { id: result.insertId, username, role };
},
// Şifre doğrula
async verifyPassword(plainPassword, hashedPassword) {
return bcrypt.compare(plainPassword, hashedPassword);
},
// Tüm kullanıcıları listele
async findAll() {
const [rows] = await pool.execute('SELECT id, username, role, is_active, created_at, updated_at FROM users ORDER BY id');
return rows;
},
// Kullanıcıyı aktif/pasif yap
async toggleActive(id, isActive) {
await pool.execute('UPDATE users SET is_active = ? WHERE id = ?', [isActive ? 1 : 0, id]);
},
// Kullanıcı sil
async delete(id) {
await pool.execute('DELETE FROM users WHERE id = ?', [id]);
},
// Şifre güncelle
async updatePassword(id, newPassword) {
const hashedPassword = await bcrypt.hash(newPassword, 10);
await pool.execute('UPDATE users SET password = ? WHERE id = ?', [hashedPassword, id]);
}
};
module.exports = UserModel;