Added settings page

This commit is contained in:
Thomas Forgione 2017-09-23 23:03:25 +00:00
parent f6d7cb552b
commit df91c45944
No known key found for this signature in database
GPG Key ID: 95D964F74A96119E
4 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,34 @@
extends ../../../templates/base.pug
block content
form(method="POST", action=getUrl("settingsTarget"))
.form-group.row
.col-2
label.col-2.col-form-label(for="username") Username
.col-6
input.form-control(type="text", value=session.user._username.value, disabled, name="username", id="username")
.col-2
.form-group.row
.col-2
label.col-2.col-form-label(for="email") Email
.col-6
input.form-control(type="email", value=session.user._email.value, disabled, name="email", id="email")
.col-2
.form-group.row
.col-2
label.col-2.col-form-label(for="resources") Resources
.col-6
input.form-control(type="number", value=session.user._resources.value, name="resources", id="resources")
.col-2
.form-group.row
.col-2
label.col-2.col-form-label(for="projectId") Project id
.col-6
input.form-control(type="number", value=session.user._projectId.value, name="projectId", id="projectId")
.col-2
.form-group.row
.col-4
.col-4
input.btn.btn-primary.form-control(type="submit", value="Submit")
.col-4

View File

@ -0,0 +1,6 @@
const url = require('create-url').url;
module.exports = [
url('/settings', 'settings', 'settings'),
url('/settingsTarget', 'settingsTarget', 'settingsTarget', 'POST'),
]

View File

@ -0,0 +1,29 @@
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'));
});
});
}

View File

@ -34,7 +34,7 @@ html
| Sign up
else
li.nav-item
a.nav-link(href='#')
a.nav-link(href=getUrl("settings"))
| #{session.user._username.value}
li.nav-item
a.btn.btn-light(href=getUrl("logout"), role='button')