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

Expiring passwords command, order of billboards #35

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions app/Console/Commands/CheckForExpiredOneTimePasswords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Console\Commands;

use App\Models\OneTimePassword;
use Illuminate\Console\Command;

class CheckForExpiredOneTimePasswords extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:check-for-expired-one-time-passwords';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Check for expired one-time passwords and change status to expired.';

/**
* Execute the console command.
*/
public function handle()
{
//
$this->info('Checking for expired one-time passwords...');
$expiredOneTimePasswords = OneTimePassword::where('expires_at', '<', now())
->where('status', 'pending')
->get();
$expiredOneTimePasswords->each(function ($otp) {
$otp->update(['status' => 'expired']);
});
$this->info('Expired one-time passwords checked and updated.');
}
}
10 changes: 8 additions & 2 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;

class Kernel extends ConsoleKernel
{
Expand All @@ -12,9 +13,14 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('sanctum:prune-expired --hours=24')->daily();
//delete expired otps
$schedule->command('app:check-for-expired-one-time-passwords')->everyMinute()
->onSuccess(function () {
Log::info('Expired one-time passwords checked and updated.');
})
->onFailure(function () {
Log::error('Expired one-time passwords check failed.');
});
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/BillboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function agentBillboards(Request $request)
return response()->json([
'billboards' => $agent->billboards()
->active()
->orderBy('updated_at', 'desc')
->with('district:id,name')
->get()

Expand Down
12 changes: 11 additions & 1 deletion app/Models/Billboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,24 @@ public static function boot()
protected $hidden = [
'created_at',
'deleted_at',
'created_by',
'updated_at',
'district_id',
];

protected $casts = [
'is_active' => 'boolean',
];

protected $appends = [
'updated_at_human',
];

public function getUpdatedAtHumanAttribute()
{
return $this->updated_at->diffForHumans();
}

//Scope Active
public function scopeActive($query)
{
return $query->where('is_active', true);
Expand Down