diff --git a/.bowerrc b/.bowerrc index 59a1cfd..1d9ce40 100644 --- a/.bowerrc +++ b/.bowerrc @@ -1,3 +1,3 @@ { "directory": "public/libs" -} \ No newline at end of file +} diff --git a/app/controllers/decrypt.js b/app/controllers/decrypt.js index 731cecd..55e1b07 100644 --- a/app/controllers/decrypt.js +++ b/app/controllers/decrypt.js @@ -6,31 +6,31 @@ var decrypt = {}; decrypt.decrypter = false; decrypt.whenOk = function (cb) { - if (this.encrypter) { - cb(); - } else { - this.prepare(cb); - } + if (this.encrypter) { + cb(); + } else { + this.prepare(cb); + } }; decrypt.prepare = function (cb) { - fs.readFile('config/ci_com.pem', function(err, data) { - if (err) { - throw err; - } - this.decrypter = ursa.createPrivateKey(data); - cb(); - }); + fs.readFile('config/ci_com.pem', function (err, data) { + if (err) { + throw err; + } + this.decrypter = ursa.createPrivateKey(data); + cb(); + }); }; -decrypt.preload = function(cb) { - this.whenOk(cb); +decrypt.preload = function (cb) { + this.whenOk(cb); }; decrypt.decrypt = function (string, cb) { - this.whenOk(function() { - cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING)); - }); + this.whenOk(function () { + cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING)); + }); }; module.exports = decrypt; diff --git a/app/controllers/membres.js b/app/controllers/membres.js index 0d65db6..4982124 100644 --- a/app/controllers/membres.js +++ b/app/controllers/membres.js @@ -1,26 +1,26 @@ var Membre = require('../models/membre'); var noms = require('../controllers/noms'); -var async = require('async') +var async = require('async'); -var membres = {} +var membres = {}; membres.list = function (cb) { Membre.find({}).lean().exec(function (err, membres) { addNom = function (membre, cb) { noms.get(membre.login, function (nom) { if (nom) { - membre.nom = nom + membre.nom = nom; } else { - membre.nom = membre.login + membre.nom = membre.login; } - cb(null, membre) - }) - } + cb(null, membre); + }); + }; async.mapSeries(membres, addNom, function (err, results) { - cb(results) - }) + cb(results); + }); }); -} +}; membres.add = function (data, cb) { Membre.create({ @@ -28,12 +28,12 @@ membres.add = function (data, cb) { role: data.role, section: data.section, }, cb); -} +}; membres.remove = function (id, cb) { Membre.remove({ _id: id }, cb); -} +}; -module.exports = membres; \ No newline at end of file +module.exports = membres; diff --git a/app/controllers/noms.js b/app/controllers/noms.js index 65c6f0b..1dd6901 100644 --- a/app/controllers/noms.js +++ b/app/controllers/noms.js @@ -1,52 +1,52 @@ var Noms = require('../models/noms'); var LineTransform = require('node-line-reader').LineTransform; -var fs = require('fs') +var fs = require('fs'); -var noms = {} +var noms = {}; noms.get = function (login, cb) { Noms.findOne({ login: login }, function (err, nom) { if (err) { - console.error(err) - cb(false) + console.error(err); + cb(false); } else { if (nom) { - cb(nom.nom) + cb(nom.nom); } else { - passwdF = 'config/passwd' + passwdF = 'config/passwd'; fs.exists(passwdF, function (exists) { - found = false + found = false; if (exists) { - stream = fs.createReadStream(passwdF) - transform = new LineTransform() - stream.pipe(transform) + stream = fs.createReadStream(passwdF); + transform = new LineTransform(); + stream.pipe(transform); transform.on('data', function (line) { - ex = line.split(':') + ex = line.split(':'); if (ex[0] == login) { // Si trouvé - stream.close() - cb(ex[4]) - found = true + stream.close(); + cb(ex[4]); + found = true; Noms.create({ login: login, nom: ex[4] - }) + }); } - }) + }); transform.on('end', function () { if (!found) { - cb(false) + cb(false); } - }) + }); } else { - console.error("Impossible de trouver le fichier passwd") - cb(login.toUpperCase()) + console.error("Impossible de trouver le fichier passwd"); + cb(login.toUpperCase()); } - }) + }); } } - }) -} + }); +}; -module.exports = noms; \ No newline at end of file +module.exports = noms; diff --git a/app/controllers/sessions.js b/app/controllers/sessions.js index f4cbba0..1ba72eb 100644 --- a/app/controllers/sessions.js +++ b/app/controllers/sessions.js @@ -1,48 +1,48 @@ var Session = require('../models/session'); var noms = require('../controllers/noms'); -var sessions = {} +var sessions = {}; -sessions.cur = false +sessions.cur = false; sessions.addData = function (session, cb) { noms.get(session.login, function (nom) { if (typeof nom == 'string') { - session.nom = nom + session.nom = nom; } else { - session.nom = 'Inconnu' + session.nom = 'Inconnu'; } - session.canAddMembre = session.login == 'gbontoux' - session.canDelMembre = session.login == 'gbontoux' - cb(session) - }) -} + session.canAddMembre = session.login == 'gbontoux'; + session.canDelMembre = session.login == 'gbontoux'; + cb(session); + }); +}; sessions.find = function (id, cb) { - _this = this + _this = this; Session.findById(id).lean().exec(function (err, session) { if (typeof session == 'object') { _this.addData(session, function (session) { - cb(err, session) - }) + cb(err, session); + }); } else { - cb(err, null) + cb(err, null); } - }) -} + }); +}; sessions.valid = function (session) { - return session.started.setSeconds(session.started.getSeconds() + 3600) > new Date() -} + return session.started.setSeconds(session.started.getSeconds() + 3600) > new Date(); +}; sessions.delete = function (id, cb) { Session.remove({ _id: id }, cb); -} +}; sessions.verify = function (id, cb) { - _this = this + _this = this; _this.find(id, function (err, session) { if (err) { cb('error'); @@ -52,67 +52,67 @@ sessions.verify = function (id, cb) { cb(null, session); } else { cb('expired'); - _this.delete(id) + _this.delete(id); } } else { - cb('unknown') + cb('unknown'); } } }); -} +}; sessions.use = function (id, cb) { - _this = this + _this = this; _this.verify(id, function (err, session) { if (err) { - cb(err) + cb(err); } else { - _this.cur = session - cb(null) + _this.cur = session; + cb(null); } - }) -} + }); +}; sessions.create = function (login, cb) { Session.create({ login: login }, cb); -} +}; sessions.login = function (data, cb) { // DUMMY noms.get(data.login, function (nom) { - if (nom == false) { - cb(null, false) + if (nom === false) { + cb(null, false); } else { if (data.pass == 'cool') { - cb(null, true) + cb(null, true); } else { - cb(null, false) + cb(null, false); } } - }) -} + }); +}; sessions.open = function (data, cb) { - _this = this + _this = this; _this.login(data, function (err, res) { if (err) { - cb('error') + cb('error'); } else { if (res) { _this.create(data.login, function (err, session) { if (err) { cb('error'); } else { - _this.use(session._id, cb) + _this.use(session._id, cb); } }); } else { - cb('invalid') + cb('invalid'); } } }); -} +}; module.exports = sessions; diff --git a/app/models/membre.js b/app/models/membre.js index a34280f..2f4fb07 100644 --- a/app/models/membre.js +++ b/app/models/membre.js @@ -17,4 +17,4 @@ module.exports = mongoose.model('Membre', { type: String, default: 'Membre' } -}); \ No newline at end of file +}); diff --git a/app/models/noms.js b/app/models/noms.js index 7d46952..724a062 100644 --- a/app/models/noms.js +++ b/app/models/noms.js @@ -9,4 +9,4 @@ module.exports = mongoose.model('Noms', { type: String, default: 'Nom' } -}); \ No newline at end of file +}); diff --git a/app/models/session.js b/app/models/session.js index 2c4838d..465dce2 100644 --- a/app/models/session.js +++ b/app/models/session.js @@ -9,4 +9,4 @@ module.exports = mongoose.model('Session', { type: Date, default: Date.now } -}); \ No newline at end of file +}); diff --git a/app/routes.js b/app/routes.js index f352d72..2ce8478 100644 --- a/app/routes.js +++ b/app/routes.js @@ -2,10 +2,10 @@ var api = require('./routes/api'); module.exports = function (app) { - app.use('/api/', api) + app.use('/api/', api); app.get('*', function (req, res) { res.sendfile('./public/views/index.html'); }); -}; \ No newline at end of file +}; diff --git a/app/routes/api.js b/app/routes/api.js index 940d3bd..3fa08f0 100644 --- a/app/routes/api.js +++ b/app/routes/api.js @@ -7,94 +7,94 @@ var api = express(); // Sessions api.get('/session', function (req, res) { // Informations sur la session - if (req.cookies && req.cookies.session) { - sessions.use(req.cookies.session, function (err) { - if (err) { - res.send(err); - } else { - res.send(sessions.cur); - } - }); - // TODO si pas bon : res.clearCookie('session') - } else { - res.send('missing'); - } + if (req.cookies && req.cookies.session) { + sessions.use(req.cookies.session, function (err) { + if (err) { + res.send(err); + } else { + res.send(sessions.cur); + } + }); + // TODO si pas bon : res.clearCookie('session') + } else { + res.send('missing'); + } }); api.post('/session', function (req, res) { // Se connecter - decrypt.decrypt(req.body[0], function (data) { - sessions.open(JSON.parse(data), function (err) { - if (err) { - res.send(err); - } else { - res.cookie('session', sessions.cur._id); - res.send(sessions.cur); - } + decrypt.decrypt(req.body[0], function (data) { + sessions.open(JSON.parse(data), function (err) { + if (err) { + res.send(err); + } else { + res.cookie('session', sessions.cur._id); + res.send(sessions.cur); + } + }); }); - }); }); api.delete('/session', function (req, res) { // Se déconnecter - if (req.cookies.session) { - sessions.delete(req.cookies.session, function () { - res.clearCookie('session'); - res.end(); - }); - } else { - res.send('missing'); - } + if (req.cookies.session) { + sessions.delete(req.cookies.session, function () { + res.clearCookie('session'); + res.end(); + }); + } else { + res.send('missing'); + } }); ifPermission = function (req, res, perm, cb) { - sessions.use(req.cookies.session, function (err) { - if (err) { - res.status(403).end(); - } else { - if (sessions.cur[perm]) { - cb(); - } else { - res.status(403).end(); - } - } - }); + sessions.use(req.cookies.session, function (err) { + if (err) { + res.status(403).end(); + } else { + if (sessions.cur[perm]) { + cb(); + } else { + res.status(403).end(); + } + } + }); }; // Membres api.get('/membres', function (req, res) { // Liste des membres - membres.list(function (err, membres) { - if (err) - res.send(err); - res.json(membres); - }); + membres.list(function (err, membres) { + if (err) + res.send(err); + res.json(membres); + }); }); api.post('/membres', function (req, res) { // Ajout d'un membre - ifPermission(req, res, 'canAddMembre', function () { - membres.add(req.body, function (err, membre) { - if (err) - res.send(err); - membres.list(function (err, membres) { - if (err) - res.send(err); - res.json(membres); - }); + ifPermission(req, res, 'canAddMembre', function () { + membres.add(req.body, function (err, membre) { + if (err) + res.send(err); + membres.list(function (err, membres) { + if (err) + res.send(err); + res.json(membres); + }); + }); }); - }); }); api.delete('/membres/:membre_id', function (req, res) { // Supression d'un membre - ifPermission(req, res, 'canDelMembre', function () { - membres.remove(req.params.membre_id, function (err, membre) { - if (err) - res.send(err); - membres.list(function (err, membres) { - if (err) - res.send(err); - res.json(membres); - }); + ifPermission(req, res, 'canDelMembre', function () { + membres.remove(req.params.membre_id, function (err, membre) { + if (err) + res.send(err); + membres.list(function (err, membres) { + if (err) + res.send(err); + res.json(membres); + }); + }); }); - }); }); module.exports = api; diff --git a/bower.json b/bower.json index 8945875..d65a014 100644 --- a/bower.json +++ b/bower.json @@ -1,11 +1,11 @@ { - "name": "ci-site", - "version": "0.0.1", - "dependencies": { - "font-awesome": "latest", - "angular": "latest", - "angular-route": "latest", - "bootswatch-dist": "3.3.2-cerulean", - "jsencrypt": "~2.1.0" - } + "name": "ci-site", + "version": "0.0.1", + "dependencies": { + "font-awesome": "latest", + "angular": "latest", + "angular-route": "latest", + "bootswatch-dist": "3.3.2-cerulean", + "jsencrypt": "~2.1.0" + } } diff --git a/package.json b/package.json index 9ff333a..7938a38 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { - "name": "ci-site", - "main": "server.js", - "dependencies": { - "async": "^0.9.0", - "body-parser": "^1.12.0", - "cookie-parser": "^1.3.4", - "express": "^4.12.2", - "method-override": "^2.3.1", - "mongoose": "^3.8.25", - "morgan": "^1.5.1", - "node-line-reader": "0.0.2", - "ursa": "^0.8.4" - } + "name": "ci-site", + "main": "server.js", + "dependencies": { + "async": "^0.9.0", + "body-parser": "^1.12.0", + "cookie-parser": "^1.3.4", + "express": "^4.12.2", + "method-override": "^2.3.1", + "mongoose": "^3.8.25", + "morgan": "^1.5.1", + "node-line-reader": "0.0.2", + "ursa": "^0.8.4" + } } diff --git a/public/css/style.css b/public/css/style.css index dd8f285..171965b 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -7,5 +7,5 @@ body { } #membre-list { - width: 90 %; -} \ No newline at end of file + width: 90%; +} diff --git a/public/js/appRoutes.js b/public/js/appRoutes.js index dc78578..9e3b7d3 100644 --- a/public/js/appRoutes.js +++ b/public/js/appRoutes.js @@ -17,4 +17,4 @@ angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', $locationProvider.html5Mode(true); } -]); \ No newline at end of file +]); diff --git a/public/js/controllers/ConnectCtrl.js b/public/js/controllers/ConnectCtrl.js index 3e1661e..df90562 100644 --- a/public/js/controllers/ConnectCtrl.js +++ b/public/js/controllers/ConnectCtrl.js @@ -1,12 +1,12 @@ angular.module('ConnectCtrl', []).controller('ConnectController', ['$scope', 'SessionService', 'EncryptService', - function ($scope, SessionService, EncryptService) { - EncryptService.preload(function () { - return undefined; - }); - $scope.connect = { - connect: function () { - SessionService.connect($scope.connect.login, $scope.connect.pass); - } - }; - } + function ($scope, SessionService, EncryptService) { + EncryptService.preload(function () { + return undefined; + }); + $scope.connect = { + connect: function () { + SessionService.connect($scope.connect.login, $scope.connect.pass); + } + }; + } ]); diff --git a/public/js/controllers/MembreCtrl.js b/public/js/controllers/MembreCtrl.js index 4386f84..684efdb 100644 --- a/public/js/controllers/MembreCtrl.js +++ b/public/js/controllers/MembreCtrl.js @@ -2,10 +2,10 @@ angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$htt function ($scope, $http, SessionService) { $scope.formData = {}; - $scope.session = SessionService.cur + $scope.session = SessionService.cur; SessionService.onChange(function () { - $scope.session = SessionService.cur - }) + $scope.session = SessionService.cur; + }); $http.get('/api/membres') .success(function (data) { @@ -40,4 +40,4 @@ angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$htt }; } -]); \ No newline at end of file +]); diff --git a/public/js/controllers/SessionCtrl.js b/public/js/controllers/SessionCtrl.js index 23382b8..f00ba15 100644 --- a/public/js/controllers/SessionCtrl.js +++ b/public/js/controllers/SessionCtrl.js @@ -1,14 +1,14 @@ angular.module('SessionsCtrl', []).controller('SessionController', ['$scope', 'SessionService', function ($scope, SessionService) { - $scope.session = SessionService.cur + $scope.session = SessionService.cur; $scope.disconnect = function () { - SessionService.disconnect() - } + SessionService.disconnect(); + }; SessionService.onChange(function () { - $scope.session = SessionService.cur - }) - // $scope.$on("$destroy", function () { - // // TODO - // }) + $scope.session = SessionService.cur; + }); + // $scope.$on("$destroy", function () { + // // TODO + // }) } -]); \ No newline at end of file +]); diff --git a/public/js/services/EncryptServ.js b/public/js/services/EncryptServ.js index e7cd25a..119ee0e 100644 --- a/public/js/services/EncryptServ.js +++ b/public/js/services/EncryptServ.js @@ -1,30 +1,30 @@ angular.module('EncryptServ', []).service('EncryptService', ['$http', - function ($http) { - a = { - encrypter: false, - whenOk: function (cb) { - if (this.encrypter) { - cb(); - } else { - this.prepare(cb); - } - }, - prepare: function (cb) { - $http.get('/com/ci_com_pub.pem').success(function (key) { - this.encrypter = new JSEncrypt(); - this.encrypter.setPublicKey(key); - cb(); - }); - }, - preload: function(cb) { - this.whenOk(cb); - }, - encrypt: function (string, cb) { - this.whenOk(function() { - cb(this.encrypter.encrypt(string)); - }); - } - }; - return a; - } + function ($http) { + a = { + encrypter: false, + whenOk: function (cb) { + if (this.encrypter) { + cb(); + } else { + this.prepare(cb); + } + }, + prepare: function (cb) { + $http.get('/com/ci_com_pub.pem').success(function (key) { + this.encrypter = new JSEncrypt(); + this.encrypter.setPublicKey(key); + cb(); + }); + }, + preload: function (cb) { + this.whenOk(cb); + }, + encrypt: function (string, cb) { + this.whenOk(function () { + cb(this.encrypter.encrypt(string)); + }); + } + }; + return a; + } ]); diff --git a/public/js/services/SessionServ.js b/public/js/services/SessionServ.js index cee6238..5a0bab2 100644 --- a/public/js/services/SessionServ.js +++ b/public/js/services/SessionServ.js @@ -1,70 +1,70 @@ angular.module('SessionsServ', []).service('SessionService', ['$http', 'EncryptService', - function ($http, EncryptService) { - a = { - cur: false, - status: 0, - changeHandlers: [], - onChange: function (fun) { - this.changeHandlers.push(fun); - }, - triggerChange: function () { - for (var fun in this.changeHandlers) { - this.changeHandlers[fun](); - } - }, - updateSessionInfos: function (data) { - console.log("Connection:", data); - if (typeof data === 'object') { - this.cur = data; - } else { - this.cur = false; - } - this.triggerChange(); - }, - get: function (cb) { // Fetch infos if needed - if (status === 0) { - this.status = 1; // Fetching - _this = this; - // TODO Verify if cookies to prevent uneeded request - $http.get('/api/session').success(function (body) { - _this.updateSessionInfos(body); - if (cb) { - if (this.logged) { - cb(null); - } else { - cb(body); - } + function ($http, EncryptService) { + a = { + cur: false, + status: 0, + changeHandlers: [], + onChange: function (fun) { + this.changeHandlers.push(fun); + }, + triggerChange: function () { + for (var fun in this.changeHandlers) { + this.changeHandlers[fun](); + } + }, + updateSessionInfos: function (data) { + console.log("Connection:", data); + if (typeof data === 'object') { + this.cur = data; + } else { + this.cur = false; + } + this.triggerChange(); + }, + get: function (cb) { // Fetch infos if needed + if (status === 0) { + this.status = 1; // Fetching + _this = this; + // TODO Verify if cookies to prevent uneeded request + $http.get('/api/session').success(function (body) { + _this.updateSessionInfos(body); + if (cb) { + if (this.logged) { + cb(null); + } else { + cb(body); + } + } + }); + } else { + console.warn("Unnecessary get() call"); + } + }, + connect: function (login, pass, cb) { + _this = this; + data = JSON.stringify({ + login: login, + pass: pass + }); + EncryptService.encrypt(data, function (dataCrypt) { + $http.post('/api/session', [dataCrypt]).success(function (body) { + _this.updateSessionInfos(body); + if (cb) { + if (this.logged) { + cb(null); + } else { + cb(body); + } + } + }); + }); + }, + disconnect: function () { + this.updateSessionInfos(false); + $http.delete('/api/session'); } - }); - } else { - console.warn("Unnecessary get() call"); - } - }, - connect: function (login, pass, cb) { - _this = this; - data = JSON.stringify({ - login: login, - pass: pass - }); - EncryptService.encrypt(data, function (dataCrypt) { - $http.post('/api/session', [dataCrypt]).success(function (body) { - _this.updateSessionInfos(body); - if (cb) { - if (this.logged) { - cb(null); - } else { - cb(body); - } - } - }); - }); - }, - disconnect: function () { - this.updateSessionInfos(false); - $http.delete('/api/session'); - } - }; - a.get(); - return a; - } + }; + a.get(); + return a; + } ]); diff --git a/public/views/home.html b/public/views/home.html index 340af94..bcd7fa4 100644 --- a/public/views/home.html +++ b/public/views/home.html @@ -1,5 +1,5 @@
Hey ! Bienvenue sur le site internet du Club Info !
- Pour l'instant, on travaille encore dessus, donc n'hésites pas à t'y aventurer, mais prends garde, les erreurs 404 te guettent !
Hey ! Bienvenue sur le site internet du Club Info !
+
Pour l'instant, on travaille encore dessus, donc n'hésites pas à t'y aventurer, mais prends garde, les erreurs 404 te guettent !