// scope module is load statically before any route is cativated
angular.module('TokenRefresh', ['AppConfig', 'ModalNotification'])
- .directive ('tokenRefresh', function($window, $timeout, $location, Notification, AppConfig, AppCall) {
+ .directive ('tokenRefresh', function($log, $window, $timeout, $location, Notification, AppConfig, AppCall) {
function mymethods(scope, elem, attrs) {
scope.logged=undefined; // neither thu neither false
$window.onbeforeunload = function () {
- AppCall.get ("token", "reset", {/*query*/}, function () {
- console.log("OPA Exit Requested");
+ AppCall.get ("token", "reset", {/*query*/}, function () {
+ $log.log("OPA exit");
});
};
};
scope.onsuccess = function(jresp) {
+
+ if (jresp.request.status !== "success") {
+ Notification.warning ({message: jresp.request.info, delay: 5000});
+ scope.offline();
+ return;
+ }
+
if (jresp.request.token) AppConfig.session.token = jresp.request.token;
if (jresp.request.uuid) AppConfig.session.uuid = jresp.request.uuid;
if (jresp.request.timeout) AppConfig.session.timeout = jresp.request.timeout;
// Check Binder status
scope.getping = function() {
- AppCall.get ("token", "ping", {/*query*/},function(result) {
- if (result.status === 200) scope.onsuccess (result.data);
- else scope.onerror();
+ AppCall.get ("token", "ping", {/*query*/},function(jresp, errcode) {
+ if (errcode) scope.onerror();
+ else scope.onsuccess (jresp);
// restart a new timer for next ping
$timeout (scope.getping, AppConfig.session.pingrate*1000);
});
// Check Binder status
scope.refresh = function() {
- AppCall.get ("token", "refresh", {/*query*/},function(result) {
- if (result.status === 200) scope.onsuccess (result.data);
- else scope.onerror();
+ AppCall.get ("token", "refresh", {/*query*/},function(jresp, errcode) {
+ if (errcode) scope.onerror();
+ else scope.onsuccess (jresp);
// restart a new timer for next refresh
$timeout (scope.refresh, AppConfig.session.timeout *250);
});
// Initial connection
scope.tkcreate = function() {
- AppCall.get ("token", "create", {token: AppConfig.session.initial},function(result) {
- if (result.status === 200) scope.onsuccess (result.data);
- else scope.onerror();
+ AppCall.get ("token", "create", {token: AppConfig.session.initial},function(jresp, errcode) {
+ if (errcode) scope.onerror();
+ else scope.onsuccess (jresp);
});
};