-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverification.js
114 lines (100 loc) · 3.47 KB
/
verification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/// I N I T I A L I S A T I O N ///
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config() //ajouter le .env pour la protection des comptes
}
//packages dont on a besoin + declarations///
const { Router } = require('express');
const router = Router();
const points = require('./attribuspoints')
const ajouterZero = points.ajouterZero
const bodyParser = require('body-parser');
const urlencodedParser = bodyParser.urlencoded({ extended: false });
const fs = require('fs');
const sauve = require('./sauve')
const personne = require('./personne')
/// les variables ///
var objectEtat = {};
var objet = {};
var valider = false;
var dossierComplet = false;
router.get('/complet', checkAuthenticated, auth, (req, res) => {
res.render('dossier_complet.ejs', { name: req.user.nom, firstname: req.user.prenom })
});
/// Fonction qui relie le browzer avec la page HTML ///
router.get('/incomplet', checkAuthenticated, auth, (req, res) => {
res.render('dossier_incomplet.ejs', { name: req.user.nom, firstname: req.user.prenom })
});
router.get('/archiver', checkAuthenticated, auth, (req, res) => {
res.render('archiver.ejs', { name: req.user.nom, firstname: req.user.prenom })
});
router.get('/verifier', checkAuthenticated, auth, (req, res) => {
res.render('Verification.ejs', { name: req.user.nom, firstname: req.user.prenom })
});
router.post('/verifier', urlencodedParser, checkAuthenticated, async function(req, res) {
let nom = req.body.Nom;
let annee = "";
let mois = "";
let jour = "";
let numero = 0;
let num = 0;
let preson = req.body.Prenom;
let date = req.body.Date_de_reception;
let heure = req.body.Heure_de_depot;
var persons = JSON.parse(fs.readFileSync('demandeurs.json', 'utf8'));
objectEtat.nom = req.body.Nom;
objectEtat.prenom = req.body.Prenom;
objectEtat.dateReception = req.body.Date_de_reception;
objectEtat.heureReception = req.body.Heure_de_depot;
numero = persons.length + 1;
for (var i = 0; i < 4; i++) {
annee = annee + req.body.Date_de_reception[i]
}
for (var i = 5; i < 7; i++) {
mois = mois + req.body.Date_de_reception[i]
}
for (var i = 8; i < 10; i++) {
jour = jour + req.body.Date_de_reception[i]
}
num = ajouterZero(numero);
objectEtat.Numerodossier = num + annee;
objectEtat.matricule = annee + mois + jour;
objet.Etat_Civil = objectEtat;
fs.writeFile('./personne.json', JSON.stringify(objet, null, 2), err => {
if (err) {
console.log(err);
} else {
console.log(' file sucessfully written ! ');
}
})
if (req.body.check.length == 11) {
sauve('./demandeurs.json', objet);
res.redirect('/complet');
} else {
res.redirect('/incomplet');
}
})
router.post('/archiver', checkAuthenticated, urlencodedParser, async function(req, res) {
personne.Valider = valider;
personne.Dossier_Complet = dossierComplet;
sauve('./demandeurs.json', personne);
res.render('archiver.ejs')
})
router.delete('/logout', (req, res) => {
req.logOut();
res.clearCookie('mlcl');
req.session.destroy()
res.redirect('/connecter');
})
function checkAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
return next()
}
res.redirect('/connecter')
}
function auth(req, res, next) {
if (req.user.profil === 'Editeur' || req.user.profil === 'Admin') {
return next()
}
res.redirect('/profil')
}
module.exports = router