From 43e6cec200024e0f0d17a529e4cdc13029246f6a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 23 Jun 2020 09:09:23 -0400 Subject: [PATCH 1/2] Update user.login_date for authenticated API calls --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index d314988ed8..ba87c8c366 100644 --- a/include/api.php +++ b/include/api.php @@ -264,7 +264,7 @@ function api_login(App $a) throw new UnauthorizedException("This API requires login"); } - DI::auth()->setForUser($a, $record); + DI::auth()->setForUser($a, $record, false, false, true); $_SESSION["allow_api"] = true; From 677eaf78ed657e309edc95899f0c3682bd67679b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 23 Jun 2020 10:15:39 -0400 Subject: [PATCH 2/2] Add API login capture 12h cooldown to spare database writes --- include/api.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index ba87c8c366..e69fefa27a 100644 --- a/include/api.php +++ b/include/api.php @@ -264,7 +264,10 @@ function api_login(App $a) throw new UnauthorizedException("This API requires login"); } - DI::auth()->setForUser($a, $record, false, false, true); + // Don't refresh the login date more often than twice a day to spare database writes + $login_refresh = strcmp(DateTimeFormat::utc('now - 12 hours'), $record['login_date']) > 0; + + DI::auth()->setForUser($a, $record, false, false, $login_refresh); $_SESSION["allow_api"] = true;