gpii-universal
Version:
Cross platform, core components of the GPII personalization infrastructure.
73 lines (63 loc) • 2.54 kB
JavaScript
/*
* GPII User Logon State Change
*
* Copyright 2012 OCAD University
* Copyright 2015, 2017 Raising the Floor - International
* Copyright 2018 OCAD University
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* The research leading to these results has received funding from the European Union's
* Seventh Framework Programme (FP7/2007-2013)
* under grant agreement no. 289016.
*
* You may obtain a copy of the License at
* https://github.com/GPII/universal/blob/master/LICENSE.txt
*/
"use strict";
var fluid = require("infusion");
var gpii = fluid.registerNamespace("gpii");
// The base handler component containing common functions required by all http request handlers for these endpoints:
// * /user/:gpiiKey/proximityTriggered
// * /user/:gpiiKey/login
// * /user/:gpiiKey/logout
fluid.defaults("gpii.flowManager.baseHandler", {
gradeNames: ["kettle.request.http"],
logonState: "proximityTriggered",
invokers: {
handleRequest: {
funcName: "gpii.flowManager.baseHandler.handleRequest",
args: ["{flowManager}.lifecycleManager", "{that}", "{that}.options.logonState", "{that}.req.params.gpiiKey"]
// logonFunc
}
}
});
/**
* Capitalize the first letter of a string.
* @param {String} inputStr - The string to have the first letter capitalized.
* @return {String} - The input string having the first letter capitalized.
*/
gpii.flowManager.capitalizeFirstLetter = function (inputStr) {
return inputStr.charAt(0).toUpperCase() + inputStr.substr(1);
};
gpii.flowManager.baseHandler.handleRequest = function (lifecycleManager, request, logonState, gpiiKey) {
var logonFunc = "perform" + gpii.flowManager.capitalizeFirstLetter(logonState);
var logonPromise = lifecycleManager[logonFunc](gpiiKey);
logonPromise.then(request.events.onSuccess.fire, request.events.onError.fire);
};
// Request handler for /user/:gpiiKey/proximityTriggered
fluid.defaults("gpii.flowManager.proximityTrigger.handler", {
gradeNames: ["gpii.flowManager.baseHandler"],
logonState: "proximityTriggered"
});
// Request handler for /user/<myGpiiKey>/login
fluid.defaults("gpii.flowManager.userLogin.handler", {
gradeNames: ["gpii.flowManager.baseHandler"],
logonState: "login"
});
// Request handler for /user/<myGpiiKey>/logout
fluid.defaults("gpii.flowManager.userLogout.handler", {
gradeNames: ["gpii.flowManager.baseHandler"],
logonState: "logout"
});