Commit 2f59332876229ab38d7930f8004116eb09853c33
1 parent
2201e360
Linting
Showing
23 changed files
with
382 additions
and
376 deletions
Show diff stats
.bowerrc
app/controllers/decrypt.js
@@ -6,31 +6,31 @@ var decrypt = {}; | @@ -6,31 +6,31 @@ var decrypt = {}; | ||
6 | decrypt.decrypter = false; | 6 | decrypt.decrypter = false; |
7 | 7 | ||
8 | decrypt.whenOk = function (cb) { | 8 | decrypt.whenOk = function (cb) { |
9 | - if (this.encrypter) { | ||
10 | - cb(); | ||
11 | - } else { | ||
12 | - this.prepare(cb); | ||
13 | - } | 9 | + if (this.encrypter) { |
10 | + cb(); | ||
11 | + } else { | ||
12 | + this.prepare(cb); | ||
13 | + } | ||
14 | }; | 14 | }; |
15 | 15 | ||
16 | decrypt.prepare = function (cb) { | 16 | decrypt.prepare = function (cb) { |
17 | - fs.readFile('config/ci_com.pem', function(err, data) { | ||
18 | - if (err) { | ||
19 | - throw err; | ||
20 | - } | ||
21 | - this.decrypter = ursa.createPrivateKey(data); | ||
22 | - cb(); | ||
23 | - }); | 17 | + fs.readFile('config/ci_com.pem', function (err, data) { |
18 | + if (err) { | ||
19 | + throw err; | ||
20 | + } | ||
21 | + this.decrypter = ursa.createPrivateKey(data); | ||
22 | + cb(); | ||
23 | + }); | ||
24 | }; | 24 | }; |
25 | 25 | ||
26 | -decrypt.preload = function(cb) { | ||
27 | - this.whenOk(cb); | 26 | +decrypt.preload = function (cb) { |
27 | + this.whenOk(cb); | ||
28 | }; | 28 | }; |
29 | 29 | ||
30 | decrypt.decrypt = function (string, cb) { | 30 | decrypt.decrypt = function (string, cb) { |
31 | - this.whenOk(function() { | ||
32 | - cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING)); | ||
33 | - }); | 31 | + this.whenOk(function () { |
32 | + cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING)); | ||
33 | + }); | ||
34 | }; | 34 | }; |
35 | 35 | ||
36 | module.exports = decrypt; | 36 | module.exports = decrypt; |
app/controllers/membres.js
1 | var Membre = require('../models/membre'); | 1 | var Membre = require('../models/membre'); |
2 | var noms = require('../controllers/noms'); | 2 | var noms = require('../controllers/noms'); |
3 | -var async = require('async') | 3 | +var async = require('async'); |
4 | 4 | ||
5 | -var membres = {} | 5 | +var membres = {}; |
6 | 6 | ||
7 | membres.list = function (cb) { | 7 | membres.list = function (cb) { |
8 | Membre.find({}).lean().exec(function (err, membres) { | 8 | Membre.find({}).lean().exec(function (err, membres) { |
9 | addNom = function (membre, cb) { | 9 | addNom = function (membre, cb) { |
10 | noms.get(membre.login, function (nom) { | 10 | noms.get(membre.login, function (nom) { |
11 | if (nom) { | 11 | if (nom) { |
12 | - membre.nom = nom | 12 | + membre.nom = nom; |
13 | } else { | 13 | } else { |
14 | - membre.nom = membre.login | 14 | + membre.nom = membre.login; |
15 | } | 15 | } |
16 | - cb(null, membre) | ||
17 | - }) | ||
18 | - } | 16 | + cb(null, membre); |
17 | + }); | ||
18 | + }; | ||
19 | async.mapSeries(membres, addNom, function (err, results) { | 19 | async.mapSeries(membres, addNom, function (err, results) { |
20 | - cb(results) | ||
21 | - }) | 20 | + cb(results); |
21 | + }); | ||
22 | }); | 22 | }); |
23 | -} | 23 | +}; |
24 | 24 | ||
25 | membres.add = function (data, cb) { | 25 | membres.add = function (data, cb) { |
26 | Membre.create({ | 26 | Membre.create({ |
@@ -28,12 +28,12 @@ membres.add = function (data, cb) { | @@ -28,12 +28,12 @@ membres.add = function (data, cb) { | ||
28 | role: data.role, | 28 | role: data.role, |
29 | section: data.section, | 29 | section: data.section, |
30 | }, cb); | 30 | }, cb); |
31 | -} | 31 | +}; |
32 | 32 | ||
33 | membres.remove = function (id, cb) { | 33 | membres.remove = function (id, cb) { |
34 | Membre.remove({ | 34 | Membre.remove({ |
35 | _id: id | 35 | _id: id |
36 | }, cb); | 36 | }, cb); |
37 | -} | 37 | +}; |
38 | 38 | ||
39 | -module.exports = membres; | ||
40 | \ No newline at end of file | 39 | \ No newline at end of file |
40 | +module.exports = membres; |
app/controllers/noms.js
1 | var Noms = require('../models/noms'); | 1 | var Noms = require('../models/noms'); |
2 | var LineTransform = require('node-line-reader').LineTransform; | 2 | var LineTransform = require('node-line-reader').LineTransform; |
3 | -var fs = require('fs') | 3 | +var fs = require('fs'); |
4 | 4 | ||
5 | -var noms = {} | 5 | +var noms = {}; |
6 | 6 | ||
7 | noms.get = function (login, cb) { | 7 | noms.get = function (login, cb) { |
8 | Noms.findOne({ | 8 | Noms.findOne({ |
9 | login: login | 9 | login: login |
10 | }, function (err, nom) { | 10 | }, function (err, nom) { |
11 | if (err) { | 11 | if (err) { |
12 | - console.error(err) | ||
13 | - cb(false) | 12 | + console.error(err); |
13 | + cb(false); | ||
14 | } else { | 14 | } else { |
15 | if (nom) { | 15 | if (nom) { |
16 | - cb(nom.nom) | 16 | + cb(nom.nom); |
17 | } else { | 17 | } else { |
18 | - passwdF = 'config/passwd' | 18 | + passwdF = 'config/passwd'; |
19 | fs.exists(passwdF, function (exists) { | 19 | fs.exists(passwdF, function (exists) { |
20 | - found = false | 20 | + found = false; |
21 | if (exists) { | 21 | if (exists) { |
22 | - stream = fs.createReadStream(passwdF) | ||
23 | - transform = new LineTransform() | ||
24 | - stream.pipe(transform) | 22 | + stream = fs.createReadStream(passwdF); |
23 | + transform = new LineTransform(); | ||
24 | + stream.pipe(transform); | ||
25 | transform.on('data', function (line) { | 25 | transform.on('data', function (line) { |
26 | - ex = line.split(':') | 26 | + ex = line.split(':'); |
27 | if (ex[0] == login) { // Si trouvé | 27 | if (ex[0] == login) { // Si trouvé |
28 | - stream.close() | ||
29 | - cb(ex[4]) | ||
30 | - found = true | 28 | + stream.close(); |
29 | + cb(ex[4]); | ||
30 | + found = true; | ||
31 | Noms.create({ | 31 | Noms.create({ |
32 | login: login, | 32 | login: login, |
33 | nom: ex[4] | 33 | nom: ex[4] |
34 | - }) | 34 | + }); |
35 | } | 35 | } |
36 | - }) | 36 | + }); |
37 | transform.on('end', function () { | 37 | transform.on('end', function () { |
38 | if (!found) { | 38 | if (!found) { |
39 | - cb(false) | 39 | + cb(false); |
40 | } | 40 | } |
41 | - }) | 41 | + }); |
42 | } else { | 42 | } else { |
43 | - console.error("Impossible de trouver le fichier passwd") | ||
44 | - cb(login.toUpperCase()) | 43 | + console.error("Impossible de trouver le fichier passwd"); |
44 | + cb(login.toUpperCase()); | ||
45 | } | 45 | } |
46 | - }) | 46 | + }); |
47 | } | 47 | } |
48 | } | 48 | } |
49 | - }) | ||
50 | -} | 49 | + }); |
50 | +}; | ||
51 | 51 | ||
52 | -module.exports = noms; | ||
53 | \ No newline at end of file | 52 | \ No newline at end of file |
53 | +module.exports = noms; |
app/controllers/sessions.js
1 | var Session = require('../models/session'); | 1 | var Session = require('../models/session'); |
2 | var noms = require('../controllers/noms'); | 2 | var noms = require('../controllers/noms'); |
3 | 3 | ||
4 | -var sessions = {} | 4 | +var sessions = {}; |
5 | 5 | ||
6 | -sessions.cur = false | 6 | +sessions.cur = false; |
7 | 7 | ||
8 | sessions.addData = function (session, cb) { | 8 | sessions.addData = function (session, cb) { |
9 | noms.get(session.login, function (nom) { | 9 | noms.get(session.login, function (nom) { |
10 | if (typeof nom == 'string') { | 10 | if (typeof nom == 'string') { |
11 | - session.nom = nom | 11 | + session.nom = nom; |
12 | } else { | 12 | } else { |
13 | - session.nom = 'Inconnu' | 13 | + session.nom = 'Inconnu'; |
14 | } | 14 | } |
15 | - session.canAddMembre = session.login == 'gbontoux' | ||
16 | - session.canDelMembre = session.login == 'gbontoux' | ||
17 | - cb(session) | ||
18 | - }) | ||
19 | -} | 15 | + session.canAddMembre = session.login == 'gbontoux'; |
16 | + session.canDelMembre = session.login == 'gbontoux'; | ||
17 | + cb(session); | ||
18 | + }); | ||
19 | +}; | ||
20 | 20 | ||
21 | sessions.find = function (id, cb) { | 21 | sessions.find = function (id, cb) { |
22 | - _this = this | 22 | + _this = this; |
23 | Session.findById(id).lean().exec(function (err, session) { | 23 | Session.findById(id).lean().exec(function (err, session) { |
24 | if (typeof session == 'object') { | 24 | if (typeof session == 'object') { |
25 | _this.addData(session, function (session) { | 25 | _this.addData(session, function (session) { |
26 | - cb(err, session) | ||
27 | - }) | 26 | + cb(err, session); |
27 | + }); | ||
28 | } else { | 28 | } else { |
29 | - cb(err, null) | 29 | + cb(err, null); |
30 | } | 30 | } |
31 | - }) | ||
32 | -} | 31 | + }); |
32 | +}; | ||
33 | 33 | ||
34 | sessions.valid = function (session) { | 34 | sessions.valid = function (session) { |
35 | - return session.started.setSeconds(session.started.getSeconds() + 3600) > new Date() | ||
36 | -} | 35 | + return session.started.setSeconds(session.started.getSeconds() + 3600) > new Date(); |
36 | +}; | ||
37 | 37 | ||
38 | sessions.delete = function (id, cb) { | 38 | sessions.delete = function (id, cb) { |
39 | Session.remove({ | 39 | Session.remove({ |
40 | _id: id | 40 | _id: id |
41 | }, cb); | 41 | }, cb); |
42 | -} | 42 | +}; |
43 | 43 | ||
44 | sessions.verify = function (id, cb) { | 44 | sessions.verify = function (id, cb) { |
45 | - _this = this | 45 | + _this = this; |
46 | _this.find(id, function (err, session) { | 46 | _this.find(id, function (err, session) { |
47 | if (err) { | 47 | if (err) { |
48 | cb('error'); | 48 | cb('error'); |
@@ -52,67 +52,67 @@ sessions.verify = function (id, cb) { | @@ -52,67 +52,67 @@ sessions.verify = function (id, cb) { | ||
52 | cb(null, session); | 52 | cb(null, session); |
53 | } else { | 53 | } else { |
54 | cb('expired'); | 54 | cb('expired'); |
55 | - _this.delete(id) | 55 | + _this.delete(id); |
56 | } | 56 | } |
57 | } else { | 57 | } else { |
58 | - cb('unknown') | 58 | + cb('unknown'); |
59 | } | 59 | } |
60 | } | 60 | } |
61 | }); | 61 | }); |
62 | -} | 62 | +}; |
63 | 63 | ||
64 | sessions.use = function (id, cb) { | 64 | sessions.use = function (id, cb) { |
65 | - _this = this | 65 | + _this = this; |
66 | _this.verify(id, function (err, session) { | 66 | _this.verify(id, function (err, session) { |
67 | if (err) { | 67 | if (err) { |
68 | - cb(err) | 68 | + cb(err); |
69 | } else { | 69 | } else { |
70 | - _this.cur = session | ||
71 | - cb(null) | 70 | + _this.cur = session; |
71 | + cb(null); | ||
72 | } | 72 | } |
73 | - }) | ||
74 | -} | 73 | + }); |
74 | +}; | ||
75 | 75 | ||
76 | sessions.create = function (login, cb) { | 76 | sessions.create = function (login, cb) { |
77 | Session.create({ | 77 | Session.create({ |
78 | login: login | 78 | login: login |
79 | }, cb); | 79 | }, cb); |
80 | -} | 80 | +}; |
81 | 81 | ||
82 | sessions.login = function (data, cb) { | 82 | sessions.login = function (data, cb) { |
83 | // DUMMY | 83 | // DUMMY |
84 | noms.get(data.login, function (nom) { | 84 | noms.get(data.login, function (nom) { |
85 | - if (nom == false) { | ||
86 | - cb(null, false) | 85 | + if (nom === false) { |
86 | + cb(null, false); | ||
87 | } else { | 87 | } else { |
88 | if (data.pass == 'cool') { | 88 | if (data.pass == 'cool') { |
89 | - cb(null, true) | 89 | + cb(null, true); |
90 | } else { | 90 | } else { |
91 | - cb(null, false) | 91 | + cb(null, false); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | - }) | ||
95 | -} | 94 | + }); |
95 | +}; | ||
96 | 96 | ||
97 | sessions.open = function (data, cb) { | 97 | sessions.open = function (data, cb) { |
98 | - _this = this | 98 | + _this = this; |
99 | _this.login(data, function (err, res) { | 99 | _this.login(data, function (err, res) { |
100 | if (err) { | 100 | if (err) { |
101 | - cb('error') | 101 | + cb('error'); |
102 | } else { | 102 | } else { |
103 | if (res) { | 103 | if (res) { |
104 | _this.create(data.login, function (err, session) { | 104 | _this.create(data.login, function (err, session) { |
105 | if (err) { | 105 | if (err) { |
106 | cb('error'); | 106 | cb('error'); |
107 | } else { | 107 | } else { |
108 | - _this.use(session._id, cb) | 108 | + _this.use(session._id, cb); |
109 | } | 109 | } |
110 | }); | 110 | }); |
111 | } else { | 111 | } else { |
112 | - cb('invalid') | 112 | + cb('invalid'); |
113 | } | 113 | } |
114 | } | 114 | } |
115 | }); | 115 | }); |
116 | -} | 116 | +}; |
117 | 117 | ||
118 | module.exports = sessions; | 118 | module.exports = sessions; |
app/models/membre.js
@@ -17,4 +17,4 @@ module.exports = mongoose.model('Membre', { | @@ -17,4 +17,4 @@ module.exports = mongoose.model('Membre', { | ||
17 | type: String, | 17 | type: String, |
18 | default: 'Membre' | 18 | default: 'Membre' |
19 | } | 19 | } |
20 | -}); | ||
21 | \ No newline at end of file | 20 | \ No newline at end of file |
21 | +}); |
app/models/noms.js
app/models/session.js
app/routes.js
@@ -2,10 +2,10 @@ var api = require('./routes/api'); | @@ -2,10 +2,10 @@ var api = require('./routes/api'); | ||
2 | 2 | ||
3 | module.exports = function (app) { | 3 | module.exports = function (app) { |
4 | 4 | ||
5 | - app.use('/api/', api) | 5 | + app.use('/api/', api); |
6 | 6 | ||
7 | app.get('*', function (req, res) { | 7 | app.get('*', function (req, res) { |
8 | res.sendfile('./public/views/index.html'); | 8 | res.sendfile('./public/views/index.html'); |
9 | }); | 9 | }); |
10 | 10 | ||
11 | -}; | ||
12 | \ No newline at end of file | 11 | \ No newline at end of file |
12 | +}; |
app/routes/api.js
@@ -7,94 +7,94 @@ var api = express(); | @@ -7,94 +7,94 @@ var api = express(); | ||
7 | 7 | ||
8 | // Sessions | 8 | // Sessions |
9 | api.get('/session', function (req, res) { // Informations sur la session | 9 | api.get('/session', function (req, res) { // Informations sur la session |
10 | - if (req.cookies && req.cookies.session) { | ||
11 | - sessions.use(req.cookies.session, function (err) { | ||
12 | - if (err) { | ||
13 | - res.send(err); | ||
14 | - } else { | ||
15 | - res.send(sessions.cur); | ||
16 | - } | ||
17 | - }); | ||
18 | - // TODO si pas bon : res.clearCookie('session') | ||
19 | - } else { | ||
20 | - res.send('missing'); | ||
21 | - } | 10 | + if (req.cookies && req.cookies.session) { |
11 | + sessions.use(req.cookies.session, function (err) { | ||
12 | + if (err) { | ||
13 | + res.send(err); | ||
14 | + } else { | ||
15 | + res.send(sessions.cur); | ||
16 | + } | ||
17 | + }); | ||
18 | + // TODO si pas bon : res.clearCookie('session') | ||
19 | + } else { | ||
20 | + res.send('missing'); | ||
21 | + } | ||
22 | }); | 22 | }); |
23 | 23 | ||
24 | api.post('/session', function (req, res) { // Se connecter | 24 | api.post('/session', function (req, res) { // Se connecter |
25 | - decrypt.decrypt(req.body[0], function (data) { | ||
26 | - sessions.open(JSON.parse(data), function (err) { | ||
27 | - if (err) { | ||
28 | - res.send(err); | ||
29 | - } else { | ||
30 | - res.cookie('session', sessions.cur._id); | ||
31 | - res.send(sessions.cur); | ||
32 | - } | 25 | + decrypt.decrypt(req.body[0], function (data) { |
26 | + sessions.open(JSON.parse(data), function (err) { | ||
27 | + if (err) { | ||
28 | + res.send(err); | ||
29 | + } else { | ||
30 | + res.cookie('session', sessions.cur._id); | ||
31 | + res.send(sessions.cur); | ||
32 | + } | ||
33 | + }); | ||
33 | }); | 34 | }); |
34 | - }); | ||
35 | }); | 35 | }); |
36 | 36 | ||
37 | api.delete('/session', function (req, res) { // Se déconnecter | 37 | api.delete('/session', function (req, res) { // Se déconnecter |
38 | - if (req.cookies.session) { | ||
39 | - sessions.delete(req.cookies.session, function () { | ||
40 | - res.clearCookie('session'); | ||
41 | - res.end(); | ||
42 | - }); | ||
43 | - } else { | ||
44 | - res.send('missing'); | ||
45 | - } | 38 | + if (req.cookies.session) { |
39 | + sessions.delete(req.cookies.session, function () { | ||
40 | + res.clearCookie('session'); | ||
41 | + res.end(); | ||
42 | + }); | ||
43 | + } else { | ||
44 | + res.send('missing'); | ||
45 | + } | ||
46 | }); | 46 | }); |
47 | 47 | ||
48 | ifPermission = function (req, res, perm, cb) { | 48 | ifPermission = function (req, res, perm, cb) { |
49 | - sessions.use(req.cookies.session, function (err) { | ||
50 | - if (err) { | ||
51 | - res.status(403).end(); | ||
52 | - } else { | ||
53 | - if (sessions.cur[perm]) { | ||
54 | - cb(); | ||
55 | - } else { | ||
56 | - res.status(403).end(); | ||
57 | - } | ||
58 | - } | ||
59 | - }); | 49 | + sessions.use(req.cookies.session, function (err) { |
50 | + if (err) { | ||
51 | + res.status(403).end(); | ||
52 | + } else { | ||
53 | + if (sessions.cur[perm]) { | ||
54 | + cb(); | ||
55 | + } else { | ||
56 | + res.status(403).end(); | ||
57 | + } | ||
58 | + } | ||
59 | + }); | ||
60 | }; | 60 | }; |
61 | 61 | ||
62 | 62 | ||
63 | // Membres | 63 | // Membres |
64 | api.get('/membres', function (req, res) { // Liste des membres | 64 | api.get('/membres', function (req, res) { // Liste des membres |
65 | - membres.list(function (err, membres) { | ||
66 | - if (err) | ||
67 | - res.send(err); | ||
68 | - res.json(membres); | ||
69 | - }); | 65 | + membres.list(function (err, membres) { |
66 | + if (err) | ||
67 | + res.send(err); | ||
68 | + res.json(membres); | ||
69 | + }); | ||
70 | }); | 70 | }); |
71 | 71 | ||
72 | api.post('/membres', function (req, res) { // Ajout d'un membre | 72 | api.post('/membres', function (req, res) { // Ajout d'un membre |
73 | - ifPermission(req, res, 'canAddMembre', function () { | ||
74 | - membres.add(req.body, function (err, membre) { | ||
75 | - if (err) | ||
76 | - res.send(err); | ||
77 | - membres.list(function (err, membres) { | ||
78 | - if (err) | ||
79 | - res.send(err); | ||
80 | - res.json(membres); | ||
81 | - }); | 73 | + ifPermission(req, res, 'canAddMembre', function () { |
74 | + membres.add(req.body, function (err, membre) { | ||
75 | + if (err) | ||
76 | + res.send(err); | ||
77 | + membres.list(function (err, membres) { | ||
78 | + if (err) | ||
79 | + res.send(err); | ||
80 | + res.json(membres); | ||
81 | + }); | ||
82 | + }); | ||
82 | }); | 83 | }); |
83 | - }); | ||
84 | }); | 84 | }); |
85 | 85 | ||
86 | api.delete('/membres/:membre_id', function (req, res) { // Supression d'un membre | 86 | api.delete('/membres/:membre_id', function (req, res) { // Supression d'un membre |
87 | - ifPermission(req, res, 'canDelMembre', function () { | ||
88 | - membres.remove(req.params.membre_id, function (err, membre) { | ||
89 | - if (err) | ||
90 | - res.send(err); | ||
91 | - membres.list(function (err, membres) { | ||
92 | - if (err) | ||
93 | - res.send(err); | ||
94 | - res.json(membres); | ||
95 | - }); | 87 | + ifPermission(req, res, 'canDelMembre', function () { |
88 | + membres.remove(req.params.membre_id, function (err, membre) { | ||
89 | + if (err) | ||
90 | + res.send(err); | ||
91 | + membres.list(function (err, membres) { | ||
92 | + if (err) | ||
93 | + res.send(err); | ||
94 | + res.json(membres); | ||
95 | + }); | ||
96 | + }); | ||
96 | }); | 97 | }); |
97 | - }); | ||
98 | }); | 98 | }); |
99 | 99 | ||
100 | module.exports = api; | 100 | module.exports = api; |
bower.json
1 | { | 1 | { |
2 | - "name": "ci-site", | ||
3 | - "version": "0.0.1", | ||
4 | - "dependencies": { | ||
5 | - "font-awesome": "latest", | ||
6 | - "angular": "latest", | ||
7 | - "angular-route": "latest", | ||
8 | - "bootswatch-dist": "3.3.2-cerulean", | ||
9 | - "jsencrypt": "~2.1.0" | ||
10 | - } | 2 | + "name": "ci-site", |
3 | + "version": "0.0.1", | ||
4 | + "dependencies": { | ||
5 | + "font-awesome": "latest", | ||
6 | + "angular": "latest", | ||
7 | + "angular-route": "latest", | ||
8 | + "bootswatch-dist": "3.3.2-cerulean", | ||
9 | + "jsencrypt": "~2.1.0" | ||
10 | + } | ||
11 | } | 11 | } |
package.json
1 | { | 1 | { |
2 | - "name": "ci-site", | ||
3 | - "main": "server.js", | ||
4 | - "dependencies": { | ||
5 | - "async": "^0.9.0", | ||
6 | - "body-parser": "^1.12.0", | ||
7 | - "cookie-parser": "^1.3.4", | ||
8 | - "express": "^4.12.2", | ||
9 | - "method-override": "^2.3.1", | ||
10 | - "mongoose": "^3.8.25", | ||
11 | - "morgan": "^1.5.1", | ||
12 | - "node-line-reader": "0.0.2", | ||
13 | - "ursa": "^0.8.4" | ||
14 | - } | 2 | + "name": "ci-site", |
3 | + "main": "server.js", | ||
4 | + "dependencies": { | ||
5 | + "async": "^0.9.0", | ||
6 | + "body-parser": "^1.12.0", | ||
7 | + "cookie-parser": "^1.3.4", | ||
8 | + "express": "^4.12.2", | ||
9 | + "method-override": "^2.3.1", | ||
10 | + "mongoose": "^3.8.25", | ||
11 | + "morgan": "^1.5.1", | ||
12 | + "node-line-reader": "0.0.2", | ||
13 | + "ursa": "^0.8.4" | ||
14 | + } | ||
15 | } | 15 | } |
public/css/style.css
public/js/appRoutes.js
@@ -17,4 +17,4 @@ angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', | @@ -17,4 +17,4 @@ angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', | ||
17 | $locationProvider.html5Mode(true); | 17 | $locationProvider.html5Mode(true); |
18 | 18 | ||
19 | } | 19 | } |
20 | -]); | ||
21 | \ No newline at end of file | 20 | \ No newline at end of file |
21 | +]); |
public/js/controllers/ConnectCtrl.js
1 | angular.module('ConnectCtrl', []).controller('ConnectController', ['$scope', 'SessionService', 'EncryptService', | 1 | angular.module('ConnectCtrl', []).controller('ConnectController', ['$scope', 'SessionService', 'EncryptService', |
2 | - function ($scope, SessionService, EncryptService) { | ||
3 | - EncryptService.preload(function () { | ||
4 | - return undefined; | ||
5 | - }); | ||
6 | - $scope.connect = { | ||
7 | - connect: function () { | ||
8 | - SessionService.connect($scope.connect.login, $scope.connect.pass); | ||
9 | - } | ||
10 | - }; | ||
11 | - } | 2 | + function ($scope, SessionService, EncryptService) { |
3 | + EncryptService.preload(function () { | ||
4 | + return undefined; | ||
5 | + }); | ||
6 | + $scope.connect = { | ||
7 | + connect: function () { | ||
8 | + SessionService.connect($scope.connect.login, $scope.connect.pass); | ||
9 | + } | ||
10 | + }; | ||
11 | + } | ||
12 | ]); | 12 | ]); |
public/js/controllers/MembreCtrl.js
@@ -2,10 +2,10 @@ angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$htt | @@ -2,10 +2,10 @@ angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$htt | ||
2 | function ($scope, $http, SessionService) { | 2 | function ($scope, $http, SessionService) { |
3 | $scope.formData = {}; | 3 | $scope.formData = {}; |
4 | 4 | ||
5 | - $scope.session = SessionService.cur | 5 | + $scope.session = SessionService.cur; |
6 | SessionService.onChange(function () { | 6 | SessionService.onChange(function () { |
7 | - $scope.session = SessionService.cur | ||
8 | - }) | 7 | + $scope.session = SessionService.cur; |
8 | + }); | ||
9 | 9 | ||
10 | $http.get('/api/membres') | 10 | $http.get('/api/membres') |
11 | .success(function (data) { | 11 | .success(function (data) { |
@@ -40,4 +40,4 @@ angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$htt | @@ -40,4 +40,4 @@ angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$htt | ||
40 | }; | 40 | }; |
41 | 41 | ||
42 | } | 42 | } |
43 | -]); | ||
44 | \ No newline at end of file | 43 | \ No newline at end of file |
44 | +]); |
public/js/controllers/SessionCtrl.js
1 | angular.module('SessionsCtrl', []).controller('SessionController', ['$scope', 'SessionService', | 1 | angular.module('SessionsCtrl', []).controller('SessionController', ['$scope', 'SessionService', |
2 | function ($scope, SessionService) { | 2 | function ($scope, SessionService) { |
3 | - $scope.session = SessionService.cur | 3 | + $scope.session = SessionService.cur; |
4 | $scope.disconnect = function () { | 4 | $scope.disconnect = function () { |
5 | - SessionService.disconnect() | ||
6 | - } | 5 | + SessionService.disconnect(); |
6 | + }; | ||
7 | SessionService.onChange(function () { | 7 | SessionService.onChange(function () { |
8 | - $scope.session = SessionService.cur | ||
9 | - }) | ||
10 | - // $scope.$on("$destroy", function () { | ||
11 | - // // TODO | ||
12 | - // }) | 8 | + $scope.session = SessionService.cur; |
9 | + }); | ||
10 | + // $scope.$on("$destroy", function () { | ||
11 | + // // TODO | ||
12 | + // }) | ||
13 | } | 13 | } |
14 | -]); | ||
15 | \ No newline at end of file | 14 | \ No newline at end of file |
15 | +]); |
public/js/services/EncryptServ.js
1 | angular.module('EncryptServ', []).service('EncryptService', ['$http', | 1 | angular.module('EncryptServ', []).service('EncryptService', ['$http', |
2 | - function ($http) { | ||
3 | - a = { | ||
4 | - encrypter: false, | ||
5 | - whenOk: function (cb) { | ||
6 | - if (this.encrypter) { | ||
7 | - cb(); | ||
8 | - } else { | ||
9 | - this.prepare(cb); | ||
10 | - } | ||
11 | - }, | ||
12 | - prepare: function (cb) { | ||
13 | - $http.get('/com/ci_com_pub.pem').success(function (key) { | ||
14 | - this.encrypter = new JSEncrypt(); | ||
15 | - this.encrypter.setPublicKey(key); | ||
16 | - cb(); | ||
17 | - }); | ||
18 | - }, | ||
19 | - preload: function(cb) { | ||
20 | - this.whenOk(cb); | ||
21 | - }, | ||
22 | - encrypt: function (string, cb) { | ||
23 | - this.whenOk(function() { | ||
24 | - cb(this.encrypter.encrypt(string)); | ||
25 | - }); | ||
26 | - } | ||
27 | - }; | ||
28 | - return a; | ||
29 | - } | 2 | + function ($http) { |
3 | + a = { | ||
4 | + encrypter: false, | ||
5 | + whenOk: function (cb) { | ||
6 | + if (this.encrypter) { | ||
7 | + cb(); | ||
8 | + } else { | ||
9 | + this.prepare(cb); | ||
10 | + } | ||
11 | + }, | ||
12 | + prepare: function (cb) { | ||
13 | + $http.get('/com/ci_com_pub.pem').success(function (key) { | ||
14 | + this.encrypter = new JSEncrypt(); | ||
15 | + this.encrypter.setPublicKey(key); | ||
16 | + cb(); | ||
17 | + }); | ||
18 | + }, | ||
19 | + preload: function (cb) { | ||
20 | + this.whenOk(cb); | ||
21 | + }, | ||
22 | + encrypt: function (string, cb) { | ||
23 | + this.whenOk(function () { | ||
24 | + cb(this.encrypter.encrypt(string)); | ||
25 | + }); | ||
26 | + } | ||
27 | + }; | ||
28 | + return a; | ||
29 | + } | ||
30 | ]); | 30 | ]); |
public/js/services/SessionServ.js
1 | angular.module('SessionsServ', []).service('SessionService', ['$http', 'EncryptService', | 1 | angular.module('SessionsServ', []).service('SessionService', ['$http', 'EncryptService', |
2 | - function ($http, EncryptService) { | ||
3 | - a = { | ||
4 | - cur: false, | ||
5 | - status: 0, | ||
6 | - changeHandlers: [], | ||
7 | - onChange: function (fun) { | ||
8 | - this.changeHandlers.push(fun); | ||
9 | - }, | ||
10 | - triggerChange: function () { | ||
11 | - for (var fun in this.changeHandlers) { | ||
12 | - this.changeHandlers[fun](); | ||
13 | - } | ||
14 | - }, | ||
15 | - updateSessionInfos: function (data) { | ||
16 | - console.log("Connection:", data); | ||
17 | - if (typeof data === 'object') { | ||
18 | - this.cur = data; | ||
19 | - } else { | ||
20 | - this.cur = false; | ||
21 | - } | ||
22 | - this.triggerChange(); | ||
23 | - }, | ||
24 | - get: function (cb) { // Fetch infos if needed | ||
25 | - if (status === 0) { | ||
26 | - this.status = 1; // Fetching | ||
27 | - _this = this; | ||
28 | - // TODO Verify if cookies to prevent uneeded request | ||
29 | - $http.get('/api/session').success(function (body) { | ||
30 | - _this.updateSessionInfos(body); | ||
31 | - if (cb) { | ||
32 | - if (this.logged) { | ||
33 | - cb(null); | ||
34 | - } else { | ||
35 | - cb(body); | ||
36 | - } | 2 | + function ($http, EncryptService) { |
3 | + a = { | ||
4 | + cur: false, | ||
5 | + status: 0, | ||
6 | + changeHandlers: [], | ||
7 | + onChange: function (fun) { | ||
8 | + this.changeHandlers.push(fun); | ||
9 | + }, | ||
10 | + triggerChange: function () { | ||
11 | + for (var fun in this.changeHandlers) { | ||
12 | + this.changeHandlers[fun](); | ||
13 | + } | ||
14 | + }, | ||
15 | + updateSessionInfos: function (data) { | ||
16 | + console.log("Connection:", data); | ||
17 | + if (typeof data === 'object') { | ||
18 | + this.cur = data; | ||
19 | + } else { | ||
20 | + this.cur = false; | ||
21 | + } | ||
22 | + this.triggerChange(); | ||
23 | + }, | ||
24 | + get: function (cb) { // Fetch infos if needed | ||
25 | + if (status === 0) { | ||
26 | + this.status = 1; // Fetching | ||
27 | + _this = this; | ||
28 | + // TODO Verify if cookies to prevent uneeded request | ||
29 | + $http.get('/api/session').success(function (body) { | ||
30 | + _this.updateSessionInfos(body); | ||
31 | + if (cb) { | ||
32 | + if (this.logged) { | ||
33 | + cb(null); | ||
34 | + } else { | ||
35 | + cb(body); | ||
36 | + } | ||
37 | + } | ||
38 | + }); | ||
39 | + } else { | ||
40 | + console.warn("Unnecessary get() call"); | ||
41 | + } | ||
42 | + }, | ||
43 | + connect: function (login, pass, cb) { | ||
44 | + _this = this; | ||
45 | + data = JSON.stringify({ | ||
46 | + login: login, | ||
47 | + pass: pass | ||
48 | + }); | ||
49 | + EncryptService.encrypt(data, function (dataCrypt) { | ||
50 | + $http.post('/api/session', [dataCrypt]).success(function (body) { | ||
51 | + _this.updateSessionInfos(body); | ||
52 | + if (cb) { | ||
53 | + if (this.logged) { | ||
54 | + cb(null); | ||
55 | + } else { | ||
56 | + cb(body); | ||
57 | + } | ||
58 | + } | ||
59 | + }); | ||
60 | + }); | ||
61 | + }, | ||
62 | + disconnect: function () { | ||
63 | + this.updateSessionInfos(false); | ||
64 | + $http.delete('/api/session'); | ||
37 | } | 65 | } |
38 | - }); | ||
39 | - } else { | ||
40 | - console.warn("Unnecessary get() call"); | ||
41 | - } | ||
42 | - }, | ||
43 | - connect: function (login, pass, cb) { | ||
44 | - _this = this; | ||
45 | - data = JSON.stringify({ | ||
46 | - login: login, | ||
47 | - pass: pass | ||
48 | - }); | ||
49 | - EncryptService.encrypt(data, function (dataCrypt) { | ||
50 | - $http.post('/api/session', [dataCrypt]).success(function (body) { | ||
51 | - _this.updateSessionInfos(body); | ||
52 | - if (cb) { | ||
53 | - if (this.logged) { | ||
54 | - cb(null); | ||
55 | - } else { | ||
56 | - cb(body); | ||
57 | - } | ||
58 | - } | ||
59 | - }); | ||
60 | - }); | ||
61 | - }, | ||
62 | - disconnect: function () { | ||
63 | - this.updateSessionInfos(false); | ||
64 | - $http.delete('/api/session'); | ||
65 | - } | ||
66 | - }; | ||
67 | - a.get(); | ||
68 | - return a; | ||
69 | - } | 66 | + }; |
67 | + a.get(); | ||
68 | + return a; | ||
69 | + } | ||
70 | ]); | 70 | ]); |
public/views/home.html
1 | <div class="jumbotron text-center"> | 1 | <div class="jumbotron text-center"> |
2 | <h1>Site internet du Club Info</h1> | 2 | <h1>Site internet du Club Info</h1> |
3 | - <p>Hey ! Bienvenue sur le site internet du Club Info !<br/> | ||
4 | - Pour l'instant, on travaille encore dessus, donc n'hésites pas à t'y aventurer, mais prends garde, les erreurs 404 te guettent !</p> | ||
5 | -</div> | ||
6 | \ No newline at end of file | 3 | \ No newline at end of file |
4 | + <p>Hey ! Bienvenue sur le site internet du Club Info ! | ||
5 | + <br/> Pour l'instant, on travaille encore dessus, donc n'hésites pas à t'y aventurer, mais prends garde, les erreurs 404 te guettent !</p> | ||
6 | +</div> |
public/views/index.html
1 | <!doctype html> | 1 | <!doctype html> |
2 | <html lang="fr"> | 2 | <html lang="fr"> |
3 | - <head> | ||
4 | - <meta charset="utf-8"> | ||
5 | - <base href="/"> | ||
6 | - <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
7 | - <title>Club Informatique de Polytech Lille</title> | ||
8 | - <link rel="stylesheet" href="libs/bootswatch-dist/css/bootstrap.min.css"> | ||
9 | - <link rel="stylesheet" href="css/style.css"> | ||
10 | - <script src="libs/jquery/dist/jquery.min.js"></script> | ||
11 | - <script src="libs/angular/angular.min.js"></script> | ||
12 | - <script src="libs/angular-route/angular-route.min.js"></script> | ||
13 | - <script src="libs/angular-bootstrap/ui-bootstrap.min.js"></script> | ||
14 | - <script src="libs/jsencrypt/bin/jsencrypt.min.js"></script> | ||
15 | - <script src="js/controllers/MembreCtrl.js"></script> | ||
16 | - <script src="js/services/EncryptServ.js"></script> | ||
17 | - <script src="js/services/SessionServ.js"></script> | ||
18 | - <script src="js/controllers/SessionCtrl.js"></script> | ||
19 | - <script src="js/controllers/ConnectCtrl.js"></script> | ||
20 | - <script src="js/appRoutes.js"></script> | ||
21 | - <script src="js/app.js"></script> | ||
22 | - </head> | ||
23 | - <body ng-app="ciApp"> | ||
24 | - <div class="container"> | ||
25 | - <nav class="navbar navbar-default"> | ||
26 | - <div class="container-fluid"> | ||
27 | - <div class="navbar-header"> | ||
28 | - <a class="navbar-brand" href="/">Club Info</a> | ||
29 | - </div> | ||
30 | - <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> | ||
31 | - <ul class="nav navbar-nav"> | ||
32 | - <li><a href="/membres">Membres</a></li> | ||
33 | - </ul> | ||
34 | - <ul class="nav navbar-nav navbar-right" ng-controller="SessionController"> | ||
35 | - <li> | ||
36 | - <a ng-hide="session" href="/connect">Se connecter</a> | ||
37 | - <a ng-show="session" href="#" ng-click="disconnect()">{{ session.nom }} <span class="glyphicon glyphicon-off"></span></a> | ||
38 | - </li> | ||
39 | - </ul> | ||
40 | - </div> | 3 | + |
4 | +<head> | ||
5 | + <meta charset="utf-8"> | ||
6 | + <base href="/"> | ||
7 | + <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
8 | + <title>Club Informatique de Polytech Lille</title> | ||
9 | + <link rel="stylesheet" href="libs/bootswatch-dist/css/bootstrap.min.css"> | ||
10 | + <link rel="stylesheet" href="css/style.css"> | ||
11 | + <script src="libs/jquery/dist/jquery.min.js"></script> | ||
12 | + <script src="libs/angular/angular.min.js"></script> | ||
13 | + <script src="libs/angular-route/angular-route.min.js"></script> | ||
14 | + <script src="libs/angular-bootstrap/ui-bootstrap.min.js"></script> | ||
15 | + <script src="libs/jsencrypt/bin/jsencrypt.min.js"></script> | ||
16 | + <script src="js/controllers/MembreCtrl.js"></script> | ||
17 | + <script src="js/services/EncryptServ.js"></script> | ||
18 | + <script src="js/services/SessionServ.js"></script> | ||
19 | + <script src="js/controllers/SessionCtrl.js"></script> | ||
20 | + <script src="js/controllers/ConnectCtrl.js"></script> | ||
21 | + <script src="js/appRoutes.js"></script> | ||
22 | + <script src="js/app.js"></script> | ||
23 | +</head> | ||
24 | + | ||
25 | +<body ng-app="ciApp"> | ||
26 | + <div class="container"> | ||
27 | + <nav class="navbar navbar-default"> | ||
28 | + <div class="container-fluid"> | ||
29 | + <div class="navbar-header"> | ||
30 | + <a class="navbar-brand" href="/">Club Info</a> | ||
41 | </div> | 31 | </div> |
42 | - </nav> | ||
43 | - <div ng-view></div> | ||
44 | - </div> | ||
45 | - </body> | 32 | + <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> |
33 | + <ul class="nav navbar-nav"> | ||
34 | + <li><a href="/membres">Membres</a></li> | ||
35 | + </ul> | ||
36 | + <ul class="nav navbar-nav navbar-right" ng-controller="SessionController"> | ||
37 | + <li> | ||
38 | + <a ng-hide="session" href="/connect">Se connecter</a> | ||
39 | + <a ng-show="session" href="#" ng-click="disconnect()">{{ session.nom }} <span class="glyphicon glyphicon-off"></span></a> | ||
40 | + </li> | ||
41 | + </ul> | ||
42 | + </div> | ||
43 | + </div> | ||
44 | + </nav> | ||
45 | + <div ng-view></div> | ||
46 | + </div> | ||
47 | +</body> | ||
48 | + | ||
46 | </html> | 49 | </html> |
public/views/membres.html
1 | <div class="container"> | 1 | <div class="container"> |
2 | <!-- HEADER AND TODO COUNT --> | 2 | <!-- HEADER AND TODO COUNT --> |
3 | <div class="jumbotron text-center"> | 3 | <div class="jumbotron text-center"> |
4 | - <h1>Il y a <span id="membre-qt"class="label label-info">{{ membres.length }}</span> personnes au Club Info !</h1> | 4 | + <h1>Il y a |
5 | + <span id="membre-qt" class="label label-info">{{ membres.length }}</span> personnes au Club Info !</h1> | ||
5 | <p>Mais avec toi, ça serait encore plus sympa !</p> | 6 | <p>Mais avec toi, ça serait encore plus sympa !</p> |
6 | </div> | 7 | </div> |
7 | <table id="membre-list" class="table table-striped table-hover"> | 8 | <table id="membre-list" class="table table-striped table-hover"> |
@@ -18,29 +19,31 @@ | @@ -18,29 +19,31 @@ | ||
18 | <td>{{ membre.nom }}</td> | 19 | <td>{{ membre.nom }}</td> |
19 | <td>{{ membre.section }}</td> | 20 | <td>{{ membre.section }}</td> |
20 | <td>{{ membre.role }}</td> | 21 | <td>{{ membre.role }}</td> |
21 | - <td ng-if="session.canDelMembre"><button type="button" class="btn btn-danger" aria-label="Expulser" ng-click="deleteMembre(membre._id)"> | ||
22 | - <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> | 22 | + <td ng-if="session.canDelMembre"> |
23 | + <button type="button" class="btn btn-danger" aria-label="Expulser" ng-click="deleteMembre(membre._id)"> | ||
24 | + <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> | ||
23 | </button> | 25 | </button> |
24 | </td> | 26 | </td> |
25 | </tr> | 27 | </tr> |
26 | </tbody> | 28 | </tbody> |
27 | <tfoot id="membre-form" ng-if="session.canAddMembre"> | 29 | <tfoot id="membre-form" ng-if="session.canAddMembre"> |
28 | - <tr class="form-group"> | ||
29 | - <td> | ||
30 | - <input type="text" class="form-control input-lg" placeholder="Login" ng-model="formData.login"> | ||
31 | - </td> | ||
32 | - <td class="form-inline"> | ||
33 | - <input type="text" class="form-control input-lg" placeholder="Section" ng-model="formData.section"><input type="number" class="form-control input-lg" placeholder="2015" ng-model="formData.promo"> | ||
34 | - </td> | ||
35 | - <td> | ||
36 | - <input type="text" class="form-control input-lg" placeholder="Rôle" ng-model="formData.role"> | ||
37 | - </td> | ||
38 | - <td> | ||
39 | - <button type="submit" class="btn btn-primary" aria-label="Ajouter" ng-click="createMembre()"> | ||
40 | - <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> | ||
41 | - </button> | ||
42 | - </td> | ||
43 | - </tr> | 30 | + <tr class="form-group"> |
31 | + <td> | ||
32 | + <input type="text" class="form-control input-lg" placeholder="Login" ng-model="formData.login"> | ||
33 | + </td> | ||
34 | + <td class="form-inline"> | ||
35 | + <input type="text" class="form-control input-lg" placeholder="Section" ng-model="formData.section"> | ||
36 | + <input type="number" class="form-control input-lg" placeholder="2015" ng-model="formData.promo"> | ||
37 | + </td> | ||
38 | + <td> | ||
39 | + <input type="text" class="form-control input-lg" placeholder="Rôle" ng-model="formData.role"> | ||
40 | + </td> | ||
41 | + <td> | ||
42 | + <button type="submit" class="btn btn-primary" aria-label="Ajouter" ng-click="createMembre()"> | ||
43 | + <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> | ||
44 | + </button> | ||
45 | + </td> | ||
46 | + </tr> | ||
44 | </tfoot> | 47 | </tfoot> |
45 | </table> | 48 | </table> |
46 | -</div> | ||
47 | \ No newline at end of file | 49 | \ No newline at end of file |
50 | +</div> |
server.js
@@ -5,7 +5,7 @@ var mongoose = require('mongoose'); | @@ -5,7 +5,7 @@ var mongoose = require('mongoose'); | ||
5 | var morgan = require('morgan'); | 5 | var morgan = require('morgan'); |
6 | var bodyParser = require('body-parser'); | 6 | var bodyParser = require('body-parser'); |
7 | var methodOverride = require('method-override'); | 7 | var methodOverride = require('method-override'); |
8 | -var cookieParser = require('cookie-parser') | 8 | +var cookieParser = require('cookie-parser'); |
9 | 9 | ||
10 | // Application ================================================================ | 10 | // Application ================================================================ |
11 | 11 | ||
@@ -26,7 +26,7 @@ app.use(bodyParser.urlencoded({ | @@ -26,7 +26,7 @@ app.use(bodyParser.urlencoded({ | ||
26 | app.use(methodOverride('X-HTTP-Method-Override')); | 26 | app.use(methodOverride('X-HTTP-Method-Override')); |
27 | 27 | ||
28 | // Cookie-parser | 28 | // Cookie-parser |
29 | -app.use(cookieParser()) | 29 | +app.use(cookieParser()); |
30 | 30 | ||
31 | // Dossier public | 31 | // Dossier public |
32 | app.use(express.static(__dirname + '/public')); | 32 | app.use(express.static(__dirname + '/public')); |
@@ -38,4 +38,4 @@ app.listen(port); | @@ -38,4 +38,4 @@ app.listen(port); | ||
38 | 38 | ||
39 | console.log('La magie du CI se passe au port ' + port); | 39 | console.log('La magie du CI se passe au port ' + port); |
40 | 40 | ||
41 | -exports = module.exports = app; | ||
42 | \ No newline at end of file | 41 | \ No newline at end of file |
42 | +exports = module.exports = app; |