From 0871f82d5cbfbe355c96787735c8ccbc315ff87f Mon Sep 17 00:00:00 2001 From: 65160258 <65160258@go.buu.ac.th> Date: Thu, 20 Mar 2025 18:50:18 +0700 Subject: [PATCH] dbconet --- app.js | 2 +- db.js | 4 ++-- package.json | 4 ++-- routes/auth.js | 8 +++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index b6fb4a0..31b03ff 100644 --- a/app.js +++ b/app.js @@ -32,7 +32,7 @@ app.use(bodyParser.json()); // การตั้งค่า Session app.use(session({ - secret: process.env.SESSION_SECRET, + secret: process.env.SESSION_SECRET || 'beaglelover', resave: false, saveUninitialized: false })); diff --git a/db.js b/db.js index c4cdfab..761aab0 100644 --- a/db.js +++ b/db.js @@ -4,10 +4,10 @@ const mysql = require('mysql2/promise'); // สร้าง connection pool const pool = mysql.createPool({ - host: process.env.DB_HOST || '10.104.20.250', + host: process.env.DB_HOST || 'localhost', port: process.env.DB_PORT || '3306', user: process.env.DB_USER || 'root', - password: process.env.DB_PASS || 'TKAzta61467', + password: process.env.DB_PASS || '', database: process.env.DB_NAME || 'club_db', }); diff --git a/package.json b/package.json index 125ab9a..41be33a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "keywords": [], "author": "", "license": "ISC", - "description": "", "dependencies": { "axios": "^1.8.1", "bcrypt": "^5.1.1", @@ -23,5 +22,6 @@ "mysql2": "^3.14.0", "nodemon": "^3.1.9", "openai": "^4.86.1" - } + }, + "description": "" } diff --git a/routes/auth.js b/routes/auth.js index cbaee2f..a4fd139 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -11,7 +11,8 @@ router.get('/login', (req, res) => { router.post('/login', async (req, res) => { const { username, password } = req.body; try { - const [users] = await db.query('SELECT * FROM user WHERE username = ?', [username]); + // เปลี่ยนจาก `user` เป็น `users` + const [users] = await db.query('SELECT * FROM users WHERE username = ?', [username]); if (users.length === 0) { return res.render('auth/login', { error: 'ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง' }); } @@ -38,8 +39,9 @@ router.post('/register', async (req, res) => { const { username, email, password, phone, f_name, l_name, club_id } = req.body; try { const hashedPassword = await bcrypt.hash(password, 10); + // เปลี่ยนจาก `user` เป็น `users` await db.query( - `INSERT INTO user + `INSERT INTO users (username, email, password, phone, f_name, l_name, club_id, role) VALUES (?, ?, ?, ?, ?, ?, ?, 'member')`, [username, email, hashedPassword, phone, f_name, l_name, club_id || null] @@ -58,4 +60,4 @@ router.get('/logout', (req, res) => { }); }); -module.exports = router; \ No newline at end of file +module.exports = router; -- GitLab