UI Admin aproape finalizat

This commit is contained in:
andrei-mihnea-cerbu
2024-04-03 02:09:12 +03:00
parent fb957a6f97
commit af8c295d75
134 changed files with 5014 additions and 1045 deletions
+40
View File
@@ -0,0 +1,40 @@
const express = require('express');
const path = require('path');
const schemas = require('../models/schemas');
const statusCodes = require('../helpers/status_codes');
const config = require('../config/credentials.json');
const router = express.Router();
router.get('/', (req, res) => {
res.sendFile('login.html', {root: path.join(__dirname, '..', 'public', 'html')});
});
function validateLogin(req, res, next) {
const {error, value} = schemas.loginModelSchema.validate(req.body);
if (error) {
res.status(statusCodes.BAD_REQUEST).json({success: false, error: error.details});
} else {
next();
}
}
router.post('/', validateLogin, (req, res) => {
const { email, password } = req.body;
if (email === config.email && password === config.password) {
res.status(statusCodes.OK).json({
success: true,
message: 'Login successful',
user: {
name: config.name,
email: config.email
}
});
} else {
res.status(statusCodes.UNAUTHORIZED).json({ success: false, message: 'Invalid email or password' });
}
});
module.exports = router;