Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user created timestamp not cast to Carbon #1954

Merged
merged 7 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/Api/Middleware/LogApiUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function handle(Request $request, Closure $next): mixed
/** @var User $user */
$user = $request->user('api-token');

$user->timestamps = false;
$user->increment('APIUses');

return $next($request);
Expand Down
41 changes: 21 additions & 20 deletions app/Helpers/database/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,36 @@
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

function isAllowedToSubmitTickets(string $user): bool
function isAllowedToSubmitTickets(string $username): bool
{
if (!isValidUsername($user)) {
if (!isValidUsername($username)) {
return false;
}

$cacheKey = CacheKey::buildUserCanTicketCacheKey($user);
$cacheKey = CacheKey::buildUserCanTicketCacheKey($username);

$value = Cache::get($cacheKey);
if ($value !== null) {
return $value;
if (Cache::has($cacheKey)) {
return Cache::get($cacheKey);
Jamiras marked this conversation as resolved.
Show resolved Hide resolved
}

$value = getUserActivityRange($user, $firstLogin, $lastLogin)
&& time() - strtotime($firstLogin) > 86400 // 86400 seconds = 1 day
&& getRecentlyPlayedGames($user, 0, 1, $userInfo)
$user = User::firstWhere('User', $username);
$isAllowed = $user->Created->diffInDays() > 1
&& getRecentlyPlayedGames($username, 0, 1, $userInfo)
&& $userInfo[0]['GameID'];

if ($value) {
// if the user can create tickets, they should be able to create tickets forever
// more. expire once every 30 days so we can purge inactive users
Cache::put($cacheKey, $value, Carbon::now()->addDays(30));
} else {
// user can't create tickets, which means the account is less than a day old
// or has no games played. only cache the value for an hour
Cache::put($cacheKey, $value, Carbon::now()->addHour());
}

return $value;
Cache::put(
$cacheKey,
$isAllowed,
$isAllowed
// if the user can create tickets, they should be able to create tickets forever
// more. expire once every 30 days so we can purge inactive users
? Carbon::now()->addDays(30)
// user can't create tickets, which means the account is less than a day old
// or has no games played. only cache the value for an hour
: Carbon::now()->addHour()
);

return $isAllowed;
}

function submitNewTicketsJSON(
Expand Down
1 change: 0 additions & 1 deletion app/Helpers/database/user-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ function postActivity(string|User $userIn, int $type, ?int $data = null, ?int $d
// update UserAccount
$user->LastLogin = Carbon::now();
$user->LastActivityID = $activity->ID;
$user->timestamps = false;
$user->save();

return true;
Expand Down
2 changes: 0 additions & 2 deletions app/Helpers/database/user-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function authenticateForConnect(?string $username, ?string $pass = null, ?string

// update appTokenExpiry
$user->appTokenExpiry = Carbon::now()->clone()->addDays(14);
$user->timestamps = false;
$user->save();

postActivity($user, ActivityType::Login);
Expand Down Expand Up @@ -208,7 +207,6 @@ function authenticateFromCookie(

// valid active account. update the last activity timestamp
$user->LastLogin = Carbon::now();
$user->timestamps = false;
$user->save();

// validate permissions for the current page if required
Expand Down
Loading