mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-25 23:43:58 +00:00
Laravel Vapor - New schedule tasks and commands for token expiration for new user and password reset (sync code from Shipping Portal)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs\Commands\V2;
|
||||
|
||||
use App\Classes\Modules\Accounts\Services\ExpiresPasswordReset;
|
||||
use App\Models\PasswordReset;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PasswordResetTokenExpirationV2CommandJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
Log::info(Carbon::now() . ': Start job - Password reset token expiration check.');
|
||||
$start = new Carbon();
|
||||
|
||||
$attempts = PasswordReset::active()->oneDayOld()->get();
|
||||
|
||||
Log::info('PasswordReset Carbon now()->subHours(24): '. Carbon::now()->subHours(24));
|
||||
Log::info('PasswordReset Attempts count: '.count($attempts));
|
||||
|
||||
foreach ($attempts as $attempt){
|
||||
(new ExpiresPasswordReset())->execute($attempt);
|
||||
Log::info('PasswordReset Expired: '.$attempt->id.', '.$attempt->created_at);
|
||||
}
|
||||
|
||||
$end = new Carbon();
|
||||
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
|
||||
Log::info(Carbon::now() . ': End job - Password reset token expiration check. ElapsedTime: ' . $elapsedTime . '.');
|
||||
}
|
||||
}
|
||||
@@ -76,11 +76,11 @@ class GeneratePasswordResetLogic extends AbstractControllerLogic
|
||||
|
||||
$attempt = $this->generatesPasswordReset->execute($user);
|
||||
|
||||
$this->passwordResetTokenExpiration::dispatch($attempt)->delay(now()->addHours(24));
|
||||
//$this->passwordResetTokenExpiration::dispatch($attempt)->delay(now()->addHours(24)); //converted to schedule task
|
||||
$this->sendResetPasswordEmail::dispatch($user, $attempt);
|
||||
|
||||
return $this->response(['email' => $object->getEmail()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ class GenerateEmailVerificationAttemptProcessor
|
||||
|
||||
$attempt = $this->generatesEmailVerificationAttempt->execute($user);
|
||||
|
||||
// $this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); //cief todo: changed to schedule task (DONE)
|
||||
// $this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); //converted to schedule task
|
||||
|
||||
$this->sendUserVerificationEmail::dispatch($user, $attempt);
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\V2;
|
||||
|
||||
|
||||
use App\Classes\Jobs\Commands\V2\PasswordResetTokenExpirationV2CommandJob;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class PasswordResetTokenExpirationV2Command extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'password-reset-token-expriration-check-command';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Password reset token expiration check.';
|
||||
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
PasswordResetTokenExpirationV2CommandJob::dispatch();
|
||||
}
|
||||
}
|
||||
+11
-8
@@ -33,14 +33,22 @@ class Kernel extends ConsoleKernel
|
||||
//Commands Version 2: Laravel Vapor/AWS
|
||||
$isEnabled = env('COMMANDS_V2_ENABLED', false);
|
||||
if($isEnabled){
|
||||
$schedule->command('dummy-command')
|
||||
->everyFiveMinutes()
|
||||
->withoutOverlapping();
|
||||
// $schedule->command('dummy-command')
|
||||
// ->everyFiveMinutes()
|
||||
// ->withoutOverlapping();
|
||||
|
||||
$schedule->command('housekeeping-s3-files-command')
|
||||
->dailyAt('01:00')
|
||||
->withoutOverlapping();
|
||||
|
||||
$schedule->command('password-reset-token-expriration-check-command')
|
||||
->everySixHours()
|
||||
->withoutOverlapping();
|
||||
|
||||
$schedule->command('new-user-registration-expire-check-command')
|
||||
->everySixHours()
|
||||
->withoutOverlapping();
|
||||
|
||||
if(env('APP_ENV') === 'production'){
|
||||
//cief todo: disable commands to avoid unintentional interfering with production starts
|
||||
// $schedule->command('email-do-to-vt-command')
|
||||
@@ -55,11 +63,6 @@ class Kernel extends ConsoleKernel
|
||||
// ->hourly()
|
||||
// ->withoutOverlapping();
|
||||
|
||||
// $schedule->command('new-user-registration-expire-check-command')
|
||||
// //->dailyAt('23:55') //cief todo: original, to be reverted back to this
|
||||
// ->everyFifteenMinutes()
|
||||
// ->withoutOverlapping();
|
||||
|
||||
// $schedule->command('booking-expired-command')
|
||||
// ->dailyAt('02:00')
|
||||
// ->withoutOverlapping();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PasswordReset extends AbstractModel
|
||||
@@ -22,4 +23,13 @@ class PasswordReset extends AbstractModel
|
||||
public function user(): BelongsTo {
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function scopeOneDayOld($query)
|
||||
{
|
||||
return $query->where('created_at', '<=', Carbon::now()->subHours(24));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user