Compare commits
10 Commits
6af45b3ee2
...
b7552e3d13
| Author | SHA1 | Date | |
|---|---|---|---|
| b7552e3d13 | |||
|
|
912b12c627 | ||
|
|
c9fb03b499 | ||
|
|
464ff4d8b4 | ||
| 5275c61483 | |||
| 4a68b5a724 | |||
| 5b0d68d66f | |||
| 756f928ced | |||
| 48aa16962c | |||
| bdab795506 |
3
.env
3
.env
@@ -3,3 +3,6 @@ DATABASE_HOST = db.thecoredev.fr
|
||||
DATABASE_PORT = 3306
|
||||
DATABASE_USER = mia
|
||||
DATABASE_PASSWORD = CalomOk0t-ISvpw-
|
||||
|
||||
MASTER_URL = 'https://slave.thecoredev.fr'
|
||||
SLAVE_URL = 'https://slave.thecoredev.fr'
|
||||
@@ -3,3 +3,6 @@ DATABASE_HOST = db.thecoredev.fr
|
||||
DATABASE_PORT = 3306
|
||||
DATABASE_USER = mia
|
||||
DATABASE_PASSWORD = CalomOk0t-ISvpw-
|
||||
|
||||
MASTER_URL = 'https://slave.thecoredev.fr'
|
||||
SLAVE_URL = 'https://slave.thecoredev.fr'
|
||||
52
app.js
52
app.js
@@ -1,5 +1,5 @@
|
||||
const express = require('express')
|
||||
const mysql = require("mysql")
|
||||
const mysql = require("mysql2")
|
||||
const dotenv = require('dotenv')
|
||||
const app = express()
|
||||
const path = require("path")
|
||||
@@ -30,19 +30,10 @@ db.connect((error) => {
|
||||
app.set('view engine', 'hbs');
|
||||
app.use(express.static(publicDir));
|
||||
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
|
||||
app.use('/css', express.static(__dirname + '/node_modules/@eonasdan/tempus-dominus/dist/css'));
|
||||
app.use('/js', express.static(__dirname + '/node_modules/@eonasdan/tempus-dominus/dist/js'));
|
||||
app.use(bodyParser.urlencoded({extended: false}));
|
||||
app.use(express.json())
|
||||
|
||||
|
||||
async function recupListeSessions() {
|
||||
let today = functions.getNowDate("yyyymmdd");
|
||||
|
||||
// On récupère la liste des sessions actives et pour lesquelles il reste de la place
|
||||
db.query('SELECT ID, topic, DATE_FORMAT(scheduled_on, "%d/%m/%Y") as "date", DATE_FORMAT(scheduled_on, "%Hh%i") as "heure", IF(nb_of_attended-nb_of_participants=0, true, false) as "maxAtteint" FROM session WHERE DATE_FORMAT(scheduled_on, "%Y%m%d") >= ?', [today], async (error, result) => {
|
||||
if(error){ console.log(error); }
|
||||
return result;
|
||||
});
|
||||
}
|
||||
app.use(bodyParser.json());
|
||||
|
||||
|
||||
// ******************************************* Arrivée sur la page d'accueil *******************************************
|
||||
@@ -63,9 +54,7 @@ app.get("/", (req, res) => {
|
||||
|
||||
app.get("/index", (req, res) => { res.render("index") });
|
||||
app.get("/login", (req, res) => { res.render("login") });
|
||||
app.get("/register", (req, res) => {
|
||||
res.render("register", { session: req.query.s, role: req.query.r})
|
||||
});
|
||||
app.get("/register", (req, res) => { res.render("register", { session: req.query.s, role: req.query.r}) });
|
||||
app.get("/create-session", (req, res) => { res.render("create-session") });
|
||||
|
||||
|
||||
@@ -164,12 +153,8 @@ app.post("/auth/check-login-no-security", (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
if (role == 'A') {
|
||||
res.redirect('https://slave.thecoredev.fr');
|
||||
}
|
||||
else {
|
||||
res.redirect('https://slave.thecoredev.fr');
|
||||
}
|
||||
if (role == 'A') { res.redirect(process.env.MASTER_URL); }
|
||||
else { res.redirect(process.env.SLAVE_URL); }
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -210,13 +195,10 @@ app.post("/auth/check-login", (req, res) => {
|
||||
}
|
||||
|
||||
userId = result[0].ID;
|
||||
if (functions.comparePassword(password, result[0].password)) {
|
||||
// Le user est connecté avec succès : on vérifie qu'il n'est pas déjà inscrit à la session et si pas le cas, on l'inscrit et on incrémente le compteur des participants
|
||||
db.query('SELECT * FROM participation WHERE user = ?', [userId], async (error, result) => {
|
||||
if(error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
bcrypt.compare(password, result[0].password)
|
||||
.then(result => {
|
||||
if (result) {
|
||||
if (result.length == 0) {
|
||||
db.query('INSERT INTO participation (user, session, role_during_session) VALUES (?,?,?)', [userId, session[0], role[0]], function (err, result) {
|
||||
if (err) throw err;
|
||||
@@ -228,23 +210,19 @@ app.post("/auth/check-login", (req, res) => {
|
||||
console.log("1 record updated");
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
if (role == 'A') {
|
||||
res.redirect('https://slave.thecoredev.fr');
|
||||
}
|
||||
else {
|
||||
res.redirect('https://slave.thecoredev.fr');
|
||||
}
|
||||
if (role == 'A') { res.redirect('https://slave.thecoredev.fr'); }
|
||||
else { res.redirect('https://slave.thecoredev.fr'); }
|
||||
}
|
||||
else {
|
||||
return res.render('login', {
|
||||
error: 'Mot de passe incorrect : corriger votre saisie',
|
||||
"session": session,
|
||||
"role": role
|
||||
session: session,
|
||||
role: role
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"main": "app.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "nodemon --inspect app.js"
|
||||
"start": "nodemon app.js"
|
||||
},
|
||||
"author": "Laurent LE CORRE",
|
||||
"license": "ISC",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
// DatePicker sur l'écran de création d'une session
|
||||
window.datetimepicker1 = $('#datetimepicker1');
|
||||
|
||||
datetimepicker1.tempusDominus({
|
||||
//put your config here
|
||||
allowInputToggle: true,
|
||||
stepping: 15,
|
||||
localization: {
|
||||
@@ -13,7 +13,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.10/dist/js/tempus-dominus.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.10/dist/js/jQuery-provider.js"></script>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@eonasdan/tempus-dominus@6.7.10/dist/css/tempus-dominus.css" />
|
||||
<script type="module" src="/scripts-session.js"></script>
|
||||
<script type="module" src="/session.js"></script>
|
||||
</head>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user