Skip to content

Commit 44262ee

Browse files
committed
GDPR2
* Remember and recall consents * Speeds up logging in if we already have it NOTES: * Good thing I twiddled with this before :) Post OpenUserJS#1174 and OpenUserJS#1385 'ish
1 parent a05e724 commit 44262ee

4 files changed

Lines changed: 32 additions & 7 deletions

File tree

controllers/auth.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ exports.callback = function (aReq, aRes, aNext) {
280280
// Save the last date a user sucessfully logged in
281281
aUser.authed = new Date();
282282

283+
// Save consent
284+
aUser.consented = true;
285+
283286
// Save the session id on the user model
284287
aUser.sessionId = aReq.sessionID;
285288

controllers/user.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var formidable = require('formidable');
1414
var async = require('async');
1515
var _ = require('underscore');
1616
var util = require('util');
17+
var rfc2047 = require('rfc2047');
1718

1819
var SPDX = require('spdx-license-ids');
1920
var SPDXOSI = require('spdx-osi'); // NOTE: Sub-dep of `spdx-is-osi`
@@ -84,21 +85,34 @@ exports.exist = function (aReq, aRes) {
8485
return;
8586
}
8687

87-
User.count({
88+
User.findOne({
8889
name: caseInsensitive(username)
89-
}, function (aErr, aCount) {
90+
}, function (aErr, aUser) {
91+
var msg = null;
92+
9093
if (aErr) {
9194
aRes.status(400).send();
9295
return;
9396
}
9497

95-
if (aCount === 0) {
98+
99+
if (!aUser) {
96100
aRes.status(404).send();
97101
return;
98102
}
99103

104+
if (!aUser.consented) {
105+
msg = [
106+
'199 ' + aReq.headers.host + ' consent'
107+
108+
].join('\u0020');
109+
aRes.set('Warning', msg);
110+
}
111+
100112
aRes.status(200).send();
101-
});
113+
});
114+
115+
102116
};
103117

104118
var setupUserModerationUITask = function (aOptions) {

models/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var userSchema = new Schema({
1717
about: String,
1818

1919
// A user can link multiple accounts to their OpenUserJS account
20+
consented: Boolean,
2021
auths: Array,
2122
strategies: Array,
2223
authed: Date, // last logged in

views/includes/scripts/loginEcho.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@
1515
function onDOMContentLoaded(aEv) {
1616
var username = document.querySelector('input[name="username"]');
1717
var auth = document.querySelector('select[name="auth"]');
18+
var consent = document.querySelector('input[name="consent"]');
1819
var action = document.querySelector('button#action');
1920

2021
function onInput(aEv) {
2122
var req = new XMLHttpRequest();
2223
var wantname = cleanFilename(aEv.target.value, '');
2324

24-
function show() {
25+
function show(aConsent) {
2526
action.innerHTML = action.innerHTML.replace(/Sign Up/, 'Sign In');
2627
action.classList.add('btn-success');
2728
action.classList.remove('btn-info');
29+
30+
if (aConsent) {
31+
consent.checked = false;
32+
} else {
33+
consent.checked = true;
34+
}
2835
}
2936

3037
function hide() {
@@ -39,11 +46,11 @@
3946
if (this.readyState == this.DONE) {
4047
switch (this.status) {
4148
case 200:
42-
show();
49+
show(/ consent$/.test(this.getResponseHeader('Warning')));
4350
auth.value = '';
4451
break;
4552
default:
46-
hide();
53+
hide(true);
4754
auth.value = 'github';
4855
}
4956
}

0 commit comments

Comments
 (0)