UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

59 lines (50 loc) 1.98 kB
/** * GPII Session Aware * * Copyright 2012 OCAD University * Copyright 2015 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 */ /* eslint-env browser */ /* eslint strict: ["error", "function"] */ (function () { "use strict"; var fluid = require("infusion"), gpii = fluid.registerNamespace("gpii"); fluid.registerNamespace("gpii.lifecycleManager"); /** A mixin request grade for requests which require an active user session to do their work. Exposes a method * withSession which will acquire the session tokens and supply them as an argument or else fail if none is available. */ fluid.defaults("gpii.flowManager.sessionAware", { invokers: { withSession: { funcName: "gpii.flowManager.sessionAware.withSession", args: ["{that}", "{lifecycleManager}", "{arguments}.0", "{arguments}.1", "{arguments}.2"] } } }); gpii.flowManager.sessionAware.withSession = function (that, lifecycleManager, onSuccess, failMessage, onError) { onError = onError || that.events.onError.fire; var userSession = lifecycleManager.getSession(); if (!userSession.model.gpiiKey) { failMessage = failMessage || "Error handling request which required active session, but none was active"; onError({ isError: true, statusCode: 401, message: failMessage }); } else { onSuccess(userSession, userSession.model.gpiiKey); } }; })();