diff --git a/:q b/:q deleted file mode 100644 index 26dbd5a..0000000 --- a/:q +++ /dev/null @@ -1,170 +0,0 @@ -function Service(app) { - var Evaluacion = app.db.model('Evaluacion'); - var Taller= app.db.model('Taller'); - var TallerBase= app.db.model('TallerBase'); - var Participante = app.db.model('Participante'); - var Creativo = app.db.model('Creativo'); - - function getEvaluaciones(req, res, next) { - var query = (function() { - if (req.params.id) { - return { _id: req.params.id } - } - return {}; - })(); - - // Find by Id - if (query._id) { - Evaluacion.findOne(query, function(err, r) { - req.evaluacion = r; - next(); - }); - } - // Find by All - else { - Evaluacion.find(query, function(err, records) { - req.evaluaciones = records; - next(); - }); - } - } - - function postEvaluaciones(req, res, next) { - var data = req.body; - console.log(data); - var model = new Evaluacion(); - model.participante_id = data[p_id]; - model.creativo_id = data[creativo_id] - model.fecha = data.fecha; - model.taller_id = data.taller_id; - var habilidades_cnt = app.params.habilidades.length; - model.habilidades = new Array(habilidades_cnt); - model.valores = new Array(habilidades_cnt); - var cnt = 0; - for (var key in data) { - console.log("++++++++++++"); - console.log(key); - console.log(key.substring(0,2)); - if (key.substring(0,2) == 'i_') { - console.log("-----------+"); - var obj = data[key]; - var hab = key.substring(2); - model.habilidades[cnt] = hab; - model.valores[cnt] = obj; - cnt++; - } - } - model.save(function(err, r) { - req.evaluacion = r; - next(); - }); - } - - function putEvaluaciones(req, res, next) { - var data = req.body; - var id = req.params.id; - Evaluacion.update({ _id: id }, data, function(err, r) { - if (err) { - res.error = true; - } - next(); - }); - } - - function delEvaluaciones(req, res, next) { - var id = req.params.id; - Evaluacion.findByIdAndRemove(id, function(err, r) { - next(); - }); - } - - /* - * JSON - */ - app.get('/evaluaciones.json', getEvaluaciones, function(req, res) { - res.send(req.evaluaciones); - }); - - app.get('/evaluaciones/:id.json', getEvaluaciones, function(req, res) { - res.send(req.evaluacion); - }); - - app.post('/evaluaciones', postEvaluaciones, function(req, res) { - res.send(req.evaluacion, 201); - }); - - app.put('/evaluaciones/:id', putEvaluaciones, function(req, res) { - if (req.error) res.send({ 'error': true }, 500); - else res.send({ 'ok': true }); - }); - - app.del('/evaluaciones/:id', delEvaluaciones, function(req, res) { - res.send({ 'ok': true }); - }); - - /* - * HTML - */ - app.get('/evaluaciones/new', getEvaluaciones, function(req, res) { - var error_text = ""; - var render_error=function(err, status_code) { - res.render('error', { - locals: { - status: status_code, - error_text: err - } - }); - return; - } - var taller_id = req.query['taller']; - console.log(taller_id); - var participante_id = req.query['p']; - //debug - //var participante_id = "503b0a155531839027000001"; - if (taller_id == null || taller_id == 'undefined') { - render_error("ID taller invalido! Ese taller no fue encontrado.", 404); - return; - } - Taller.findById(taller_id, function(err, taller) { - if (err) { - render_error("No fui capable de econtrar el taller deseado.", 404); - return; - } - console.log(taller); - Creativo.find({email: app.login_email}, function(err, creativo) { - if (err) { - render_error("No fui capaz de encontrar el Creativo relacionado al usuário en sesión",500); - return; - } - console.log(creativo); - Participante.findOne({_id: participante_id}, function(err, participante) { - if (err) { - render_error("No fui capaz de encontrar el participante de la evaluación", 500); - return; - } else { - console.log(participante); - res.render('forms/eval_participante', { - locals: { - params: app.params, - participante: participante, - creativo: creativo[0], - taller: taller, - articulo: 'FormEvaluacion' - } - }); - } - }); - }); - }); - }); - - app.get('/evaluaciones/:id', getEvaluaciones, function(req, res) { - res.render('evaluacion', { - locals: { - evaluacion: req.evaluacion - } - }); - }); -} - -module.exports = Service; diff --git a/domain/Admin.js b/domain/Admin.js index 3d878bf..56dbaa4 100644 --- a/domain/Admin.js +++ b/domain/Admin.js @@ -6,8 +6,6 @@ function Service(app) { var Evaluacion = app.db.model('Evaluacion'); function getCreativos(req, res, next) { - console.log("************"); - console.log(req.query); var query = (function() { if (req.params.id) { return { _id: req.params.id } diff --git a/domain/Evaluaciones.js b/domain/Evaluaciones.js index 94d10be..51569c8 100644 --- a/domain/Evaluaciones.js +++ b/domain/Evaluaciones.js @@ -84,6 +84,7 @@ function Service(app) { console.log(req.params.taller_id); Sesion.findById(req.params.taller_id, function(err, r) { req.sesion = r; + console.log(r); next(); }); } diff --git a/models/models.js b/models/models.js index c0201db..d5eb856 100644 --- a/models/models.js +++ b/models/models.js @@ -102,14 +102,13 @@ var Creativo = new Schema({ email : { type: String }, telefono : { type: String }, direccion : { type: String }, - titulo : { type: String }, - ids_talleres : { type: Array }, + titulo : { type: String } }); mongoose.model('Creativo', Creativo); var Evaluacion = new Schema({ participante_id : { type: String } - , creativo_id : { type: String } + , creativo_cedula : { type: String } , fecha : { type: Date } , taller_id : { type: String, index: true } , habilidades : { type: Array } diff --git a/server.js b/server.js index 303be17..d5b25e3 100644 --- a/server.js +++ b/server.js @@ -16,11 +16,9 @@ everyauth.debug = true; //Intialize authentication with username/password require('./lib/Auth')(app) -everyauth.password - .findUserById( function (id, callback) { - console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%***"); - Usuario.findById(id, callback); - }); +everyauth.everymodule.findUserById(function (id, callback) { + app.db.model('Usuario').findById(id, callback); +}); // Configuration @@ -47,9 +45,12 @@ app.configure(function(){ })); this.use(express.favicon(__dirname + '/public/favicon.ico', { maxAge: 2592000000})); this.use(express.static(__dirname + '/public')); + this.use(everyauth.middleware()); + // Keep this as last one this.use(this.router); + this.use(function(req, res, next){ res.render('error', { status: 404, error_text: '404 Pagina no encontrada en el sistema', url: req.url }); }); @@ -82,28 +83,17 @@ app.get('/login', function(req, res){ }); app.get('*', function(req, res, next) { - if (!req.session.auth) { + var auth = req.session.auth; + + if (!auth || !auth.loggedIn) { res.redirect('/login'); } else { - if (typeof req.session.creativo_id == 'undefined') { - req.session.creativo_id = '71381688'; - } next(); } }); app.get('/', function(req, res) { - if (req.session.user) { - console.log('Session found, redirecting..................'); - res.redirect('/equipamientos'); - } else { - console.log('No session found, rendering index..................'); - res.render('index', { - locals:{ - articulo: 'None' - } - }); - } + res.redirect('/equipamientos'); }); // Initialize Domain