Check for worker_id (no duplicate allowed)
This commit is contained in:
parent
eb79b0bc42
commit
0a034471ca
|
@ -594,6 +594,40 @@ DBReq.UserIdChecker.prototype.finish = function() {
|
||||||
this.finishAction(this.finalResult);
|
this.finishAction(this.finalResult);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DBReq.UserNameChecker = function(name, finishAction) {
|
||||||
|
this.name = name;
|
||||||
|
this.finishAction = finishAction;
|
||||||
|
var self = this;
|
||||||
|
pg.connect(pgc.url, function(err, client, release) {
|
||||||
|
self.client = client;
|
||||||
|
self.release = release;
|
||||||
|
self.execute();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
DBReq.UserNameChecker.prototype.execute = function() {
|
||||||
|
var self = this;
|
||||||
|
this.client.query(
|
||||||
|
"SELECT count(id) > 0 AS answer FROM users WHERE worker_id = $1",
|
||||||
|
[self.name],
|
||||||
|
function(err, result) {
|
||||||
|
if (err !== null)
|
||||||
|
Log.dberror(err + ' in UserNameChecker');
|
||||||
|
self.finalResult = result.rows[0].answer;
|
||||||
|
self.finish();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
DBReq.UserNameChecker.prototype.finish = function() {
|
||||||
|
this.release();
|
||||||
|
this.client = null;
|
||||||
|
this.release = null;
|
||||||
|
|
||||||
|
this.finishAction(this.finalResult);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that creates an experiment
|
* Class that creates an experiment
|
||||||
* @param id {Number} id of the experiment to check
|
* @param id {Number} id of the experiment to check
|
||||||
|
@ -671,7 +705,7 @@ DBReq.ExpGetter.prototype.execute = function() {
|
||||||
this.client.query(
|
this.client.query(
|
||||||
"SELECT " +
|
"SELECT " +
|
||||||
"experiment.id as exp_id, " +
|
"experiment.id as exp_id, " +
|
||||||
"users.name as username, " +
|
"users.worker_id as username, " +
|
||||||
"scene.name as scenename, " +
|
"scene.name as scenename, " +
|
||||||
"users.id as user_id " +
|
"users.id as user_id " +
|
||||||
"FROM experiment, users, scene " +
|
"FROM experiment, users, scene " +
|
||||||
|
@ -757,6 +791,10 @@ DBReq.checkUserId = function(id, callback) {
|
||||||
new DBReq.UserIdChecker(id, callback);
|
new DBReq.UserIdChecker(id, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DBReq.checkUserName = function(name, callback) {
|
||||||
|
new DBReq.UserNameChecker(name, callback);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if an experiment id exists
|
* Checks if an experiment id exists
|
||||||
* @memberof DBReq
|
* @memberof DBReq
|
||||||
|
|
|
@ -148,7 +148,7 @@ module.exports.tutorial = function(req, res) {
|
||||||
req.session.save();
|
req.session.save();
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'text/html');
|
res.setHeader('Content-Type', 'text/html');
|
||||||
res.render('tutorial.jade', res.lcals, function(err, result) {
|
res.render('tutorial.jade', res.locals, function(err, result) {
|
||||||
res.send(result);
|
res.send(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -211,7 +211,11 @@ module.exports.viewer = function(req, res, next) {
|
||||||
module.exports.userstudy = function(req, res) {
|
module.exports.userstudy = function(req, res) {
|
||||||
res.setHeader('Content-Type', 'text/html');
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
|
||||||
res.render('user_study.jade', res.lcals, function(err, result) {
|
res.locals.identificationFailed = req.session.identificationFailed;
|
||||||
|
req.session.identificationFailed = false;
|
||||||
|
req.session.save();
|
||||||
|
|
||||||
|
res.render('user_study.jade', res.locals, function(err, result) {
|
||||||
res.send(result);
|
res.send(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,14 @@ extends ../../../views/base.jade
|
||||||
block extrahead
|
block extrahead
|
||||||
link(rel="stylesheet", href="/static/css/signin.css")
|
link(rel="stylesheet", href="/static/css/signin.css")
|
||||||
|
|
||||||
|
block extrabody
|
||||||
|
if identificationFailed
|
||||||
|
.container
|
||||||
|
.alert.alert-danger.alert-dismissible(role="alert", style={'margin-top':'20px'})
|
||||||
|
button.close(type="button", data-dismiss="alert", aria-label="Close")
|
||||||
|
span(aria-hidden="true") ×
|
||||||
|
<strong>Error</strong> : this id is already used !
|
||||||
|
|
||||||
block content
|
block content
|
||||||
form.form-signin(method="POST", action='/identification')
|
form.form-signin(method="POST", action='/identification')
|
||||||
h2 Please sign in
|
h2 Please sign in
|
||||||
|
@ -13,10 +21,11 @@ block content
|
||||||
|
|
||||||
div(style={'text-align': 'center', 'margin-top':'10px', 'margin-bottom':'10px'})
|
div(style={'text-align': 'center', 'margin-top':'10px', 'margin-bottom':'10px'})
|
||||||
label.radio-inline
|
label.radio-inline
|
||||||
input(type='radio', name='inputGender', value="male")
|
input(type='radio', name='inputGender', value="male", checked)
|
||||||
| Male
|
| Male
|
||||||
label.radio-inline
|
label.radio-inline
|
||||||
input(type='radio', name='inputGender', value="female")
|
input(type='radio', name='inputGender', value="female")
|
||||||
| Female
|
| Female
|
||||||
|
|
||||||
button.btn.btn-lg.btn-primary.btn-block(type='submit') Sign in
|
button.btn.btn-lg.btn-primary.btn-block(type='submit') Sign in
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ var db = require('../../controllers/prototype/dbrequests.js');
|
||||||
var Log = require('../../lib/NodeLog.js');
|
var Log = require('../../lib/NodeLog.js');
|
||||||
|
|
||||||
module.exports.index = function(req, res) {
|
module.exports.index = function(req, res) {
|
||||||
|
db.checkUserName(req.body.inputId, function(ok) {
|
||||||
|
if (!ok) {
|
||||||
db.tryUser(req.session.user_id, function(id) {
|
db.tryUser(req.session.user_id, function(id) {
|
||||||
req.session.user_id = id;
|
req.session.user_id = id;
|
||||||
req.session.save();
|
req.session.save();
|
||||||
|
@ -22,6 +23,12 @@ module.exports.index = function(req, res) {
|
||||||
});
|
});
|
||||||
|
|
||||||
res.redirect('/');
|
res.redirect('/');
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
req.session.identificationFailed = true;
|
||||||
|
res.redirect('/user-study');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,6 +24,8 @@ html(lang='fr')
|
||||||
|
|
||||||
block links
|
block links
|
||||||
|
|
||||||
|
block extrabody
|
||||||
|
|
||||||
section#main-section.container
|
section#main-section.container
|
||||||
if alertCookie
|
if alertCookie
|
||||||
.alert.alert-warning.alert-dismissible(role="alert", style={'margin-top':'20px'})
|
.alert.alert-warning.alert-dismissible(role="alert", style={'margin-top':'20px'})
|
||||||
|
|
Loading…
Reference in New Issue