Commit 7a1fe62de3e70db35be910d86be35a44ef002339
1 parent
238aebb6
Consistence des noms
Showing
16 changed files
with
63 additions
and
64 deletions
Show diff stats
app/models/membre.js renamed to app/models/MembreModl.js
app/models/noms.js renamed to app/models/NomsModl.js
app/models/session.js renamed to app/models/SessionModl.js
app/routes.js
app/routes/api.js renamed to app/routes/ApiRtes.js
1 | -var membres = require('../controllers/membres'); | |
2 | -var sessions = require('../controllers/sessions'); | |
3 | -var decrypt = require('../controllers/decrypt'); | |
1 | +var MembresServ = require('../services/MembresServ'); | |
2 | +var SessionsServ = require('../services/SessionsServ'); | |
3 | +var DecryptServ = require('../services/DecryptServ'); | |
4 | 4 | var express = require('express'); |
5 | 5 | |
6 | 6 | var api = express(); |
... | ... | @@ -8,11 +8,11 @@ var api = express(); |
8 | 8 | // Sessions |
9 | 9 | api.get('/session', function (req, res) { // Informations sur la session |
10 | 10 | if (req.cookies && req.cookies.session) { |
11 | - sessions.use(req.cookies.session, function (err) { | |
11 | + SessionsServ.use(req.cookies.session, function (err) { | |
12 | 12 | if (err) { |
13 | 13 | res.send(err); |
14 | 14 | } else { |
15 | - res.send(sessions.cur); | |
15 | + res.send(SessionsServ.cur); | |
16 | 16 | } |
17 | 17 | }); |
18 | 18 | // TODO si pas bon : res.clearCookie('session') |
... | ... | @@ -22,13 +22,13 @@ api.get('/session', function (req, res) { // Informations sur la session |
22 | 22 | }); |
23 | 23 | |
24 | 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) { | |
25 | + DecryptServ.decrypt(req.body[0], function (data) { | |
26 | + SessionsServ.open(JSON.parse(data), function (err) { | |
27 | 27 | if (err) { |
28 | 28 | res.send(err); |
29 | 29 | } else { |
30 | - res.cookie('session', sessions.cur._id); | |
31 | - res.send(sessions.cur); | |
30 | + res.cookie('session', SessionsServ.cur._id); | |
31 | + res.send(SessionsServ.cur); | |
32 | 32 | } |
33 | 33 | }); |
34 | 34 | }); |
... | ... | @@ -36,7 +36,7 @@ api.post('/session', function (req, res) { // Se connecter |
36 | 36 | |
37 | 37 | api.delete('/session', function (req, res) { // Se déconnecter |
38 | 38 | if (req.cookies.session) { |
39 | - sessions.delete(req.cookies.session, function () { | |
39 | + SessionsServ.delete(req.cookies.session, function () { | |
40 | 40 | res.clearCookie('session'); |
41 | 41 | res.end(); |
42 | 42 | }); |
... | ... | @@ -46,11 +46,11 @@ api.delete('/session', function (req, res) { // Se déconnecter |
46 | 46 | }); |
47 | 47 | |
48 | 48 | ifPermission = function (req, res, perm, cb) { |
49 | - sessions.use(req.cookies.session, function (err) { | |
49 | + SessionsServ.use(req.cookies.session, function (err) { | |
50 | 50 | if (err) { |
51 | 51 | res.status(403).end(); |
52 | 52 | } else { |
53 | - if (sessions.cur[perm]) { | |
53 | + if (SessionsServ.cur[perm]) { | |
54 | 54 | cb(); |
55 | 55 | } else { |
56 | 56 | res.status(403).end(); |
... | ... | @@ -62,7 +62,7 @@ ifPermission = function (req, res, perm, cb) { |
62 | 62 | |
63 | 63 | // Membres |
64 | 64 | api.get('/membres', function (req, res) { // Liste des membres |
65 | - membres.list(function (err, membres) { | |
65 | + MembresServ.list(function (err, membres) { | |
66 | 66 | if (err) |
67 | 67 | res.send(err); |
68 | 68 | else |
... | ... | @@ -72,10 +72,10 @@ api.get('/membres', function (req, res) { // Liste des membres |
72 | 72 | |
73 | 73 | api.post('/membres', function (req, res) { // Ajout d'un membre |
74 | 74 | ifPermission(req, res, 'canAddMembre', function () { |
75 | - membres.add(req.body, function (err, membre) { | |
75 | + MembresServ.add(req.body, function (err, membre) { | |
76 | 76 | if (err) |
77 | 77 | res.send(err); |
78 | - membres.list(function (err, membres) { | |
78 | + MembresServ.list(function (err, membres) { | |
79 | 79 | if (err) |
80 | 80 | res.send(err); |
81 | 81 | res.json(membres); |
... | ... | @@ -86,10 +86,10 @@ api.post('/membres', function (req, res) { // Ajout d'un membre |
86 | 86 | |
87 | 87 | api.delete('/membres/:membre_id', function (req, res) { // Supression d'un membre |
88 | 88 | ifPermission(req, res, 'canDelMembre', function () { |
89 | - membres.remove(req.params.membre_id, function (err, membre) { | |
89 | + MembresServ.remove(req.params.membre_id, function (err, membre) { | |
90 | 90 | if (err) |
91 | 91 | res.send(err); |
92 | - membres.list(function (err, membres) { | |
92 | + MembresServ.list(function (err, membres) { | |
93 | 93 | if (err) |
94 | 94 | res.send(err); |
95 | 95 | res.json(membres); | ... | ... |
app/controllers/decrypt.js renamed to app/services/DecryptServ.js
1 | 1 | var ursa = require('ursa'); |
2 | 2 | var fs = require('fs'); |
3 | 3 | |
4 | -var decrypt = {}; | |
4 | +var DecryptServ = {}; | |
5 | 5 | |
6 | -decrypt.decrypter = false; | |
6 | +DecryptServ.decrypter = false; | |
7 | 7 | |
8 | -decrypt.whenOk = function (cb) { | |
8 | +DecryptServ.whenOk = function (cb) { | |
9 | 9 | if (this.encrypter) { |
10 | 10 | cb(); |
11 | 11 | } else { |
... | ... | @@ -13,7 +13,7 @@ decrypt.whenOk = function (cb) { |
13 | 13 | } |
14 | 14 | }; |
15 | 15 | |
16 | -decrypt.prepare = function (cb) { | |
16 | +DecryptServ.prepare = function (cb) { | |
17 | 17 | fs.readFile('config/ci_com.pem', function (err, data) { |
18 | 18 | if (err) { |
19 | 19 | throw err; |
... | ... | @@ -23,14 +23,14 @@ decrypt.prepare = function (cb) { |
23 | 23 | }); |
24 | 24 | }; |
25 | 25 | |
26 | -decrypt.preload = function (cb) { | |
26 | +DecryptServ.preload = function (cb) { | |
27 | 27 | this.whenOk(cb); |
28 | 28 | }; |
29 | 29 | |
30 | -decrypt.decrypt = function (string, cb) { | |
30 | +DecryptServ.decrypt = function (string, cb) { | |
31 | 31 | this.whenOk(function () { |
32 | 32 | cb(this.decrypter.decrypt(string, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING)); |
33 | 33 | }); |
34 | 34 | }; |
35 | 35 | |
36 | -module.exports = decrypt; | |
36 | +module.exports = DecryptServ; | ... | ... |
app/controllers/membres.js renamed to app/services/MembresServ.js
1 | -var Membre = require('../models/membre'); | |
2 | -var noms = require('../controllers/noms'); | |
1 | +var MembreModl = require('../models/MembreModl'); | |
2 | +var NomsServ = require('../services/NomsServ'); | |
3 | 3 | var async = require('async'); |
4 | 4 | |
5 | 5 | var membres = {}; |
6 | 6 | |
7 | 7 | membres.list = function (cb) { |
8 | - Membre.find({}).lean().exec(function (err, membres) { | |
8 | + MembreModl.find({}).lean().exec(function (err, membres) { | |
9 | 9 | addNom = function (membre, cbA) { |
10 | - noms.get(membre.login, function (nom) { | |
10 | + NomsServ.get(membre.login, function (nom) { | |
11 | 11 | if (nom) { |
12 | 12 | membre.nom = nom; |
13 | 13 | } else { |
... | ... | @@ -21,7 +21,7 @@ membres.list = function (cb) { |
21 | 21 | }; |
22 | 22 | |
23 | 23 | membres.add = function (data, cb) { |
24 | - Membre.create({ | |
24 | + MembreModl.create({ | |
25 | 25 | login: data.login, |
26 | 26 | role: data.role, |
27 | 27 | section: data.section, |
... | ... | @@ -29,7 +29,7 @@ membres.add = function (data, cb) { |
29 | 29 | }; |
30 | 30 | |
31 | 31 | membres.remove = function (id, cb) { |
32 | - Membre.remove({ | |
32 | + MembreModl.remove({ | |
33 | 33 | _id: id |
34 | 34 | }, cb); |
35 | 35 | }; | ... | ... |
app/controllers/noms.js renamed to app/services/NomsServ.js
1 | -var Noms = require('../models/noms'); | |
1 | +var NomsModl = require('../models/NomsModl'); | |
2 | 2 | var LineTransform = require('node-line-reader').LineTransform; |
3 | 3 | var fs = require('fs'); |
4 | 4 | |
5 | 5 | var noms = {}; |
6 | 6 | |
7 | 7 | noms.get = function (login, cb) { |
8 | - Noms.findOne({ | |
8 | + NomsModl.findOne({ | |
9 | 9 | login: login |
10 | 10 | }, function (err, nom) { |
11 | 11 | if (err) { |
... | ... | @@ -28,7 +28,7 @@ noms.get = function (login, cb) { |
28 | 28 | stream.close(); |
29 | 29 | cb(ex[4]); |
30 | 30 | found = true; |
31 | - Noms.create({ | |
31 | + NomsModl.create({ | |
32 | 32 | login: login, |
33 | 33 | nom: ex[4] |
34 | 34 | }); | ... | ... |
app/controllers/sessions.js renamed to app/services/SessionsServ.js
1 | -var Session = require('../models/session'); | |
2 | -var noms = require('../controllers/noms'); | |
1 | +var SessionModl = require('../models/SessionModl'); | |
2 | +var NomsServ = require('../services/NomsServ'); | |
3 | 3 | |
4 | 4 | var sessions = {}; |
5 | 5 | |
6 | 6 | sessions.cur = false; |
7 | 7 | |
8 | 8 | sessions.addData = function (session, cb) { |
9 | - noms.get(session.login, function (nom) { | |
9 | + NomsServ.get(session.login, function (nom) { | |
10 | 10 | if (typeof nom == 'string') { |
11 | 11 | session.nom = nom; |
12 | 12 | } else { |
... | ... | @@ -20,7 +20,7 @@ sessions.addData = function (session, cb) { |
20 | 20 | |
21 | 21 | sessions.find = function (id, cb) { |
22 | 22 | _this = this; |
23 | - Session.findById(id).lean().exec(function (err, session) { | |
23 | + SessionModl.findById(id).lean().exec(function (err, session) { | |
24 | 24 | if (typeof session == 'object') { |
25 | 25 | _this.addData(session, function (session) { |
26 | 26 | cb(err, session); |
... | ... | @@ -36,7 +36,7 @@ sessions.valid = function (session) { |
36 | 36 | }; |
37 | 37 | |
38 | 38 | sessions.delete = function (id, cb) { |
39 | - Session.remove({ | |
39 | + SessionModl.remove({ | |
40 | 40 | _id: id |
41 | 41 | }, cb); |
42 | 42 | }; |
... | ... | @@ -74,14 +74,14 @@ sessions.use = function (id, cb) { |
74 | 74 | }; |
75 | 75 | |
76 | 76 | sessions.create = function (login, cb) { |
77 | - Session.create({ | |
77 | + SessionModl.create({ | |
78 | 78 | login: login |
79 | 79 | }, cb); |
80 | 80 | }; |
81 | 81 | |
82 | 82 | sessions.login = function (data, cb) { |
83 | 83 | // DUMMY |
84 | - noms.get(data.login, function (nom) { | |
84 | + NomsServ.get(data.login, function (nom) { | |
85 | 85 | if (nom === false) { |
86 | 86 | cb(null, false); |
87 | 87 | } else { | ... | ... |
public/js/appRoutes.js
1 | -// public/js/appRoutes.js | |
2 | 1 | angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', |
3 | 2 | function ($routeProvider, $locationProvider) { |
4 | 3 | $routeProvider |
... | ... | @@ -7,11 +6,11 @@ angular.module('appRoutes', []).config(['$routeProvider', '$locationProvider', |
7 | 6 | }) |
8 | 7 | .when('/membres', { |
9 | 8 | templateUrl: 'views/membres.html', |
10 | - controller: 'MembreController' | |
9 | + controller: 'MembreCtrl' | |
11 | 10 | }) |
12 | 11 | .when('/connect', { |
13 | 12 | templateUrl: 'views/connect.html', |
14 | - controller: 'ConnectController' | |
13 | + controller: 'ConnectCtrl' | |
15 | 14 | }); |
16 | 15 | |
17 | 16 | $locationProvider.html5Mode(true); | ... | ... |
public/js/controllers/ConnectCtrl.js
1 | -angular.module('ConnectCtrl', []).controller('ConnectController', ['$scope', 'SessionService', 'EncryptService', | |
2 | - function ($scope, SessionService, EncryptService) { | |
3 | - EncryptService.preload(function () { | |
1 | +angular.module('ConnectCtrl', []).controller('ConnectCtrl', ['$scope', 'SessionServ', 'EncryptServ', | |
2 | + function ($scope, SessionServ, EncryptServ) { | |
3 | + EncryptServ.preload(function () { | |
4 | 4 | return undefined; |
5 | 5 | }); |
6 | 6 | $scope.connect = { |
7 | 7 | connect: function () { |
8 | - SessionService.connect($scope.connect.login, $scope.connect.pass); | |
8 | + SessionServ.connect($scope.connect.login, $scope.connect.pass); | |
9 | 9 | } |
10 | 10 | }; |
11 | 11 | } | ... | ... |
public/js/controllers/MembreCtrl.js
1 | -angular.module('MembreCtrl', []).controller('MembreController', ['$scope', '$http', 'SessionService', | |
2 | - function ($scope, $http, SessionService) { | |
1 | +angular.module('MembreCtrl', []).controller('MembreCtrl', ['$scope', '$http', 'SessionServ', | |
2 | + function ($scope, $http, SessionServ) { | |
3 | 3 | $scope.formData = {}; |
4 | 4 | |
5 | - $scope.session = SessionService.cur; | |
6 | - SessionService.onChange(function () { | |
7 | - $scope.session = SessionService.cur; | |
5 | + $scope.session = SessionServ.cur; | |
6 | + SessionServ.onChange(function () { | |
7 | + $scope.session = SessionServ.cur; | |
8 | 8 | }); |
9 | 9 | |
10 | 10 | $http.get('/api/membres') | ... | ... |
public/js/controllers/SessionCtrl.js
1 | -angular.module('SessionsCtrl', []).controller('SessionController', ['$scope', 'SessionService', | |
2 | - function ($scope, SessionService) { | |
3 | - $scope.session = SessionService.cur; | |
1 | +angular.module('SessionsCtrl', []).controller('SessionCtrl', ['$scope', 'SessionServ', | |
2 | + function ($scope, SessionServ) { | |
3 | + $scope.session = SessionServ.cur; | |
4 | 4 | $scope.disconnect = function () { |
5 | - SessionService.disconnect(); | |
5 | + SessionServ.disconnect(); | |
6 | 6 | }; |
7 | - SessionService.onChange(function () { | |
8 | - $scope.session = SessionService.cur; | |
7 | + SessionServ.onChange(function () { | |
8 | + $scope.session = SessionServ.cur; | |
9 | 9 | }); |
10 | 10 | // $scope.$on("$destroy", function () { |
11 | 11 | // // TODO | ... | ... |
public/js/services/EncryptServ.js
public/js/services/SessionServ.js
1 | -angular.module('SessionsServ', []).service('SessionService', ['$http', 'EncryptService', | |
2 | - function ($http, EncryptService) { | |
1 | +angular.module('SessionsServ', []).service('SessionServ', ['$http', 'EncryptServ', | |
2 | + function ($http, EncryptServ) { | |
3 | 3 | a = { |
4 | 4 | cur: false, |
5 | 5 | status: 0, |
... | ... | @@ -46,7 +46,7 @@ angular.module('SessionsServ', []).service('SessionService', ['$http', 'EncryptS |
46 | 46 | login: login, |
47 | 47 | pass: pass |
48 | 48 | }); |
49 | - EncryptService.encrypt(data, function (dataCrypt) { | |
49 | + EncryptServ.encrypt(data, function (dataCrypt) { | |
50 | 50 | $http.post('/api/session', [dataCrypt]).success(function (body) { |
51 | 51 | _this.updateSessionInfos(body); |
52 | 52 | if (cb) { | ... | ... |
public/views/index.html
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | <ul class="nav navbar-nav"> |
34 | 34 | <li><a href="/membres">Membres</a></li> |
35 | 35 | </ul> |
36 | - <ul class="nav navbar-nav navbar-right" ng-controller="SessionController"> | |
36 | + <ul class="nav navbar-nav navbar-right" ng-controller="SessionCtrl"> | |
37 | 37 | <li> |
38 | 38 | <a ng-hide="session" href="/connect">Se connecter</a> |
39 | 39 | <a ng-show="session" href="#" ng-click="disconnect()">{{ session.nom }} <span class="glyphicon glyphicon-off"></span></a> | ... | ... |