32 lines
840 B
JavaScript
32 lines
840 B
JavaScript
const getUrl = require('create-url').getUrl;
|
|
const User = require('auth/models');
|
|
|
|
const redirectIfNotLogged = require('auth/views').redirectIfNotLogged;
|
|
|
|
module.exports.settings = redirectIfNotLogged('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, (err, user) => {
|
|
|
|
user.projectId = projectId;
|
|
user.resources = resources;
|
|
|
|
user.save(() => {
|
|
req.session.user = user;
|
|
req.session.save();
|
|
res.redirect(getUrl('index'));
|
|
});
|
|
|
|
});
|
|
|
|
}
|