const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const userAuthentication = require('../middlewares/userAuthentication');
const { signup } = require('../controller/signup');
const { login } = require('../controller/login');
const PORT = 4000;
const app = express();

app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', (req, res) => {
    res.sendFile(path.join(__dirname, '..', 'public', 'index.html'));
});

app.post('/login', login);

app.get('/dashboard', userAuthentication, (req, res) => {
    res.send('<h1>Welcome to the dashboard</h1> <a href="/logout">Logout</a>');
});

app.get('/logout', (req, res) => {
    res.redirect('/login')
});

app.post('/signup', signup);

app.listen(PORT, () => {
    console.log(`Server is running on ${PORT}`);
})

