- Added `jose` library for JWT token generation and verification. - Implemented login functionality with token storage using cookies. - Created `HeaderAdmin` component for admin panel with login/logout capabilities. - Developed `LoginForm` component for user authentication. - Added `Table` component to display data with caching from localStorage. - Introduced `SubHeaderAdmin` for additional admin actions. - Enhanced `database.js` with functions for admin login and fetching table data. - Updated `server.js` to handle new routes for login and table data retrieval. - Modified `package.json` and `package-lock.json` to include new dependencies.
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
import mysql from "mysql2";
|
|
import dotenv from "dotenv";
|
|
dotenv.config();
|
|
|
|
// Ein einzelner Pool reicht; der zweite Pool benutzte fälschlich DB_TABLE als Datenbank
|
|
const pool = mysql
|
|
.createPool({
|
|
host: process.env.DB_HOST,
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
})
|
|
.promise();
|
|
|
|
export async function query(params) {
|
|
const [result] = await pool.query(
|
|
"UPDATE lose SET vorname = ?, nachname = ?, adresse = ?, plz = ?, email = ? WHERE losnummer = ? AND vorname IS NULL AND nachname IS NULL AND adresse IS NULL AND plz IS NULL AND email IS NULL",
|
|
[
|
|
params.vorname,
|
|
params.nachname,
|
|
params.adresse,
|
|
params.plz,
|
|
params.email,
|
|
params.losnummer,
|
|
]
|
|
);
|
|
|
|
if (result.affectedRows > 0) {
|
|
console.log("Update successful:", result);
|
|
return { success: true };
|
|
} else {
|
|
return { success: false };
|
|
}
|
|
}
|
|
|
|
export async function loginAdmin(username, password) {
|
|
const [rows] = await pool.query(
|
|
"SELECT * FROM admin_user WHERE username = ? AND password = ?",
|
|
[username, password]
|
|
);
|
|
if (rows.length > 0) return { success: true };
|
|
return { success: false };
|
|
}
|
|
|
|
export async function getTableData() {
|
|
const [result] = await pool.query("SELECT * FROM lose");
|
|
|
|
if (result.length > 0) {
|
|
return { success: true, data: result };
|
|
}
|
|
return { success: false };
|
|
}
|