Commit cd0b1552 authored by Paul-Elliot Anglès d'Auriac's avatar Paul-Elliot Anglès d'Auriac
Browse files

Merge branch 'master' into accountView

parents b5aff1b5 8feae373
...@@ -12,6 +12,9 @@ Presque fait, il manque juste une harmonisation des noms... (getBy/FromID, setGe ...@@ -12,6 +12,9 @@ Presque fait, il manque juste une harmonisation des noms... (getBy/FromID, setGe
** DONE Sécurité redirection user/admin/non loggé ** DONE Sécurité redirection user/admin/non loggé
CLOSED: [2018-08-20 lun. 18:16] CLOSED: [2018-08-20 lun. 18:16]
** DONE Virer tous les logs inutiles
CLOSED: [2018-09-12 mer. 13:25]
** TODO Proprifier le hack de questionController
* Court terme * Court terme
...@@ -74,9 +77,38 @@ Au final je n'ai pas utilisé flex ...@@ -74,9 +77,38 @@ Au final je n'ai pas utilisé flex
** TODO Tester le tout ** TODO Tester le tout
** TODO voir pour le problème de timers.enroll deprecated (express-session-mysql est bloqué sur mysql v2.15, on peut manuellement l'upgrader en v2.16)
** TODO Randomiser l'affichage des réponses ** TODO Randomiser l'affichage des réponses
Fait (mais commenté) modulo le fait que ça se passe du coté client...
** DONE faire les routes GET de delete, update, etc...
CLOSED: [2018-09-12 mer. 22:26]
** DONE Refaire l'interface d'ajout d'une question
CLOSED: [2018-09-13 jeu. 23:22]
** TODO Vérifier les RESTRICT/CASCADE pour la bdd (dans le fichier)
** TODO Réfléchir à ce qui est le mieux pour indexSet et currentQuestion...
** TODO Empecher les noms vides
** DONE style css pour souligner dans quelle page nous sommes dans le menu...
CLOSED: [2018-09-19 mer. 14:31]
** TODO mettre configuration.js en configuration.js.example et mettre à jour le README en accord avec cela
* BUGs
** DONE Lors d'une reconnexion, on recrée un nouvelle réponse au lieu d'updater la précédente...
CLOSED: [2018-09-19 mer. 00:17]
** DONE Bug game.questionFromRoom is not a function
CLOSED: [2018-09-17 lun. 14:16]
/home/panglesd/class-panic/controllers/sockets.js:111
game.questionFromRoom(socket.room, function (question) {
^
TypeError: game.questionFromRoom is not a function
at Socket.<anonymous> (/home/panglesd/class-panic/controllers/sockets.js:111:11)
at Socket.emit (events.js:182:13)
at /home/panglesd/class-panic/node_modules/socket.io/lib/socket.js:528:12
at process._tickCallback (internal/process/next_tick.js:61:11)
[nodemon] app crashed - waiting for file changes before starting...
* Long terme * Long terme
......
...@@ -13,7 +13,7 @@ exports.room_enter = function(req, res) { ...@@ -13,7 +13,7 @@ exports.room_enter = function(req, res) {
server : function(callback) { server : function(callback) {
callback(null, req.protocol + '://' + req.get('host') ); callback(null, req.protocol + '://' + req.get('host') );
}, },
config : function(callback) { console.log(config); callback(null, config) }, config : function(callback) { /*console.log(config);*/ callback(null, config) },
room : function (callback) { room : function (callback) {
Room.getByID(req.params.id, callback) Room.getByID(req.params.id, callback)
} }
......
...@@ -12,7 +12,7 @@ exports.login_get = function(req, res) { ...@@ -12,7 +12,7 @@ exports.login_get = function(req, res) {
if(req.session.user){ if(req.session.user){
res.redirect(config.PATH+"/room"); res.redirect(config.PATH+"/room");
} }
res.render('login', {config: config}); res.render('login', {config: config, msgs: []});
}; };
// Afficher la page d'inscription // Afficher la page d'inscription
...@@ -21,14 +21,15 @@ exports.sign_in_get = function(req, res) { ...@@ -21,14 +21,15 @@ exports.sign_in_get = function(req, res) {
if(req.session.user){ if(req.session.user){
res.redirect(config.PATH+"/room"); res.redirect(config.PATH+"/room");
} }
res.render('signin', {config: config}); res.render('signin', {config: config, msgs: []});
}; };
// Se délogger // Se délogger
exports.logout = function(req, res) { exports.logout = function(req, res) {
req.session.user = null; req.session.user = null;
exports.login_get(req, res); // exports.login_get(req, res);
res.redirect(config.PATH+"/login");
}; };
/*************************************************************/ /*************************************************************/
...@@ -38,22 +39,24 @@ exports.logout = function(req, res) { ...@@ -38,22 +39,24 @@ exports.logout = function(req, res) {
// Créer un utilisateur // Créer un utilisateur
exports.user_create_post = function(req, res) { exports.user_create_post = function(req, res) {
Users.create(req.body, function () { Users.create(req.body, function (err, rows) {
res.redirect(config.PATH) if(err) {
// console.log(err);
res.render('signin', {config: config, msgs: ["Impossible de créer votre compte : sans doute le pseudo est-il déjà utilisé."]});
}
else {
res.redirect(config.PATH)
}
}); });
}; };
// Se logger // Se logger
exports.login_post = function(req, res) { exports.login_post = function(req, res) {
console.log("A");
Users.userCheck(req.body.login, req.body.password, function (err, user) { Users.userCheck(req.body.login, req.body.password, function (err, user) {
console.log("F");
console.log('user is ', user);
if (!user) if (!user)
res.redirect(config.PATH); res.render('login', {config: config, msgs: ["Connexion impossible, vérifiez vos identifiants"]});
else { else {
console.log("user = user");
req.session.user=user; req.session.user=user;
res.redirect(config.PATH+"/room"); res.redirect(config.PATH+"/room");
} }
......
var User = require('../models/user'); var User = require('../models/user');
var Room = require('../models/room'); var Room = require('../models/room');
var Set = require('../models/set'); var Set = require('../models/set');
var SetController = require('./setController');
var Question = require('../models/question'); var Question = require('../models/question');
var config = require("./../configuration"); var config = require("./../configuration");
var async = require('async'); var async = require('async');
/*************************************************************/ /*************************************************************/
/* Controlleurs GET pour les questions */ /* Fonctions render pour les questions */
/*************************************************************/ /*************************************************************/
// Afficher la liste des questions // render de manage_question.ejs
exports.question_list = function(req, res) {
async.parallel(
{
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
config: function(callback) { callback(null, config) },
user: function (callback) {
callback(null, req.session.user);
},
questionList: function (callback) {
Question.listOwnedFromSetId(req.params.setId,function (e,b) {callback(e,b)});
},
set: function (callback) {
Set.setOwnedGet(req.session.user, req.params.setId, callback);
},
title: function(callback) { callback(null, "Class Panic: Modification d'un set")}
},
function (err, results) {
console.log(results.questionList);
res.render('questions', results)
});
};
// Afficher le détails d'une question
exports.questionShow = function(req, res) { renderManageQuestion = function(user, questionID, setID, msgs, res) {
async.parallel( async.parallel(
{ {
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")}, title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
config: function(callback) { callback(null, config) }, config: function(callback) { callback(null, config) },
user: function (callback) { user: function (callback) {
callback(null, req.session.user); callback(null, user);
}, },
newQuestion: function(callback) { callback(null, typeof questionID == "undefined")},
question: function (callback) { question: function (callback) {
Question.getOwnedByID(req.params.questionId,function (e,b) {callback(e,b)}); if(typeof questionID != "undefined")
Question.getOwnedByID(user, questionID, function (e,b) {callback(e,b)});
else
callback(null,
{
reponses : [{
reponse: "",
validity: false
}],
enonce: ""
})
}, },
title: function(callback) { callback(null, "Class Panic: Modification d'un set")}, title: function(callback) { callback(null, "Class Panic: Modification d'un set")},
set: function (callback) { set: function (callback) {
Set.setOwnedGet(req.session.user, req.params.setId, callback); Set.setOwnedGet(user, setID, function(a,b) {callback(a,b)});
} }
}, },
function (err, results) { function (err, results) {
console.log(results.questionList); // console.log(results);
res.render('questioqzdn', results) res.render('manage_question', results)
}); });
}; };
/*************************************************************/
/* Controlleurs GET pour les questions */
/*************************************************************/
// Pour commencer à créer une question // Pour commencer à créer une question
exports.question_create_get = function(req, res) { exports.question_create_get = function(req, res) {
tmp = {}; renderManageQuestion(req.session.user, undefined, req.params.idSet, [], res);
Set.setOwnedGet(req.session.user, req.params.idSet, function(err, r) {
options = {
title: "ClassPanic : créer une nouvelle question",
user: req.session.user,
config: config,
newQuestion: true,
question: {
reponses : [{
reponse: "",
validity: false
}],
enonce: ""
},
set : r
};
res.render('manage_question', options);
});
}; };
// Pour commencer à modifier une question // Pour commencer à modifier une question
exports.question_update_get = function(req, res) { exports.question_update_get = function(req, res) {
async.parallel( renderManageQuestion(req.session.user, req.params.id, req.params.idSet, [], res);
{
title: function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
config: function(callback) { callback(null, config) },
user: function (callback) {
callback(null, req.session.user);
},
question: function (callback) {
Question.getOwnedByID(req.session.user, req.params.id,function (e,b) {callback(e,b)});
},
newQuestion: function (callback) { callback(null, false) },
title: function(callback) { callback(null, "Class Panic: Modification d'un set")},
set: function (callback) {
Set.setOwnedGet(req.session.user, req.params.idSet, callback);
}
},
function (err, results) {
res.render('manage_question', results)
});
}; };
...@@ -113,19 +70,39 @@ exports.question_update_get = function(req, res) { ...@@ -113,19 +70,39 @@ exports.question_update_get = function(req, res) {
// Create // Create
exports.question_create_post = function(req, res) { exports.question_create_post = function(req, res) {
Question.questionCreate(req.session.user, req.body, {id:req.params.idSet}, function(err, id) { res.redirect(config.PATH+"/manage/set/"+req.params.idSet) ; }); Question.questionCreate(req.session.user, req.body, req.params.idSet, function(err, info) {
// res.redirect(config.PATH+"/manage/set/"+req.params.idSet) ;
req.params.id = req.params.idSet; // HORRIBLE HACK
if(err)
SetController.set_manage_msgs(req, res, ["Impossible d'ajouter la question !"]);
else
SetController.set_manage_msgs(req, res, ["Question ajoutée !"]);
});
}; };
// Update // Update
exports.question_update_post = function(req, res) { exports.question_update_post = function(req, res) {
Question.questionUpdate(req.session.user, req.params, req.body, function() { Question.questionUpdate(req.session.user, req.params, req.body, function(err, info) {
res.redirect(config.PATH+"/manage/set/"+req.params.idSet); // res.redirect(config.PATH+"/manage/set/"+req.params.idSet);
req.params.id = req.params.idSet; // HORRIBLE HACK
if(err)
SetController.set_manage_msgs(req, res, ["Impossible de mettre à jour la question !"]);
else
SetController.set_manage_msgs(req, res, ["Question mise à jour !"]);
}); });
}; };
// Delete // Delete
exports.question_delete_post = function(req, res) { exports.question_delete_post = function(req, res) {
Question.questionDelete(req.session.user, req.params, function(err, id) { res.redirect(config.PATH+"/manage/set/"+req.params.idSet) ; }); Question.questionDelete(req.session.user, parseInt(req.params.id), function(err, id) {
// console.log(err);
req.params.id = req.params.idSet; // HORRIBLE HACK
if(err)
SetController.set_manage_msgs(req, res, ["Impossible de supprimer la question (peut-être est-elle la question courante d'une room) !"]);
else
SetController.set_manage_msgs(req, res, ["Question supprimée !"]);
// res.redirect(config.PATH+"/manage/set/"+req.params.idSet);
});
}; };
...@@ -4,97 +4,84 @@ var Set = require('../models/set'); ...@@ -4,97 +4,84 @@ var Set = require('../models/set');
var config = require('../configuration'); var config = require('../configuration');
var async = require('async'); var async = require('async');
/*************************************************************/ /*************************************************************/
/* Controlleurs GET pour les rooms */ /* Fonctions render pour les rooms */
/*************************************************************/ /*************************************************************/
// Afficher la liste des rooms afin d'y participer // Render rooms.ejs
exports.room_list = function(req, res) { renderRooms = function(user, msgs, res) {
async.parallel( async.parallel(
{ {
title : function(callback) { callback(null, "ClassPanic: Rejoindre une salle")}, title : function(callback) { callback(null, "ClassPanic: Rejoindre une salle")},
config : function(callback) { callback(null, config) }, config : function(callback) { callback(null, config) },
user : function (callback) { user : function (callback) {
callback(null, req.session.user); callback(null, user);
}, },
roomList : function (callback) { msgs : function(callback) {
Room.list(callback); callback(null, msgs);
}
},
function (err, results) {
res.render('rooms', results)
});
};
// A supprimer si ça ne sert bien à rien
/*exports.room_admin_all = function(req, res) {
async.parallel(
{
title : function(callback) { callback(null, "ClassPanic: Administrer une salle")},
user : function (callback) {
callback(null, req.session.user);
}, },
roomList : function (callback) { roomList : function (callback) {
Room.list(callback); Room.list(callback);
},
roomOwnedList : function (callback) {
Room.ownedList(req.session.user, function (r) { callback(null, r) });
},
setOwnedList : function (callback) {
Set.setOwnedList(req.session.user, callback);
} }
}, },
function (err, results) { function (err, results) {
res.render('admin_rooms', results) // console.log(results);
res.render('rooms', results)
}); });
};*/ }
// Afficher le détails d'une room pour la modifier // Render manage_room.ejs
exports.room_manage = function (req, res) { // renderRoomManage = function (req, res, msgs) {
Room.getOwnedByID(req.session.user, req.params.id, function (err, thisRoom) { renderRoomManage = function (user, roomID, msgs, res) {
Room.getOwnedByID(user, roomID, function (err, thisRoom) {
async.parallel( async.parallel(
{ {
title : function(callback) { callback(null, "ClassPanic: Administrer "+thisRoom.name)}, title : function(callback) { callback(null, "ClassPanic: Administrer "+thisRoom.name)},
config : function(callback) { callback(null, config) }, config : function(callback) { callback(null, config) },
user : function (callback) { user : function (callback) {
callback(null, req.session.user); callback(null, user);
}, },
room : function (callback) { room : function (callback) {
callback(null, thisRoom); callback(null, thisRoom);
}, },
msgs : function(callback) {
callback(null, msgs);
},
setOwnedList : function (callback) { setOwnedList : function (callback) {
Set.setOwnedList(req.session.user, callback); Set.setOwnedList(user, callback);
} }
}, },
function (err, results) { function (err, results) {
console.log(results);
res.render('manage_room', results); res.render('manage_room', results);
}); });
}); });
}; };
// Afficher la liste des rooms afin de les manager // Render manage_rooms.ejs
exports.room_manage_all = function(req, res) { renderManageRooms = function(user, msgs, res) {
async.parallel( async.parallel(
{ {
title : function(callback) { callback(null, "ClassPanic: ... une salle")}, title : function(callback) { callback(null, "ClassPanic: ... une salle")},
config : function(callback) { callback(null, config) }, config : function(callback) { callback(null, config) },
user : function (callback) { user : function (callback) {
callback(null, req.session.user); callback(null, user);
}, },
roomList : function (callback) { roomList : function (callback) {
Room.list(callback); Room.list(callback);
}, },
msgs : function(callback) {
callback(null, msgs);
},
roomOwnedList : function (callback) { roomOwnedList : function (callback) {
Room.ownedList(req.session.user, function (r) { callback(null, r) }); Room.ownedList(user, callback);
}, },
setOwnedList : function (callback) { setOwnedList : function (callback) {
Set.setOwnedList(req.session.user, callback); Set.setOwnedList(user, callback);
} }
}, },
function (err, results) { function (err, results) {
...@@ -102,6 +89,29 @@ exports.room_manage_all = function(req, res) { ...@@ -102,6 +89,29 @@ exports.room_manage_all = function(req, res) {
}); });
}; };
/*************************************************************/
/* Controlleurs GET pour les rooms */
/*************************************************************/
// Afficher la liste des rooms afin d'y participer
exports.room_list = function(req, res) {
renderRooms(req.session.user, [], res);
};
// Afficher le détails d'une room pour la modifier
exports.room_manage = function (req, res) {
renderRoomManage(req.session.user, req.params.id, [], res);
};
// Afficher la liste des rooms afin de les manager
exports.room_manage_all = function(req, res) {
renderManageRooms(req.session.user, [], res);
};
/*************************************************************/ /*************************************************************/
/* Controlleurs POST pour modifier les rooms */ /* Controlleurs POST pour modifier les rooms */
...@@ -111,20 +121,30 @@ exports.room_manage_all = function(req, res) { ...@@ -111,20 +121,30 @@ exports.room_manage_all = function(req, res) {
exports.room_create_post = function(req, res) { exports.room_create_post = function(req, res) {
if(req.body.questionSet) { if(req.body.questionSet) {
Room.create(req.session.user, req.body, function (err) { Room.create(req.session.user, req.body, function (err,r) {
res.redirect(config.PATH+'/manage/room'); // res.redirect(config.PATH+'/manage/room');
// console.log(req.body);
if(err)
renderManageRooms(req.session.user, ["Impossible de créer la room !"], res);
else
renderManageRooms(req.session.user, ["Room créée !"], res);
}); });
} }
<