Error if user already exists, clean user
This commit is contained in:
parent
dff2c4bbb8
commit
aa88b397d8
|
@ -61,6 +61,11 @@ module.exports.signupTarget = function(req, res, render) {
|
||||||
require('crypto').randomBytes(48, function(err, buffer) {
|
require('crypto').randomBytes(48, function(err, buffer) {
|
||||||
user.activationKey = buffer.toString('hex');
|
user.activationKey = buffer.toString('hex');
|
||||||
user.save((err) => {
|
user.save((err) => {
|
||||||
|
|
||||||
|
if (err !== undefined) {
|
||||||
|
return res.redirect(getUrl('signup'));
|
||||||
|
}
|
||||||
|
|
||||||
res.locals.user = user;
|
res.locals.user = user;
|
||||||
|
|
||||||
let baseUrl =
|
let baseUrl =
|
||||||
|
|
|
@ -2,7 +2,7 @@ extends ../../../templates/base.pug
|
||||||
|
|
||||||
block content
|
block content
|
||||||
.jumbotron
|
.jumbotron
|
||||||
h1.display-3 Welcome#{session.user !== undefined ? ', ' + session.user._username.value : ' on ADEjs'}!
|
h1.display-3 Welcome#{session.user !== undefined ? ', ' + session.user.username : ' on ADEjs'}!
|
||||||
if session.user === undefined
|
if session.user === undefined
|
||||||
p.lead.
|
p.lead.
|
||||||
On this site, you can subscribe, set your calendar information
|
On this site, you can subscribe, set your calendar information
|
||||||
|
|
|
@ -6,25 +6,25 @@ block content
|
||||||
.col-2
|
.col-2
|
||||||
label.col-2.col-form-label(for="username") Username
|
label.col-2.col-form-label(for="username") Username
|
||||||
.col-6
|
.col-6
|
||||||
input.form-control(type="text", value=session.user._username.value, disabled, name="username", id="username")
|
input.form-control(type="text", value=session.user.username, disabled, name="username", id="username")
|
||||||
.col-2
|
.col-2
|
||||||
.form-group.row
|
.form-group.row
|
||||||
.col-2
|
.col-2
|
||||||
label.col-2.col-form-label(for="email") Email
|
label.col-2.col-form-label(for="email") Email
|
||||||
.col-6
|
.col-6
|
||||||
input.form-control(type="email", value=session.user._email.value, disabled, name="email", id="email")
|
input.form-control(type="email", value=session.user.email, disabled, name="email", id="email")
|
||||||
.col-2
|
.col-2
|
||||||
.form-group.row
|
.form-group.row
|
||||||
.col-2
|
.col-2
|
||||||
label.col-2.col-form-label(for="resources") Resources
|
label.col-2.col-form-label(for="resources") Resources
|
||||||
.col-6
|
.col-6
|
||||||
input.form-control(type="number", value=session.user._resources.value, name="resources", id="resources")
|
input.form-control(type="number", value=session.user.resources, name="resources", id="resources")
|
||||||
.col-2
|
.col-2
|
||||||
.form-group.row
|
.form-group.row
|
||||||
.col-2
|
.col-2
|
||||||
label.col-2.col-form-label(for="projectId") Project id
|
label.col-2.col-form-label(for="projectId") Project id
|
||||||
.col-6
|
.col-6
|
||||||
input.form-control(type="number", value=session.user._projectId.value, name="projectId", id="projectId")
|
input.form-control(type="number", value=session.user.projectId, name="projectId", id="projectId")
|
||||||
.col-2
|
.col-2
|
||||||
|
|
||||||
.form-group.row
|
.form-group.row
|
||||||
|
|
|
@ -15,7 +15,7 @@ module.exports.settingsTarget = function(req, res, render) {
|
||||||
return res.redirect(getUrl("settings"));
|
return res.redirect(getUrl("settings"));
|
||||||
}
|
}
|
||||||
|
|
||||||
User.getById(req.session.user._id.value, (err, user) => {
|
User.getById(req.session.user.id, (err, user) => {
|
||||||
|
|
||||||
user.projectId = projectId;
|
user.projectId = projectId;
|
||||||
user.resources = resources;
|
user.resources = resources;
|
||||||
|
|
5
index.js
5
index.js
|
@ -10,6 +10,7 @@ const path = require('path');
|
||||||
const log = require('log');
|
const log = require('log');
|
||||||
const model = require('model');
|
const model = require('model');
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
|
const User = require('auth/models');
|
||||||
|
|
||||||
// Load models
|
// Load models
|
||||||
model.load(config.CONTROLLERS_DIR);
|
model.load(config.CONTROLLERS_DIR);
|
||||||
|
@ -39,6 +40,10 @@ function startServer() {
|
||||||
log.request(req, res, Date.now() - start);
|
log.request(req, res, Date.now() - start);
|
||||||
});
|
});
|
||||||
res.locals.session = req.session;
|
res.locals.session = req.session;
|
||||||
|
|
||||||
|
if (req.session.user !== undefined) {
|
||||||
|
req.session.user = User.fromJSON(req.session.user);
|
||||||
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -245,6 +245,25 @@ module.exports.createClass = function(model) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret.prototype.toJSON = function() {
|
||||||
|
let json = {};
|
||||||
|
for (let field of model.fields) {
|
||||||
|
json[field.name] = this[field.name]
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.fromJSON = function(json) {
|
||||||
|
let result = new ret();
|
||||||
|
|
||||||
|
for (let field of model.fields) {
|
||||||
|
result[field.name] = json[field.name];
|
||||||
|
}
|
||||||
|
result._persisted = false;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
ret.prototype.save = function(callback = () => {}) {
|
ret.prototype.save = function(callback = () => {}) {
|
||||||
let fieldsToSave = [];
|
let fieldsToSave = [];
|
||||||
for (let field of model.fields) {
|
for (let field of model.fields) {
|
||||||
|
|
Loading…
Reference in New Issue