From dcca295c52cd5c0668d21fc12e6ebd122957a86f Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 9 Oct 2024 12:22:50 +0800 Subject: [PATCH 1/3] 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)); + } } From 7953de1f7d2418281c08ac4f9c6fa8d26aa4abaf Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 9 Oct 2024 12:52:25 +0800 Subject: [PATCH 2/3] Laravel Vapor - New schedule tasks and commands for token expiration for new user and password reset --- .../V2/PasswordResetTokenExpirationV2CommandJob.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php b/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php index a11b8ba1..93049f5e 100644 --- a/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php +++ b/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php @@ -23,12 +23,12 @@ class PasswordResetTokenExpirationV2CommandJob implements ShouldQueue $attempts = PasswordReset::active()->oneDayOld()->get(); - Log::info('PasswordReset Carbon now()->subHours(24): '. Carbon::now()->subHours(48)); + 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->email.', '.$attempt->created_at); + (new ExpiresPasswordReset())->execute($attempt); + Log::info('PasswordReset Expired: '.$attempt->id.', '.$attempt->created_at); } $end = new Carbon(); From 497666e582eb5d19b8be18cf1eb9bb1bf62f1d8d Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 9 Oct 2024 13:13:28 +0800 Subject: [PATCH 3/3] Laravel Vapor - New schedule tasks and commands for token expiration for new user and password reset --- .../V2/NewUserRegistrationExpireCheckV2CommandJob.php | 2 +- .../Accounts/ControllersLogic/GeneratePasswordResetLogic.php | 2 +- .../Processors/GenerateEmailVerificationAttemptProcessor.php | 2 +- app/Console/Kernel.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php b/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php index 196d8aa8..3170611a 100644 --- a/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php +++ b/app/Classes/Jobs/Commands/V2/NewUserRegistrationExpireCheckV2CommandJob.php @@ -28,7 +28,7 @@ class NewUserRegistrationExpireCheckV2CommandJob implements ShouldQueue foreach ($attempts as $attempt){ (new ExpiresEmailVerificationAttempt())->execute($attempt); - Log::info('NewUser Expired: '.$attempt->email.', '.$attempt->created_at); + Log::info('NewUser Expired: '.$attempt->id.', '.$attempt->created_at); } $end = new Carbon(); diff --git a/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php index f3255138..b397041b 100644 --- a/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php +++ b/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php @@ -77,7 +77,7 @@ class GeneratePasswordResetLogic extends AbstractControllerLogic $attempt = $this->generatesPasswordReset->execute($user); - // $this->passwordResetTokenExpiration::dispatch($attempt)->delay(now()->addHours(24)); // cief todo: to convert to schedule task + // $this->passwordResetTokenExpiration::dispatch($attempt)->delay(now()->addHours(24)); //converted to schedule task $this->sendResetPasswordEmail::dispatch($user, $attempt); return $this->response(['email' => $object->getEmail()]); diff --git a/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php index bd15c786..18531684 100644 --- a/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php +++ b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php @@ -50,7 +50,7 @@ class GenerateEmailVerificationAttemptProcessor $attempt = $this->generatesEmailVerificationAttempt->execute($user); - //$this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); // cief todo: to convert to schedule task + //$this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); //converted to schedule task $this->sendUserVerificationEmail::dispatch($user, $attempt); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e955de62..a3b83314 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -39,11 +39,11 @@ class Kernel extends ConsoleKernel ->withoutOverlapping(); $schedule->command('password-reset-token-expriration-check-command') - ->everyFiveMinutes() + ->everySixHours() ->withoutOverlapping(); $schedule->command('new-user-registration-expire-check-command') - ->everyFiveMinutes() + ->everySixHours() ->withoutOverlapping(); if(env('APP_ENV') === 'production'){