diff --git a/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php b/app/Classes/Jobs/Commands/V2/PasswordResetTokenExpirationV2CommandJob.php new file mode 100644 index 00000000..93049f5e --- /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(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 . '.'); + } +} diff --git a/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php b/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php index 36b560a6..e799df5b 100644 --- a/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php +++ b/app/Classes/Modules/Accounts/ControllersLogic/GeneratePasswordResetLogic.php @@ -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()]); } } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php b/app/Classes/Modules/Accounts/Processors/GenerateEmailVerificationAttemptProcessor.php index b07b0cc9..fae5b4ae 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: changed to schedule task (DONE) + // $this->emailVerificationAttemptExpiration::dispatch($attempt)->delay(now()->addHours(48)); //converted to schedule task $this->sendUserVerificationEmail::dispatch($user, $attempt); diff --git a/app/Console/Commands/V2/PasswordResetTokenExpirationV2Command.php b/app/Console/Commands/V2/PasswordResetTokenExpirationV2Command.php new file mode 100644 index 00000000..8efae7b4 --- /dev/null +++ b/app/Console/Commands/V2/PasswordResetTokenExpirationV2Command.php @@ -0,0 +1,46 @@ +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(); 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)); + } }