From eb79b0bc428ce94b472babcf61fe71ba93db22cb Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Thu, 23 Jul 2015 17:19:53 +0200 Subject: [PATCH] Identification --- controllers/prototype/dbrequests.js | 2 +- controllers/prototype/index.js | 9 ++ controllers/prototype/urls.js | 3 +- controllers/prototype/views/user_study.jade | 22 ++++ lib/controllers.js | 1 - lib/posts.js | 4 +- posts/arrow-clicked/urls.js | 2 +- posts/coin-clicked/urls.js | 2 +- posts/coin-id/urls.js | 2 +- posts/coin-info/urls.js | 2 +- posts/fps/urls.js | 2 +- posts/hovered/urls.js | 2 +- posts/identification/index.js | 27 +++++ posts/identification/urls.js | 3 + posts/keyboard-event/urls.js | 2 +- posts/pointer-locked/urls.js | 2 +- posts/previous-next-clicked/urls.js | 2 +- posts/reset-clicked/urls.js | 2 +- posts/switched-lock-option/urls.js | 2 +- sql/backup.pgsql | 4 +- views/base.jade | 40 ++++++ views/main.jade | 128 +++++++------------- 22 files changed, 166 insertions(+), 99 deletions(-) create mode 100644 controllers/prototype/views/user_study.jade create mode 100644 posts/identification/index.js create mode 100644 posts/identification/urls.js create mode 100644 views/base.jade diff --git a/controllers/prototype/dbrequests.js b/controllers/prototype/dbrequests.js index 4c8d3a2..788a2e9 100644 --- a/controllers/prototype/dbrequests.js +++ b/controllers/prototype/dbrequests.js @@ -477,7 +477,7 @@ DBReq.UserCreator = function(finishAction) { DBReq.UserCreator.prototype.execute = function() { var self = this; this.client.query( - "INSERT INTO users(name) VALUES('anonymous'); SELECT currval('users_id_seq');", + "INSERT INTO users DEFAULT VALUES; SELECT currval('users_id_seq');", [], function(err, result) { self.finalResult = result.rows[0].currval; diff --git a/controllers/prototype/index.js b/controllers/prototype/index.js index 3086cb6..dcba3fe 100644 --- a/controllers/prototype/index.js +++ b/controllers/prototype/index.js @@ -207,3 +207,12 @@ module.exports.viewer = function(req, res, next) { }); }; + +module.exports.userstudy = function(req, res) { + res.setHeader('Content-Type', 'text/html'); + + res.render('user_study.jade', res.lcals, function(err, result) { + res.send(result); + }); + +}; diff --git a/controllers/prototype/urls.js b/controllers/prototype/urls.js index 253fad4..242c3d0 100644 --- a/controllers/prototype/urls.js +++ b/controllers/prototype/urls.js @@ -9,5 +9,6 @@ module.exports = { '/prototype/tutorial': 'tutorial', '/prototype/sponza': 'sponza', '/prototype/coin-creator/:scene': 'clicker', - '/prototype/coin-viewer/:scene': 'viewer' + '/prototype/coin-viewer/:scene': 'viewer', + '/user-study': 'userstudy' }; diff --git a/controllers/prototype/views/user_study.jade b/controllers/prototype/views/user_study.jade new file mode 100644 index 0000000..bf383fd --- /dev/null +++ b/controllers/prototype/views/user_study.jade @@ -0,0 +1,22 @@ +extends ../../../views/base.jade + +block extrahead + link(rel="stylesheet", href="/static/css/signin.css") + +block content + form.form-signin(method="POST", action='/identification') + h2 Please sign in + label(for='inputId').sr-only Id + input#inputId.form-control(name="inputId", type="text", placeholder='Id', required, autofocus) + label(for='inputAge').sr-only Age + input#inputAge.form-control(name="inputAge", type="number", placeholder='Age', min="18", required) + + div(style={'text-align': 'center', 'margin-top':'10px', 'margin-bottom':'10px'}) + label.radio-inline + input(type='radio', name='inputGender', value="male") + | Male + label.radio-inline + input(type='radio', name='inputGender', value="female") + | Female + + button.btn.btn-lg.btn-primary.btn-block(type='submit') Sign in diff --git a/lib/controllers.js b/lib/controllers.js index e1a9b4f..34d4b78 100644 --- a/lib/controllers.js +++ b/lib/controllers.js @@ -31,7 +31,6 @@ module.exports = function(parent){ for (var key in urls) { app.get(key, obj[urls[key]]); - Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]); } diff --git a/lib/posts.js b/lib/posts.js index 7382117..3e58109 100644 --- a/lib/posts.js +++ b/lib/posts.js @@ -30,9 +30,9 @@ module.exports = function(parent){ Log.debug(' ' + name + ':'); for (var key in urls) { - app.post('/posts' + key, obj[urls[key]]); + app.post(key, obj[urls[key]]); - Log.debug(' /posts' + key + ' -> posts.' + name + '.' + urls[key]); + Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]); } Log.debug(); diff --git a/posts/arrow-clicked/urls.js b/posts/arrow-clicked/urls.js index b0729d0..efb9a04 100644 --- a/posts/arrow-clicked/urls.js +++ b/posts/arrow-clicked/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/arrow-clicked': 'index' + '/posts/arrow-clicked': 'index' }; diff --git a/posts/coin-clicked/urls.js b/posts/coin-clicked/urls.js index b6546fc..e2208ac 100644 --- a/posts/coin-clicked/urls.js +++ b/posts/coin-clicked/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/coin-clicked': 'index' + '/posts/coin-clicked': 'index' }; diff --git a/posts/coin-id/urls.js b/posts/coin-id/urls.js index c5a8d7e..4b3a708 100644 --- a/posts/coin-id/urls.js +++ b/posts/coin-id/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/coin-id': 'index' + '/posts/coin-id': 'index' }; diff --git a/posts/coin-info/urls.js b/posts/coin-info/urls.js index a9e6a1e..46fe8d0 100644 --- a/posts/coin-info/urls.js +++ b/posts/coin-info/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/coin-info': 'index' + '/posts/coin-info': 'index' }; diff --git a/posts/fps/urls.js b/posts/fps/urls.js index af9fc07..b7dfa28 100644 --- a/posts/fps/urls.js +++ b/posts/fps/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/fps': 'index' + '/posts/fps': 'index' }; diff --git a/posts/hovered/urls.js b/posts/hovered/urls.js index e4b8eb9..f224f67 100644 --- a/posts/hovered/urls.js +++ b/posts/hovered/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/hovered': 'index' + '/posts/hovered': 'index' }; diff --git a/posts/identification/index.js b/posts/identification/index.js new file mode 100644 index 0000000..0079579 --- /dev/null +++ b/posts/identification/index.js @@ -0,0 +1,27 @@ +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) { + + db.tryUser(req.session.user_id, function(id) { + req.session.user_id = id; + req.session.save(); + + pg.connect(secret.url, function(err, client, release) { + client.query( + "UPDATE Users SET worker_id = $1, age = $2, male = $3 WHERE id = $4;", + [req.body.inputId, req.body.inputAge, req.body.inputGender === 'male', req.session.user_id], + function(err, result) { + if (err !== null) + Log.dberror(err + ' in identfication'); + release(); + } + ); + }); + + res.redirect('/'); + }); + +}; diff --git a/posts/identification/urls.js b/posts/identification/urls.js new file mode 100644 index 0000000..0f6f327 --- /dev/null +++ b/posts/identification/urls.js @@ -0,0 +1,3 @@ +module.exports = { + '/identification': 'index' +}; diff --git a/posts/keyboard-event/urls.js b/posts/keyboard-event/urls.js index 8abfea9..8df96b5 100644 --- a/posts/keyboard-event/urls.js +++ b/posts/keyboard-event/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/keyboard-event': 'index' + '/posts/keyboard-event': 'index' }; diff --git a/posts/pointer-locked/urls.js b/posts/pointer-locked/urls.js index 8aaecbd..376dc96 100644 --- a/posts/pointer-locked/urls.js +++ b/posts/pointer-locked/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/pointer-locked': 'index' + '/posts/pointer-locked': 'index' }; diff --git a/posts/previous-next-clicked/urls.js b/posts/previous-next-clicked/urls.js index f013a5f..b93625b 100644 --- a/posts/previous-next-clicked/urls.js +++ b/posts/previous-next-clicked/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/previous-next-clicked': 'index' + '/posts/previous-next-clicked': 'index' }; diff --git a/posts/reset-clicked/urls.js b/posts/reset-clicked/urls.js index d6c1a22..d5bbcca 100644 --- a/posts/reset-clicked/urls.js +++ b/posts/reset-clicked/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/reset-clicked': 'index' + '/posts/reset-clicked': 'index' }; diff --git a/posts/switched-lock-option/urls.js b/posts/switched-lock-option/urls.js index 55e590a..a954670 100644 --- a/posts/switched-lock-option/urls.js +++ b/posts/switched-lock-option/urls.js @@ -1,3 +1,3 @@ module.exports = { - '/switched-lock-option': 'index' + '/posts/switched-lock-option': 'index' }; diff --git a/sql/backup.pgsql b/sql/backup.pgsql index d309cb7..6d0853e 100644 --- a/sql/backup.pgsql +++ b/sql/backup.pgsql @@ -36,7 +36,9 @@ CREATE TYPE CAMERA AS( -- Base tables CREATE TABLE Users( id SERIAL PRIMARY KEY, - name CHAR(50) + worker_id varchar(50), + age INTEGER, + male BOOLEAN ); CREATE TABLE Scene( diff --git a/views/base.jade b/views/base.jade new file mode 100644 index 0000000..6887798 --- /dev/null +++ b/views/base.jade @@ -0,0 +1,40 @@ +doctype html +html(lang='fr') + head + meta(charset='utf-8') + meta(name='viewport', content='width=device-width, initial-scale=1') + link(rel="stylesheet", href="/static/bootstrap/css/bootstrap.css") + link(rel="stylesheet", href="/static/css/style.css") + link(rel="stylesheet", href="/static/css/syntax.css") + block extrahead + link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic") + link(rel="icon", type="image/x-icon", href="/favicon.ico") + block title + title Hello + + body + nav#nav.navbar.navbar-inverse.navbar-fixed-top(role="navigation") + .container + #navbar.navbar-header + button.navbar-toggle(type="button", data-toggle="collapse" data-target=".navbar-collapse") + span.sr-only Toggle navigation + span.icon-bar + span.icon-bar + a.navbar-brand(href="#{urls.index}") 3DUI + + block links + + section#main-section.container + if alertCookie + .alert.alert-warning.alert-dismissible(role="alert", style={'margin-top':'20px'}) + button.close(type="button", data-dismiss="alert", aria-label="Close") + span(aria-hidden="true") × + Warning : this website use cookies ! + + block content + + script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js") + script(src="/static/bootstrap/js/bootstrap.min.js") + block js + block extrajs + diff --git a/views/main.jade b/views/main.jade index 00774c4..e911b21 100644 --- a/views/main.jade +++ b/views/main.jade @@ -1,91 +1,55 @@ +extends ./base.jade + mixin button_link(href) form.navbar-form.navbar-left(role="search", action="#{href}", method='GET') button.btn.btn-default(type="submit") block - -doctype html -html(lang='fr') - head - meta(charset='utf-8') - meta(name='viewport', content='width=device-width, initial-scale=1') - link(rel="stylesheet", href="/static/bootstrap/css/bootstrap.css") - link(rel="stylesheet", href="/static/css/style.css") - link(rel="stylesheet", href="/static/css/syntax.css") - block extrahead - link(rel="stylesheet", href="http://fonts.googleapis.com/css?family=Ubuntu:400,700,400italic") - link(rel="icon", type="image/x-icon", href="/favicon.ico") - block title - title Hello - - body - nav#nav.navbar.navbar-inverse.navbar-fixed-top(role="navigation") - .container - #navbar.navbar-header - button.navbar-toggle(type="button", data-toggle="collapse" data-target=".navbar-collapse") - span.sr-only Toggle navigation - span.icon-bar - span.icon-bar - a.navbar-brand(href="#{urls.index}") 3DUI - - div.navbar-collapse.collapse - ul.nav.navbar-nav - li - a(href="#{urls.bouncing}") Bouncing cube - li - a(href="#{urls.multisphere}") Multisphere - li - a.dropdown-toggle(href="#", data-toggle="dropdown", role="button", aria-expanded="false") Prototype - span.caret - ul.dropdown-menu(role="menu") - li - a(href="#{urls.arrows}") Arrows - li - a(href="#{urls.reverse}") Reverse arrows - li - a(href="#{urls.viewports}") Viewports - li.divider - li - a(href="#{urls.replay_index}") Replays - li.divider - li - a(href="#{urls.tutorial}") Tutorial - li - a(href="#{urls.stream}") Sphere streaming - li.divider - if (session && session.user_id) - li - +button_link(urls.logout) - span.glyphicon.glyphicon-log-out(aria-hidden=true, style={"margin-right":"10px"}) - span Log out +block links + div.navbar-collapse.collapse + ul.nav.navbar-nav + li + a(href="#{urls.bouncing}") Bouncing cube + li + a(href="#{urls.multisphere}") Multisphere + li + a.dropdown-toggle(href="#", data-toggle="dropdown", role="button", aria-expanded="false") Prototype + span.caret + ul.dropdown-menu(role="menu") + li + a(href="#{urls.arrows}") Arrows + li + a(href="#{urls.reverse}") Reverse arrows + li + a(href="#{urls.viewports}") Viewports + li.divider + li + a(href="#{urls.replay_index}") Replays + li.divider + li + a(href="#{urls.tutorial}") Tutorial + li + a(href="#{urls.stream}") Sphere streaming + li.divider + if (session && session.user_id) + li + +button_link(urls.logout) + span.glyphicon.glyphicon-log-out(aria-hidden=true, style={"margin-right":"10px"}) + span Log out - ul.nav.navbar-nav.navbar-right - li - +button_link('https://github.com/tforgione/3dinterface') - img(src="/static/GitHub-Mark/PNG/GitHub-Mark-32px.png", width="17px", style={align:vertical}) - span(style={'margin-left':'5px', align:vertical}) Github Repo - li - +button_link('https://github.com/tforgione/3dinterface/wiki') - span.glyphicon.glyphicon-book(aria-hidden=true) - span(style={'margin-left':'5px'}) Github wiki + ul.nav.navbar-nav.navbar-right + li + +button_link('https://github.com/tforgione/3dinterface') + img(src="/static/GitHub-Mark/PNG/GitHub-Mark-32px.png", width="17px", style={align:vertical}) + span(style={'margin-left':'5px', align:vertical}) Github Repo + li + +button_link('https://github.com/tforgione/3dinterface/wiki') + span.glyphicon.glyphicon-book(aria-hidden=true) + span(style={'margin-left':'5px'}) Github wiki - li - +button_link('mailto:thomas.forgione@gmail.com') - span.glyphicon.glyphicon-envelope(aria-hidden=true) - span(style={'margin-left':'5px'}) Contact - - section#main-section.container - if alertCookie - .alert.alert-warning.alert-dismissible(role="alert", style={'margin-top':'20px'}) - button.close(type="button", data-dismiss="alert", aria-label="Close") - span(aria-hidden="true") × - Warning : this website use cookies ! - - block content - - script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js") - script(src="/static/bootstrap/js/bootstrap.min.js") - block js - block extrajs + li + +button_link('mailto:thomas.forgione@gmail.com') + span.glyphicon.glyphicon-envelope(aria-hidden=true) + span(style={'margin-left':'5px'}) Contact