Skip to content

Commit

Permalink
Merge pull request #35 from MariaInsyt/arthur
Browse files Browse the repository at this point in the history
Expiring passwords command, order of billboards
  • Loading branch information
kyagie committed Mar 6, 2024
2 parents 27ed023 + df06638 commit d46782e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
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

0 comments on commit d46782e

Please sign in to comment.