From f46a941b61b61af539dd07d6115bc3bf3145f6e7 Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 10 May 2020 06:36:42 +0100 Subject: [PATCH] Add hold period enforcement --- app/Http/Kernel.php | 1 + .../Middleware/ApplicationEligibility.php | 59 ++++++++ .../application-rendering/apply.blade.php | 135 ++++++++++-------- resources/views/dashboard/dashboard.blade.php | 12 ++ resources/views/home.blade.php | 10 +- routes/web.php | 6 +- 6 files changed, 161 insertions(+), 62 deletions(-) create mode 100644 app/Http/Middleware/ApplicationEligibility.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index c3640f3..b81271b 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -62,5 +62,6 @@ class Kernel extends HttpKernel 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, + 'eligibility' => \App\Http\Middleware\ApplicationEligibility::class ]; } diff --git a/app/Http/Middleware/ApplicationEligibility.php b/app/Http/Middleware/ApplicationEligibility.php new file mode 100644 index 0000000..f091d8e --- /dev/null +++ b/app/Http/Middleware/ApplicationEligibility.php @@ -0,0 +1,59 @@ +id)->get(); + $eligible = true; + + $daysRemaining = 0; + + if (!$applications->isEmpty()) + { + foreach ($applications as $application) + { + $appTime = Carbon::parse($application->created_at); + if ($appTime->isSameMonth($curtime)) + { + + Log::warning('Notice: Application ID ' . $application->id . ' was found to be in the same month as today\'s time, making the user ' . Auth::user()->name . ' ineligible for application'); + $eligible = false; + } + } + + $allowedTime = Carbon::parse($applications->last()->created_at)->addMonth(); + $daysRemaining = $allowedTime->diffInDays(now()); + + } + + View::share('isEligibleForApplication', $eligible); + View::share('eligibilityDaysRemaining', $daysRemaining); + } + + + return $next($request); + } +} diff --git a/resources/views/dashboard/application-rendering/apply.blade.php b/resources/views/dashboard/application-rendering/apply.blade.php index cf15541..236b520 100644 --- a/resources/views/dashboard/application-rendering/apply.blade.php +++ b/resources/views/dashboard/application-rendering/apply.blade.php @@ -22,109 +22,119 @@ @endif + @if(!$isEligibleForApplication) + + + + @endif + @stop @section('content') -