Commit 43b2778dd43adfc870c873db58c77f43781eb66c

Authored by Geoffrey PREUD'HOMME
1 parent a9a5cb2a

Rassemblement de tout ce qui est compte Polytech

app/models/NomsModl.js renamed to app/models/PolyUserModl.js
1 1 var mongoose = require('mongoose');
2 2  
3   -module.exports = mongoose.model('Noms', {
4   - login: { // On récupèrera le nom via les passwd
  3 +module.exports = mongoose.model('PolyUser', {
  4 + login: {
5 5 type: String,
6 6 default: 'login'
7 7 },
... ...
app/services/ConvsServ.js
1 1 var ConvModl = require('../models/ConvModl');
2   -// var NomsServ = require('../services/NomsServ');
  2 +// var PolyUserServ = require('../services/PolyUserServ');
3 3 var async = require('async');
4 4  
5 5 var ConvsServ = {};
6 6  
7 7 ConvsServ.addData = function (conv, cb) {
8   - // NomsServ.get(Conv.login, function (nom) {
  8 + // PolyUserServ.get(Conv.login, function (err, nom) {
9 9 // if (nom) {
10 10 // Conv.nom = nom;
11 11 // } else {
... ...
app/services/MembresServ.js
1 1 var MembreModl = require('../models/MembreModl');
2   -var NomsServ = require('../services/NomsServ');
  2 +var PolyUserServ = require('../services/PolyUserServ');
3 3 var async = require('async');
4 4  
5 5 var MembresServ = {};
6 6  
7 7 MembresServ.addData = function (membre, cb) {
8   - NomsServ.get(membre.login, function (nom) {
  8 + PolyUserServ.get(membre.login, function (err, nom) {
9 9 membre.nom = nom.nom;
10 10 membre.section = nom.section;
11 11 cb(null, membre);
... ...
app/services/MessServ.js
1 1 var MessModl = require('../models/MessModl');
2   -// var NomsServ = require('../services/NomsServ');
  2 +// var PolyUserServ = require('../services/PolyUserServ');
3 3 var ConvsServ = require('../services/ConvsServ');
4 4 var async = require('async');
5 5  
6 6 var MesssServ = {};
7 7  
8 8 MesssServ.addData = function (mess, cb) {
9   - // NomsServ.get(Mess.login, function (nom) {
  9 + // PolyUserServ.get(Mess.login, function (err, nom) {
10 10 // if (nom) {
11 11 // Mess.nom = nom;
12 12 // } else {
... ...
app/services/NomsServ.js renamed to app/services/PolyUserServ.js
1   -var NomsModl = require('../models/NomsModl');
  1 +var PolyUserModl = require('../models/PolyUserModl');
2 2 var LineTransform = require('node-line-reader').LineTransform;
3 3 var fs = require('fs');
  4 +var Client = require('ssh2').Client;
  5 +var creds = require('../../config/sshAuth');
4 6  
5   -var noms = {};
  7 +var PolyUserServ = {};
6 8  
7   -noms.readPasswd = function (login, cb) {
  9 +PolyUserServ.readPasswd = function (login, cb) {
8 10 passwdF = 'config/passwd';
9 11 fs.exists(passwdF, function (exists) {
10 12 found = false;
... ... @@ -39,7 +41,7 @@ noms.readPasswd = function (login, cb) {
39 41 });
40 42 };
41 43  
42   -noms.readGroup = function (gid, cb) {
  44 +PolyUserServ.readGroup = function (gid, cb) {
43 45 groupF = 'config/group';
44 46 fs.exists(groupF, function (exists) {
45 47 found = false;
... ... @@ -71,59 +73,112 @@ noms.readGroup = function (gid, cb) {
71 73 });
72 74 };
73 75  
74   -noms.get = function (login, cb) {
75   - NomsModl.findOne({
76   - login: login
77   - }, {
78   - nom: 1,
79   - section: 1,
80   - _id: 0
81   - }, function (err, nom) {
82   - if (nom && !err && nom.nom && nom.section) {
83   - cb(nom);
84   - } else {
85   - noms.readPasswd(login, function (passwd) {
86   - if (passwd) {
87   - noms.readGroup(passwd.GID, function (group) {
88   - if (group) {
89   - cb({
90   - nom: passwd.GECOS,
91   - section: group.name.toUpperCase()
92   - });
93   - NomsModl.create({
94   - login: login,
95   - nom: passwd.GECOS,
96   - section: group.name.toUpperCase()
97   - });
98   - } else {
99   - if (group === undefined) {
100   - console.error("Impossible d'ouvrir le fichier des groupes.");
101   - } else {
102   - console.error("Impossible d'obtenir le groupe de " + passwd.GID + ".");
103   - }
104   - cb({
105   - nom: passwd.GECOS,
106   - section: passwd.GID
107   - });
108   - }
  76 +PolyUserServ.grabInfos = function (login, cb) {
  77 + PolyUserServ.readPasswd(login, function (passwd) {
  78 + if (passwd) {
  79 + PolyUserServ.readGroup(passwd.GID, function (group) {
  80 + if (group) {
  81 + cb({
  82 + nom: passwd.GECOS,
  83 + section: group.name.toUpperCase()
  84 + });
  85 + PolyUserModl.create({
  86 + login: login,
  87 + nom: passwd.GECOS,
  88 + section: group.name.toUpperCase()
109 89 });
110 90 } else {
111   - if (passwd === undefined) {
112   - console.error("Impossible d'ouvrir le fichier des noms.");
  91 + if (group === undefined) {
  92 + console.error("Impossible d'ouvrir le fichier des groupes.");
113 93 } else {
114   - console.error("Impossible d'obtenir le nom de " + login + ".");
115   - }
116   - if (!login) {
117   - login = 'Inconnu';
  94 + console.error("Impossible d'obtenir le groupe de " + passwd.GID + ".");
118 95 }
119 96 cb({
120   - nom: login.toUpperCase(),
121   - section: 'Inconnue'
  97 + nom: passwd.GECOS,
  98 + section: passwd.GID
122 99 });
123 100 }
124 101 });
  102 + } else {
  103 + if (passwd === undefined) {
  104 + console.error("Impossible d'ouvrir le fichier des noms.");
  105 + } else {
  106 + console.error("Impossible d'obtenir le nom de " + login + ".");
  107 + }
  108 + if (!login) {
  109 + login = 'Inconnu';
  110 + }
  111 + cb({
  112 + nom: login.toUpperCase(),
  113 + section: 'Inconnue'
  114 + });
  115 + }
  116 + });
  117 +};
  118 +
  119 +PolyUserServ.addData = function (polyuser, cb) {
  120 + cb(null, polyuser);
  121 +};
  122 +
  123 +PolyUserServ.obtain = function (login, cb) {
  124 + PolyUserModl.findOne({
  125 + login: login
  126 + }, {
  127 + nom: 1,
  128 + section: 1,
  129 + _id: 0
  130 + }, function (err, polyuser) {
  131 + if (err) {
  132 + cb(err);
  133 + } else {
  134 + PolyUserServ.addData(polyuser, cb);
  135 + }
  136 + });
  137 +};
  138 +
  139 +PolyUserServ.add = function (login, cb) {
  140 + PolyUserServ.grabInfos(login, function (data) {
  141 + data.login = login;
  142 + PolyUserModl.create(data, function (err, polyuser) {
  143 + PolyUserServ.obtain(login, cb);
  144 + });
  145 + });
  146 +};
  147 +
  148 +// PolyUserServ.remove = function (login, cb) {
  149 +// PolyUserModl.remove({
  150 +// login: login
  151 +// }, cb);
  152 +// };
  153 +
  154 +PolyUserServ.get = function (login, cb) {
  155 + PolyUserModl.findOne({
  156 + login: login
  157 + }, function (err, polyuser) {
  158 + if (polyuser && !err && polyuser.polyuser && polyuser.section) {
  159 + PolyUserServ.obtain(login, cb);
  160 + } else {
  161 + PolyUserServ.add(login, cb);
  162 + }
  163 + });
  164 +};
  165 +
  166 +PolyUserServ.verify = function (login, pass, cb) {
  167 + var conn = new Client();
  168 + conn.on('ready', function () {
  169 + cb(null, true);
  170 + }).on('error', function (err) {
  171 + if (err.level === 'client-authentication') {
  172 + cb(null, false);
  173 + } else {
  174 + cb(err);
125 175 }
  176 + }).connect({
  177 + host: creds.host,
  178 + port: creds.port,
  179 + username: login,
  180 + password: pass
126 181 });
127 182 };
128 183  
129   -module.exports = noms;
  184 +module.exports = PolyUserServ;
... ...
app/services/SessionsServ.js
1 1 var SessionModl = require('../models/SessionModl');
2   -var NomsServ = require('../services/NomsServ');
  2 +var PolyUserServ = require('../services/PolyUserServ');
3 3 var MembresServ = require('../services/MembresServ');
4   -var SshAuthServ = require('../services/SshAuthServ');
5 4  
6 5 var sessions = {};
7 6  
8 7 sessions.cur = false;
9 8  
10 9 sessions.addData = function (session, cb) {
11   - NomsServ.get(session.login, function (nom) {
  10 + PolyUserServ.get(session.login, function (err, nom) {
12 11 // Nom
13 12 session.nom = nom.nom;
14 13 session.section = nom.section;
... ... @@ -87,7 +86,7 @@ sessions.create = function (login, cb) {
87 86 };
88 87  
89 88 sessions.login = function (data, cb) {
90   - SshAuthServ.verify(data.login, data.pass, cb);
  89 + PolyUserServ.verify(data.login, data.pass, cb);
91 90 };
92 91  
93 92 sessions.open = function (data, cb) {
... ...
app/services/SshAuthServ.js deleted
... ... @@ -1,25 +0,0 @@
1   -var Client = require('ssh2').Client;
2   -
3   -var creds = require('../../config/sshAuth');
4   -
5   -var SshAuth = {};
6   -
7   -SshAuth.verify = function (login, pass, cb) {
8   - var conn = new Client();
9   - conn.on('ready', function () {
10   - cb(null, true);
11   - }).on('error', function(err) {
12   - if (err.level === 'client-authentication') {
13   - cb(null, false);
14   - } else {
15   - cb(err);
16   - }
17   - }).connect({
18   - host: creds.host,
19   - port: creds.port,
20   - username: login,
21   - password: pass
22   - });
23   -};
24   -
25   -module.exports = SshAuth;
package.json
1 1 {
2   - "name": "ci-site",
3   - "main": "server.js",
4   - "repository": "https://github.com/ClubInfoPolytechLille/ci-site",
5   - "dependencies": {
6   - "async": "^0.9.0",
7   - "body-parser": "^1.12.2",
8   - "cookie-parser": "^1.3.4",
9   - "express": "^4.12.3",
10   - "mongoose": "^4.0.1",
11   - "node-line-reader": "0.0.2",
12   - "ssh2": "^0.4.6",
13   - "ursa": "^0.8.4"
14   - }
  2 + "name": "ci-site",
  3 + "main": "server.js",
  4 + "repository": "https://github.com/ClubInfoPolytechLille/ci-site",
  5 + "dependencies": {
  6 + "async": "^0.9.0",
  7 + "body-parser": "^1.12.2",
  8 + "cookie-parser": "^1.3.4",
  9 + "express": "^4.12.3",
  10 + "express-http-proxy": "^0.5.0",
  11 + "mongoose": "^4.0.1",
  12 + "node-line-reader": "0.0.2",
  13 + "ssh2": "^0.4.6",
  14 + "ursa": "^0.8.4"
  15 + }
15 16 }
... ...