Skip to content

Commit

Permalink
Merge branch 'master' into contest-judging
Browse files Browse the repository at this point in the history
  • Loading branch information
venix12 authored Nov 30, 2023
2 parents b68a1dd + 1c8aeed commit de8e1ef
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Kernel extends HttpKernel
Middleware\AuthApi::class,
Middleware\SetLocaleApi::class,
Middleware\CheckUserBanStatus::class,
Middleware\UpdateUserLastvisit::class,
],
'web' => [
Middleware\StripCookies::class,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/AuthApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private function validTokenFromRequest($psr)
throw new AuthenticationException('invalid token');
}

$token->setRelation('client', $client);
$token->validate();

$user = $token->getResourceOwner();
Expand Down
32 changes: 19 additions & 13 deletions app/Http/Middleware/UpdateUserLastvisit.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,30 @@ public function handle($request, Closure $next)
$user = $this->auth->user();

if ($user !== null) {
$isInactive = $user->isInactive();
$token = $user->token();
$shouldUpdate = $token === null || $token->client->password_client;

if ($isInactive) {
$isVerified = $user->isSessionVerified();
}
if ($shouldUpdate) {
$isInactive = $user->isInactive();
if ($isInactive) {
$isVerified = $user->isSessionVerified();
}

if (!$isInactive || $isVerified) {
$recordedLastVisit = $user->getRawAttribute('user_lastvisit');
$currentLastVisit = time();
if (!$isInactive || $isVerified) {
$recordedLastVisit = $user->getRawAttribute('user_lastvisit');
$currentLastVisit = time();

if ($currentLastVisit - $recordedLastVisit > 300) {
$user->update([
'user_lastvisit' => $currentLastVisit,
], ['skipValidations' => true]);
if ($currentLastVisit - $recordedLastVisit > 300) {
$user->update([
'user_lastvisit' => $currentLastVisit,
], ['skipValidations' => true]);
}
}
}

$this->recordSession($request);
if ($token === null) {
$this->recordSession($request);
}
}
}

return $next($request);
Expand Down

0 comments on commit de8e1ef

Please sign in to comment.