3d-interface/posts/identification/index.js

43 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-07-23 17:19:53 +02:00
var pg = require('pg');
var secret = require('../../private');
var db = require('../../controllers/prototype/dbrequests.js');
var Log = require('../../lib/NodeLog.js');
module.exports.index = function(req, res) {
2015-07-27 16:59:53 +02:00
db.checkUserName(req.body.inputId, function(ok) {
if (!ok) {
db.tryUser(req.session.user_id, function(id) {
req.session.user_id = id;
req.session.save();
2015-07-23 17:19:53 +02:00
pg.connect(secret.url, function(err, client, release) {
client.query(
2015-07-27 16:59:53 +02:00
"UPDATE Users SET worker_id = $1, age = $2, male = $3, rating = $5, lasttime = $6 WHERE id = $4;",
[
req.body.inputId,
req.body.inputAge,
req.body.inputGender === 'male',
req.session.user_id,
req.body.input3dskills,
req.body.inputLastTime
],
function(err, result) {
if (err !== null)
Log.dberror(err + ' in identfication');
release();
}
);
});
2015-07-23 17:19:53 +02:00
2015-07-29 11:04:38 +02:00
res.redirect('/prototype/tutorial');
2015-07-23 17:19:53 +02:00
});
} else {
req.session.identificationFailed = true;
res.redirect('/user-study');
}
2015-07-23 17:19:53 +02:00
});
};