From 38efd774d833f2fe82e4beb0f8688386c3660c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Robles?= Date: Wed, 19 Jul 2023 15:17:08 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20add=20census=20data=20second=20b?= =?UTF-8?q?atch=20will=20not=20be=20executed=20(#322)=20(#329)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parent issue: https://github.com/sequentech/meta/issues/119 --- SequentConfig.js | 6 ++++++ avRegistration/auth-method-service.js | 21 ++++++++++++++++----- dist/SequentConfig-v9.0.0.js | 6 ++++++ dist/appCommon-v9.0.0.js | 20 ++++++++++++++------ 4 files changed, 42 insertions(+), 11 deletions(-) diff --git a/SequentConfig.js b/SequentConfig.js index fa59b7f8..cc59e62e 100644 --- a/SequentConfig.js +++ b/SequentConfig.js @@ -151,6 +151,12 @@ var SequentConfigData = { // Information regarding OpenID Connect authentication openIDConnectProviders: [], + //Minimum loading time (milliseconds) + minLoadingTime: 12000, + + // Server timeout (seconds) + serverTimeoutSeconds: 200, + // contact data where users can reach to a human when they need it contact: { // Support contact email displayed in the footer links diff --git a/avRegistration/auth-method-service.js b/avRegistration/auth-method-service.js index b2acd552..97bb26cd 100644 --- a/avRegistration/auth-method-service.js +++ b/avRegistration/auth-method-service.js @@ -24,7 +24,8 @@ angular.module('avRegistration') $interval, $state, $location, - $document + $document, + $q ) { var backendUrl = ConfigService.authAPI; var authId = ConfigService.freeAuthId; @@ -387,7 +388,14 @@ angular.module('avRegistration') "field-validation": validation, "census": data }; - return $http.post(backendUrl + 'auth-event/' + id + '/census/', d); + var url = backendUrl + 'auth-event/' + id + '/census/'; + + return $http({ + method : "POST", + url : url, + timeout: ConfigService.serverTimeoutSeconds * 1000, + data: d + }); }; authmethod.getCensus = function(id, params) { @@ -710,11 +718,13 @@ angular.module('avRegistration') }; authmethod.launchPingDaemon = function(autheventid) { + var deferred = $q.defer(); var postfix = "_authevent_" + autheventid; // ping daemon is not active for normal users if (!authmethod.admin) { - return; + deferred.reject("not an admin"); + return deferred.promise; } // if document is hidden, then do not update the cookie, and redirect // to admin logout if cookie expired @@ -722,10 +732,11 @@ angular.module('avRegistration') if (!$cookies.get("auth" + postfix)) { $state.go("admin.logout"); } - return; + deferred.reject("tab not focused"); + return deferred.promise; } var now = Date.now(); - authmethod.ping() + return authmethod.ping() .then(function(response) { var options = {}; if (ConfigService.authTokenExpirationSeconds) { diff --git a/dist/SequentConfig-v9.0.0.js b/dist/SequentConfig-v9.0.0.js index fa59b7f8..cc59e62e 100644 --- a/dist/SequentConfig-v9.0.0.js +++ b/dist/SequentConfig-v9.0.0.js @@ -151,6 +151,12 @@ var SequentConfigData = { // Information regarding OpenID Connect authentication openIDConnectProviders: [], + //Minimum loading time (milliseconds) + minLoadingTime: 12000, + + // Server timeout (seconds) + serverTimeoutSeconds: 200, + // contact data where users can reach to a human when they need it contact: { // Support contact email displayed in the footer links diff --git a/dist/appCommon-v9.0.0.js b/dist/appCommon-v9.0.0.js index 0bf48ab1..2caf5471 100644 --- a/dist/appCommon-v9.0.0.js +++ b/dist/appCommon-v9.0.0.js @@ -3,7 +3,7 @@ function $buo_f() { } if (angular.module("avRegistration", [ "ui.bootstrap", "ui.utils", "ui.router" ]), -angular.module("avRegistration").config(function() {}), angular.module("avRegistration").factory("Authmethod", [ "$http", "$cookies", "ConfigService", "$interval", "$state", "$location", "$document", function($http, $cookies, ConfigService, $interval, $state, $location, $document) { +angular.module("avRegistration").config(function() {}), angular.module("avRegistration").factory("Authmethod", [ "$http", "$cookies", "ConfigService", "$interval", "$state", "$location", "$document", "$q", function($http, $cookies, ConfigService, $interval, $state, $location, $document, $q) { var backendUrl = ConfigService.authAPI, authId = ConfigService.freeAuthId, authmethod = { captcha_code: null, captcha_image_url: "", @@ -199,7 +199,12 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist "field-validation": validation = !angular.isDefined(validation) ? "enabled" : validation, census: d }; - return $http.post(backendUrl + "auth-event/" + id + "/census/", d); + return $http({ + method: "POST", + url: backendUrl + "auth-event/" + id + "/census/", + timeout: 1e3 * ConfigService.serverTimeoutSeconds, + data: d + }); }, getCensus: function(id, params) { return angular.isObject(params) ? $http.get(backendUrl + "auth-event/" + id + "/census/", { @@ -363,15 +368,18 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist return $http.post(url, data); }, launchPingDaemon: function(autheventid) { - var now, postfix = "_authevent_" + autheventid; - authmethod.admin && ("hidden" !== document.visibilityState ? (now = Date.now(), - authmethod.ping().then(function(response) { + var deferred = $q.defer(), postfix = "_authevent_" + autheventid; + if (!authmethod.admin) return deferred.reject("not an admin"), deferred.promise; + if ("hidden" === document.visibilityState) return $cookies.get("auth" + postfix) || $state.go("admin.logout"), + deferred.reject("tab not focused"), deferred.promise; + var now = Date.now(); + return authmethod.ping().then(function(response) { var options = {}; ConfigService.authTokenExpirationSeconds && (options.expires = new Date(now + 1e3 * ConfigService.authTokenExpirationSeconds)), $cookies.put("auth" + postfix, response.data["auth-token"], options), $cookies.put("isAdmin" + postfix, $cookies.get("isAdmin" + postfix), options), $cookies.put("userid" + postfix, $cookies.get("userid" + postfix), options), $cookies.put("userid" + postfix, $cookies.get("userid" + postfix), options), $cookies.put("user" + postfix, $cookies.get("user" + postfix), options), authmethod.setAuth($cookies.get("auth" + postfix), $cookies.get("isAdmin" + postfix), autheventid); - })) : $cookies.get("auth" + postfix) || $state.go("admin.logout")); + }); }, getUserDraft: function() { if (authmethod.isLoggedIn()) return $http.get(backendUrl + "user/draft/", {});