From 415311de9b66607668eff472847cd947cbe93ff6 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Thu, 23 May 2013 13:41:35 +0200 Subject: added loadProject to Access so that all project participants are loading. also fixed error validation --- controllers/system.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/controllers/system.js b/controllers/system.js index a3d5a60..d37a252 100644 --- a/controllers/system.js +++ b/controllers/system.js @@ -122,8 +122,10 @@ exports.dashboard = function(req, res) { exports.project = function(req, res) { Project.loadShort(req.params.short, function(err, project) { if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack }); - - res.render('project', { title: 'Harepus', user: req.user, req: req, project: project }); + Access.loadProject(project._id, function(err, access) { + if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack }); + res.render('project', { title: project.name, user: req.user, req: req, project: project, access: access }); + }); }); } @@ -154,15 +156,15 @@ exports.projectPost = function(req, res) { exports.postProjectPost = function(req, res) { // Validation - v.check('project', 'The project was lost').notEmpty(); - v.check('what', 'You need to fill in the what-field').notEmpty(); - v.check('value', 'The value must be a positive number').notEmpty().isInt().min(0); + v.check(req.body.project, 'The project was lost').notEmpty(); + v.check(req.body.what, 'You need to fill in the what-field').notEmpty(); + v.check(req.body.value, 'The value must be a positive number').notEmpty().isInt().min(0); // error when validation fails var errors = v.getErrors(); - if (errors.length !== 0) return res.status(500).render('error', { title: '500', text: 'Det oppstod en valideringsfeil', error: errors.stack }); + if (errors.length !== 0) return res.status(500).render('error', { title: '500', text: 'Det oppstod en valideringsfeil ' + errors, error: errors }); - Project.load(req.sanitize('project').escape(), function(err, project) { + Project.load(sanitize(req.body.project).escape(), function(err, project) { if (err) return res.status(500).render('error', { title: '500', text: 'En serverfeil oppstod', error: err.stack }); // check if access -- cgit v1.2.3