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
** DONE Sécurité redirection user/admin/non loggé
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
......@@ -74,9 +77,38 @@ Au final je n'ai pas utilisé flex
** 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
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
......
......@@ -13,7 +13,7 @@ exports.room_enter = function(req, res) {
server : function(callback) {
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.getByID(req.params.id, callback)
}
......
......@@ -12,7 +12,7 @@ exports.login_get = function(req, res) {
if(req.session.user){
res.redirect(config.PATH+"/room");
}
res.render('login', {config: config});
res.render('login', {config: config, msgs: []});
};
// Afficher la page d'inscription
......@@ -21,14 +21,15 @@ exports.sign_in_get = function(req, res) {
if(req.session.user){
res.redirect(config.PATH+"/room");
}
res.render('signin', {config: config});
res.render('signin', {config: config, msgs: []});
};
// Se délogger
exports.logout = function(req, res) {
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) {
// Créer un utilisateur
exports.user_create_post = function(req, res) {
Users.create(req.body, function () {
Users.create(req.body, function (err, rows) {
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
exports.login_post = function(req, res) {
console.log("A");
Users.userCheck(req.body.login, req.body.password, function (err, user) {
console.log("F");
console.log('user is ', user);
if (!user)
res.redirect(config.PATH);
res.render('login', {config: config, msgs: ["Connexion impossible, vérifiez vos identifiants"]});
else {
console.log("user = user");
req.session.user=user;
res.redirect(config.PATH+"/room");
}
......
var User = require('../models/user');
var Room = require('../models/room');
var Set = require('../models/set');
var SetController = require('./setController');
var Question = require('../models/question');
var config = require("./../configuration");
var async = require('async');
/*************************************************************/
/* Controlleurs GET pour les questions */
/* Fonctions render pour les questions */
/*************************************************************/
// Afficher la liste des questions
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
// render de manage_question.ejs
exports.questionShow = function(req, res) {
renderManageQuestion = function(user, questionID, setID, msgs, 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);
callback(null, user);
},
newQuestion: function(callback) { callback(null, typeof questionID == "undefined")},
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")},
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) {
console.log(results.questionList);
res.render('questioqzdn', results)
// console.log(results);
res.render('manage_question', results)
});
};
/*************************************************************/
/* Controlleurs GET pour les questions */
/*************************************************************/
// Pour commencer à créer une question
exports.question_create_get = function(req, res) {
tmp = {};
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);
});
renderManageQuestion(req.session.user, undefined, req.params.idSet, [], res);
};
// Pour commencer à modifier une question
exports.question_update_get = 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);
},
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)
});
renderManageQuestion(req.session.user, req.params.id, req.params.idSet, [], res);
};
......@@ -113,19 +70,39 @@ exports.question_update_get = function(req, res) {
// Create
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
exports.question_update_post = function(req, res) {
Question.questionUpdate(req.session.user, req.params, req.body, function() {
res.redirect(config.PATH+"/manage/set/"+req.params.idSet);
Question.questionUpdate(req.session.user, req.params, req.body, 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 de mettre à jour la question !"]);
else
SetController.set_manage_msgs(req, res, ["Question mise à jour !"]);
});
};
// Delete
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');
var config = require('../configuration');
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(
{
title : function(callback) { callback(null, "ClassPanic: Rejoindre une salle")},
config : function(callback) { callback(null, config) },
user : function (callback) {
callback(null, req.session.user);
callback(null, user);
},
roomList : function (callback) {
Room.list(callback);
}
},
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);
msgs : function(callback) {
callback(null, msgs);
},
roomList : function (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) {
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) {
Room.getOwnedByID(req.session.user, req.params.id, function (err, thisRoom) {
// renderRoomManage = function (req, res, msgs) {
renderRoomManage = function (user, roomID, msgs, res) {
Room.getOwnedByID(user, roomID, function (err, thisRoom) {
async.parallel(
{
title : function(callback) { callback(null, "ClassPanic: Administrer "+thisRoom.name)},
config : function(callback) { callback(null, config) },
user : function (callback) {
callback(null, req.session.user);
callback(null, user);
},
room : function (callback) {
callback(null, thisRoom);
},
msgs : function(callback) {
callback(null, msgs);
},
setOwnedList : function (callback) {
Set.setOwnedList(req.session.user, callback);
Set.setOwnedList(user, callback);
}
},
function (err, results) {
console.log(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(
{
title : function(callback) { callback(null, "ClassPanic: ... une salle")},
config : function(callback) { callback(null, config) },
user : function (callback) {
callback(null, req.session.user);
callback(null, user);
},
roomList : function (callback) {
Room.list(callback);
},
msgs : function(callback) {
callback(null, msgs);
},
roomOwnedList : function (callback) {
Room.ownedList(req.session.user, function (r) { callback(null, r) });
Room.ownedList(user, callback);
},
setOwnedList : function (callback) {
Set.setOwnedList(req.session.user, callback);
Set.setOwnedList(user, callback);
}
},
function (err, results) {
......@@ -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 */
......@@ -111,20 +121,30 @@ exports.room_manage_all = function(req, res) {
exports.room_create_post = function(req, res) {
if(req.body.questionSet) {
Room.create(req.session.user, req.body, function (err) {
res.redirect(config.PATH+'/manage/room');
Room.create(req.session.user, req.body, function (err,r) {
// 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);
});
}
else {
res.redirect(config.PATH+'/manage/room');
renderManageRooms(req.session.user, ["Impossible de créer la room : merci de spécifier un set valide à associer"], res);
// res.redirect(config.PATH+'/manage/room');
}
};
//Delete
exports.room_delete_post = function(req, res) {
Room.delete(req.session.user, req.params.id, function () {
res.redirect(config.PATH+"/manage/room");
Room.delete(req.session.user, req.params.id, function (err, info) {
if(err)
renderManageRooms(req.session.user, ["Impossible de supprimer la room"], res);
else
renderManageRooms(req.session.user, ["Room supprimée"], res);
// res.redirect(config.PATH+"/manage/room");
});
};
......@@ -132,6 +152,10 @@ exports.room_delete_post = function(req, res) {
exports.room_update_post = function(req, res) {
Room.update(req.session.user, req.params, req.body, function (id) {
res.redirect(config.PATH+'/manage/room/');
if(err)
renderRoomManage(req.session.user, req.params.id, ["Impossible de modifier la room"], res);
else
renderRoomManage(req.session.user, req.params.id, ["Room updaté"], res);
// res.redirect(config.PATH+'/manage/room/');
});
};
......@@ -7,34 +7,35 @@ var config = require("./../configuration");
var async = require('async');
/*************************************************************/
/* Controlleurs GET pour les sets */
/* Fonctions render pour les sets */
/*************************************************************/
// Afficher la liste des sets
// render pour manage_sets.ejs
exports.set_manage_all = function(req, res) {
// res.send('NOT IMPLEMENTED: Room list');
renderManageSets = function(user, msgs, 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);
callback(null, user);
},
msgs: function(callback) {
callback(null, msgs)
},
setOwnedList : function (callback) {
Set.setOwnedList(req.session.user, callback);
Set.setOwnedList(user, callback);
}
},
function (err, results) {
console.log(results);
// console.log(results);
res.render('manage_sets', results)
});
};
// Afficher le détails d'un set
// render pour managet_set.ejs
exports.set_manage = function(req, res) {
// res.send('NOT IMPLEMENTED: Room list');
renderManageSet = function(req, user, setID, msgs, res) {
async.parallel(
{
title : function(callback) { callback(null, "ClassPanic: Gérer vos sets de questions")},
......@@ -43,21 +44,43 @@ exports.set_manage = function(req, res) {
},
config : function(callback) { callback(null, config) },
user : function (callback) {
callback(null, req.session.user);
callback(null, user);
},
questionList : function (callback) {
Question.listOwnedBySetID(req.session.user, req.params.id,function (e,b) {callback(e,b)});
Question.listOwnedBySetID(user, setID, function(a,b) {callback(a,b)});
},
msgs: function(callback) { callback(null, msgs) },
set : function (callback) {
Set.setOwnedGet(req.session.user, req.params.id, callback);
Set.setOwnedGet(user, setID, callback);
}
},
function (err, results) {
console.log(results);
res.render('manage_set', results)
});
};
/*************************************************************/
/* Controlleurs GET pour les sets */
/*************************************************************/
// Afficher la liste des sets
exports.set_manage_all = function(req, res) {
renderManageSets(req.session.user, [], res);
};
exports.set_manage_all_msgs = function(req, res, msgs) {
renderManageSets(req.session.user, msgs, res);
};
// Afficher le détails d'un set
exports.set_manage = function(req, res) {
renderManageSet(req, req.session.user, req.params.id, [], res);
};
exports.set_manage_msgs = function(req, res, msgs) {
renderManageSet(req, req.session.user, req.params.id, msgs, res);
};
/*************************************************************/
/* Controlleurs POST pour modifier les sets */
/*************************************************************/
......@@ -66,7 +89,10 @@ exports.set_manage = function(req, res) {
exports.set_create_post = function(req, res) {
Set.setCreate(req.session.user, req.body, function (err, set) {