diff options
author | Lurifax <stianalexanderolsen@gmail.com> | 2013-05-01 22:20:18 +0200 |
---|---|---|
committer | Lurifax <stianalexanderolsen@gmail.com> | 2013-05-01 22:20:18 +0200 |
commit | 464d4717ace36646db7636f2ebc7701a921c75dd (patch) | |
tree | 670d7fa67e7633ca818cc5b48e8886fab2d6ab3f /controllers | |
parent | Changes in text (diff) | |
parent | added generateRandomAccessToken method (diff) | |
download | Divid-464d4717ace36646db7636f2ebc7701a921c75dd.tar.gz |
Changes in text in home.ejs
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/system.js | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/controllers/system.js b/controllers/system.js index e3a55bd..a5e8f46 100644 --- a/controllers/system.js +++ b/controllers/system.js @@ -3,9 +3,9 @@ * Module dependencies */ var mongoose = require('mongoose') - , Project = mongoose.model('Project'); - - + , Project = mongoose.model('Project') + , Access = mongoose.model('Access') + , User = mongoose.model('User'); /** @@ -53,12 +53,47 @@ exports.faq = function(req, res) { exports.dashboard = function(req, res) { - console.log('/dashboard - ' + req.user); - res.render('dashboard', { - title: 'kanin', - loggedin: true + console.log('/dashboard - ' + req.user._id); + +/* + Access.find({ user: req.user._id }, function(err, accesses) { + if (err) return res.render('500'); + console.log('accesses ' + accesses); + accesses.forEach(function(access) { + Project.load(access.project, function(err, project) { + if (err) return res.render('500'); + projectList.push(project); + console.log(project.user.username); + }); + }); }); -}; +*/ + Access.loadUser(req.user._id, function(err, projects) { + if (err) return res.render('500'); + Project.populate(projects, { path: 'project.user', model: User }, function(err, projects) { + + console.log('accesses: ' + projects); + + res.render('dashboard', { + title: 'Dashboard', + loggedin: true, + projects: projects + }); + + }); + + }) + +/* + Project.find(function(err, projects) { + if (err) return res.render('500'); + res.render('dashboard', { + title: 'Dashboad', + loggedin: true, + projects: projects + }); + });*/ +} @@ -66,15 +101,44 @@ exports.project = function(req, res) { res.render('project', { title: 'Harepus', loggedin: true }); } +exports.projectParticipants = function(req, res) { + + res.render('projectParticipants', { title: 'Prosjektdeltakere', loggedin: true }); + +} + +exports.postProjectParticipants = function(req, res) { + + + +} + + exports.newProject = function(req, res) { res.render('newproject', { title: 'Nytt prosjekt', loggedin: true }); } exports.postNewProject = function(req, res) { var project = new Project(req.body); + project.user = req.user._id; project.save(function(err) { - if (err) return res.render('newproject', { title: 'Nytt prosjekt - en feil oppstod', loggedin: true, errors: err.errors, project: project }); - return res.redirect('/dashboard'); + if (err) { + console.log(err.errors); + return res.render('newproject', { title: 'Nytt prosjekt - en feil oppstod', loggedin: true, errors: err.errors, project: project }); + } }); + + var access = new Access(); + access.user = req.user._id; + access.creator = req.user._id; + access.project = project._id; + access.permissions = 1; + access.save(function(err) { + if (err) { + console.log(err.errors); + return res.render('newproject', { title: 'Nytt prosjekt - en feil oppstod', loggedin: true }); + } + return res.redirect('/dashboard'); + }) } |