From dcca295c52cd5c0668d21fc12e6ebd122957a86f Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 9 Oct 2024 12:22:50 +0800 Subject: [PATCH] Laravel Vapor - New schedule tasks and commands for token expiration for new user and password reset --- ...serRegistrationExpireCheckV2CommandJob.php | 38 +++++++++++++++ ...sswordResetTokenExpirationV2CommandJob.php | 38 +++++++++++++++ .../CallbackBillplzDataPatchProcessor.php | 4 +- ...ewUserRegistrationExpireCheckV2Command.php | 46 +++++++++++++++++++ .../PasswordResetTokenExpirationV2Command.php | 46 +++++++++++++++++++ app/Console/Kernel.php | 8 ++++ app/Models/PasswordReset.php | 10 ++++ app/Models/UserEmailVerification.php | 10 ++++ 8 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php create mode 100644 app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php create mode 100644 app/Console/Commands/V2/NewUserRegistrationExpireCheckV2Command.php create mode 100644 app/Console/Commands/V2/PasswordResetTokenExpirationV2Command.php diff --git a/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php b/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php new file mode 100644 index 00000000..196d8aa8 --- /dev/null +++ b/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php @@ -0,0 +1,38 @@ +twoDaysOld()->get(); + + Log::info('NewUser Carbon now()->subHours(48): '. Carbon::now()->subHours(48)); + Log::info('NewUser Attempts count: '.count($attempts)); + + foreach ($attempts as $attempt){ + (new ExpiresEmailVerificationAttempt())->execute($attempt); + Log::info('NewUser Expired: '.$attempt->email.', '.$attempt->created_at); + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + Log::info(Carbon::now() . ': End job - New user email verification expiration check. ElapsedTime: ' . $elapsedTime . '.'); + } +} diff --git a/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php b/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php new file mode 100644 index 00000000..a11b8ba1 --- /dev/null +++ b/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php @@ -0,0 +1,38 @@ +oneDayOld()->get(); + + Log::info('PasswordReset Carbon now()->subHours(24): '. Carbon::now()->subHours(48)); + Log::info('PasswordReset Attempts count: '.count($attempts)); + + foreach ($attempts as $attempt){ + //(new ExpiresPasswordReset())->execute($attempt); + Log::info('PasswordReset Expired: '.$attempt->email.', '.$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 . '.'); + } +} diff --git a/app/Classes/Modules/Billplzs/Processors/CallbackBillplzDataPatchProcessor.php b/app/Classes/Modules/Billplzs/Processors/CallbackBillplzDataPatchProcessor.php index 9843a0d9..7bbd0e82 100644 --- a/app/Classes/Modules/Billplzs/Processors/CallbackBillplzDataPatchProcessor.php +++ b/app/Classes/Modules/Billplzs/Processors/CallbackBillplzDataPatchProcessor.php @@ -130,8 +130,8 @@ class CallbackBillplzDataPatchProcessor } else{ - Log::channel('storage_invoices')->info('Total amount from current transaction: '.$totalAmountToBePaid); //cief todo: to be removed - Log::channel('storage_invoices')->info('Total amount from paid transaction: '.$transaction->amount); //cief todo: to be removed + Log::channel('storage_invoices')->info('Total amount from current transaction: '.$totalAmountToBePaid); + Log::channel('storage_invoices')->info('Total amount from paid transaction: '.$transaction->amount); return false; } } diff --git a/app/Console/Commands/V2/NewUserRegistrationExpireCheckV2Command.php b/app/Console/Commands/V2/NewUserRegistrationExpireCheckV2Command.php new file mode 100644 index 00000000..a74b6bf5 --- /dev/null +++ b/app/Console/Commands/V2/NewUserRegistrationExpireCheckV2Command.php @@ -0,0 +1,46 @@ +dailyAt('01:00') ->withoutOverlapping(); + $schedule->command('password-reset-token-expriration-check-command') + ->everyFiveMinutes() + ->withoutOverlapping(); + + $schedule->command('new-user-registration-expire-check-command') + ->everyFiveMinutes() + ->withoutOverlapping(); + if(env('APP_ENV') === 'production'){ $schedule->command('curl-vt-command') ->cron('0 8 * * *') diff --git a/app/Models/PasswordReset.php b/app/Models/PasswordReset.php index 6ab27179..e22e85a0 100644 --- a/app/Models/PasswordReset.php +++ b/app/Models/PasswordReset.php @@ -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)); + } } diff --git a/app/Models/UserEmailVerification.php b/app/Models/UserEmailVerification.php index 278c8cd6..a89627af 100644 --- a/app/Models/UserEmailVerification.php +++ b/app/Models/UserEmailVerification.php @@ -2,6 +2,7 @@ namespace App\Models; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Relations\BelongsTo; class UserEmailVerification extends AbstractModel @@ -25,4 +26,13 @@ class UserEmailVerification extends AbstractModel public function user(): BelongsTo { return $this->belongsTo(User::class, 'email', 'email'); } + + /** + * @param $query + * @return mixed + */ + public function scopeTwoDaysOld($query) + { + return $query->where('created_at', '<=', Carbon::now()->subHours(48)); + } }