Admin freischaltung

This commit is contained in:
Klaas 2024-05-29 20:04:50 +02:00
parent 5b0a65daaa
commit 90c6f77b12
1 changed files with 2 additions and 2 deletions

4
app.js
View File

@ -224,7 +224,7 @@ app.post('/register', async (req, res) => {
app.post('/login', async (req, res) => { app.post('/login', async (req, res) => {
const { username, password } = req.body; const { username, password } = req.body;
try { try {
const userResult = await pool.query("SELECT *, CASE WHEN admin_temp IS NOT NULL AND (now() - admin_temp) > interval '24 hours' THEN 'expired' ELSE 'valid' END AS admin_status FROM users WHERE username = $1", [ username]); const userResult = await pool.query("SELECT *, CASE WHEN admin_temp IS NOT NULL AND (now() - admin_temp) > interval '22 hours' THEN 'expired' ELSE 'valid' END AS admin_status FROM users WHERE username = $1", [ username]);
console.log(userResult.rows[0]); console.log(userResult.rows[0]);
if (userResult.rows.length > 0) { if (userResult.rows.length > 0) {
const user = userResult.rows[0]; const user = userResult.rows[0];
@ -233,7 +233,7 @@ app.post('/login', async (req, res) => {
if (user.is_active) { if (user.is_active) {
req.session.userId = user.id; req.session.userId = user.id;
if (user.admin_status === 'expired') { if (user.admin_status === 'expired') {
await pool.query('UPDATE users SET role = $1, admin_temp = $2 WHERE id = $3', ['user', NULL , userId]); await pool.query('UPDATE users SET role = $1, admin_temp = NULL WHERE id = $2', ['user', user.id]);
req.session.role='user'; req.session.role='user';
} else { } else {
req.session.role=user.role; req.session.role=user.role;