adejs/controllers/settings/views.js

30 lines
741 B
JavaScript

const getUrl = require('create-url').getUrl;
const User = require('auth/models');
module.exports.settings = function(req, res, render) {
render('settings.pug');
}
module.exports.settingsTarget = function(req, res, render) {
let projectId = parseInt(req.body.projectId, 10);
let resources = parseInt(req.body.resources, 10);
if (isNaN(projectId) || isNaN(resources)) {
return res.redirect(getUrl("settings"));
}
User.getById(req.session.user._id.value, (err, user) => {
user.projectId = projectId;
user.resources = resources;
user.save(() => {
req.session.user = user;
req.session.save();
res.redirect(getUrl('index'));
});
});
}