From c2209690ad0c60e4504fa621ff6b610b8c40e7ab Mon Sep 17 00:00:00 2001 From: Findeton Date: Sun, 30 Jun 2024 11:54:26 -0500 Subject: [PATCH] wip --- avRegistration/auth-method-service.js | 23 +++++++++++------- dist/appCommon-v10.4.2.js | 34 +++++++++++++-------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/avRegistration/auth-method-service.js b/avRegistration/auth-method-service.js index 55d65735..53df3508 100644 --- a/avRegistration/auth-method-service.js +++ b/avRegistration/auth-method-service.js @@ -109,20 +109,25 @@ angular.module('avRegistration') return secondsDifference; } - function getAllTokens() { + function getAllTokens(isAdmin) { var credentialsStr = $window.sessionStorage.getItem("vote_permission_tokens"); + var tokens = []; if (credentialsStr) { var credentials = JSON.parse(credentialsStr); - var tokens = credentials.map(function (credential) { return credential.token; }); - tokens.push($http.defaults.headers.common.Authorization); + tokens = credentials.map(function (credential) { return credential.token; }); return tokens; - } else { - return [$http.defaults.headers.common.Authorization]; } + if (isAdmin) { + tokens.push($http.defaults.headers.common.Authorization); + } + return tokens; } - function hasPassedHalfLifeExpiry(now) { - var tokens = getAllTokens(); + function hasPassedHalfLifeExpiry(now, isAdmin) { + var tokens = getAllTokens(isAdmin); + if (0 === tokens.length) { + return false; + } var halfLifes = tokens.map(function (token) { var decodedToken = authmethod.decodeToken(token); return 1000 * (decodedToken.expiry_timestamp + decodedToken.create_timestamp)/2; @@ -145,7 +150,7 @@ angular.module('avRegistration') // Only try to renew token when it's older than 50% of // the expiration time var now = new Date(); - if (!hasPassedHalfLifeExpiry(now.getTime())) { + if (!hasPassedHalfLifeExpiry(now.getTime(), isAdmin)) { return; } authmethod.lastAuthDate = now; @@ -832,6 +837,7 @@ angular.module('avRegistration') var postfix = "_authevent_" + autheventid; // ping daemon is not active for normal users + /* if (!authmethod.admin) { var hasGracefulPeriod = window.sessionStorage.getItem('hasGracefulPeriod'); if (hasGracefulPeriod === "true") { @@ -839,6 +845,7 @@ angular.module('avRegistration') return deferred.promise; } } + */ // if document is hidden, then do not update the cookie, and redirect // to admin logout if cookie expired if (document.visibilityState === 'hidden') { diff --git a/dist/appCommon-v10.4.2.js b/dist/appCommon-v10.4.2.js index 7dfbec9a..c2a945f7 100644 --- a/dist/appCommon-v10.4.2.js +++ b/dist/appCommon-v10.4.2.js @@ -5,21 +5,20 @@ 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", "$window", "ConfigService", "$interval", "$state", "$location", "$document", "$q", function($http, $cookies, $window, ConfigService, $interval, $state, $location, $document, $q) { var backendUrl = ConfigService.authAPI, authId = ConfigService.freeAuthId, authmethod = {}; - function hasPassedHalfLifeExpiry(now) { - var halfLifes = function() { - var tokens = $window.sessionStorage.getItem("vote_permission_tokens"); - if (tokens) { - tokens = JSON.parse(tokens).map(function(credential) { - return credential.token; - }); - return tokens.push($http.defaults.headers.common.Authorization), tokens; - } - return [ $http.defaults.headers.common.Authorization ]; - }().map(function(decodedToken) { - decodedToken = authmethod.decodeToken(decodedToken); - return 1e3 * (decodedToken.expiry_timestamp + decodedToken.create_timestamp) / 2; - }); - return Math.min.apply(null, halfLifes) < now; + function hasPassedHalfLifeExpiry(now, halfLifes) { + halfLifes = function(isAdmin) { + var credentialsStr = $window.sessionStorage.getItem("vote_permission_tokens"), tokens = []; + return credentialsStr ? JSON.parse(credentialsStr).map(function(credential) { + return credential.token; + }) : (isAdmin && tokens.push($http.defaults.headers.common.Authorization), tokens); + }(halfLifes); + if (0 !== halfLifes.length) { + halfLifes = halfLifes.map(function(decodedToken) { + decodedToken = authmethod.decodeToken(decodedToken); + return 1e3 * (decodedToken.expiry_timestamp + decodedToken.create_timestamp) / 2; + }); + return Math.min.apply(null, halfLifes) < now; + } } return authmethod.captcha_code = null, authmethod.captcha_image_url = "", authmethod.captcha_status = "", authmethod.admin = !1, authmethod.decodeToken = function(createTimestamp) { @@ -47,7 +46,8 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist authmethod.lastAuthDate = new Date(), !authmethod.iddleDetectionSetup) return authmethod.iddleDetectionSetup = !0, callback = function() { var now = new Date(); - hasPassedHalfLifeExpiry(now.getTime()) && (authmethod.lastAuthDate = now, authmethod.refreshAuthToken(autheventid)); + hasPassedHalfLifeExpiry(now.getTime(), isAdmin) && (authmethod.lastAuthDate = now, + authmethod.refreshAuthToken(autheventid)); }, [ "click", "keypress", "mousemove", "mousedown", "touchstart", "touchmove" ].forEach(function(event) { document.addEventListener(event, callback); }), !1; @@ -353,8 +353,6 @@ angular.module("avRegistration").config(function() {}), angular.module("avRegist return $http.post(url, data); }, authmethod.refreshAuthToken = function(autheventid) { var deferred = $q.defer(), postfix = "_authevent_" + autheventid; - if (!authmethod.admin && "true" === window.sessionStorage.getItem("hasGracefulPeriod")) 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(), sessionStartedAtMs = now;