Skip to content

Commit

Permalink
De *async* login (OpenUserJS#1562)
Browse files Browse the repository at this point in the history
* Trying this as a test again officially. Seemed to work well the first time. Plus it squashes an unmonitored `Err`
* Change maxItems per page to 25 period instead of 100. May go lower if requested. We can't have anything nice anymore. \*sigh\* Not detected as being used but I didn't spend much time looking at these when url monitored. Better to be safe than sorry now.

NOTES:
* Tries `async` and `await` *(pseudo `Promise`s)* and that screen lagged during site perusing. So that option is probably out.

Applies to OpenUserJS#1548

Auto-merge
  • Loading branch information
Martii authored Dec 21, 2018
1 parent 1248dcb commit a43bb8d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 46 deletions.
76 changes: 31 additions & 45 deletions controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var execQueryTask = require('../libs/tasks').execQueryTask;
var removeSession = require('../libs/modifySessions').remove;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;
var orderDir = require('../libs/templateHelpers').orderDir;
var statusCodePage = require('../libs/templateHelpers').statusCodePage;

//--- Configuration inclusions
var strategies = require('./strategies.json');
Expand Down Expand Up @@ -209,26 +210,6 @@ function getRedirect(aReq) {

// UI for user registration
exports.register = function (aReq, aRes) {
function preRender() {
// Sort the strategies
options.strategies = _.sortBy(options.strategies, function (aStrategy) {
return aStrategy.display;
});
}

function render() {
aRes.header('Cache-Control', 'no-cache, no-store, must-revalidate');
aRes.header('Pragma', 'no-cache');
aRes.header('Expires', '0');

aRes.render('pages/loginPage', options);
}

function asyncComplete() {
preRender();
render();
}

//
var options = {};
var authedUser = aReq.session.user;
Expand Down Expand Up @@ -268,35 +249,40 @@ exports.register = function (aReq, aRes) {
}
});

//--- Tasks

//
tasks.push(function (aCallback) {
Strategy.find({}, function (aErr, aAvailableStrategies) {
if (aErr || !aAvailableStrategies) {
aCallback(); // WARNING: Silent error handling
} else {
// Get the strategies we have OAuth keys for
aAvailableStrategies.forEach(function (aStrategy) {
options.strategies.push({
'strat': aStrategy.name,
'display': aStrategy.display
});

Strategy.find({}, function (aErr, aAvailableStrategies) {
if (aErr || !aAvailableStrategies) {
statusCodePage(aReq, aRes, aNext, {
statusCode: 503,
statusMessage:
'We are experiencing technical difficulties right now. Please try again later.'
});
} else {
// Get the strategies we have OAuth keys for
aAvailableStrategies.forEach(function (aStrategy) {
options.strategies.push({
'strat': aStrategy.name,
'display': aStrategy.display
});
aCallback();
}
});
});
});

tasks.push(function (aCallback) {
// Insert an empty default strategy at the beginning
// NOTE: Safari always autoselects an option when disabled
options.strategies.unshift({'strat': '', 'display': '(default preferred authentication)'});
aCallback();
});
// Insert an empty default strategy at the beginning
// NOTE: Safari always autoselects an option when disabled
options.strategies.unshift({'strat': '', 'display': '(default preferred authentication)'});

//---
async.parallel(tasks, asyncComplete);
// Sort the strategies
options.strategies = _.sortBy(options.strategies, function (aStrategy) {
return aStrategy.display;
});

aRes.header('Cache-Control', 'no-cache, no-store, must-revalidate');
aRes.header('Pragma', 'no-cache');
aRes.header('Expires', '0');

aRes.render('pages/loginPage', options);
}
});
};

exports.logout = function (aReq, aRes) {
Expand Down
2 changes: 1 addition & 1 deletion libs/templateHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ exports.paginateTemplate = paginateTemplate;

var newPagination = function (aCurrentPage, aItemsPerPage) {
// Options
var maxItemsPerPage = 100;
var maxItemsPerPage = 25;
var defaultItemsPerPage = 25;

//
Expand Down

0 comments on commit a43bb8d

Please sign in to comment.