Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Findeton committed Jun 30, 2024
1 parent de36391 commit c220969
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
23 changes: 15 additions & 8 deletions avRegistration/auth-method-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -832,13 +837,15 @@ 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") {
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
if (document.visibilityState === 'hidden') {
Expand Down
34 changes: 16 additions & 18 deletions dist/appCommon-v10.4.2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c220969

Please sign in to comment.