Add hold period enforcement
This commit is contained in:
parent
cf7cc142a7
commit
f46a941b61
|
@ -62,5 +62,6 @@ class Kernel extends HttpKernel
|
||||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
'eligibility' => \App\Http\Middleware\ApplicationEligibility::class
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use App\Application;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Closure;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
|
||||||
|
class ApplicationEligibility
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
$curtime = new Carbon(now());
|
||||||
|
|
||||||
|
|
||||||
|
if (Auth::check())
|
||||||
|
{
|
||||||
|
$applications = Application::where('applicantUserID', Auth::user()->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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,109 +22,119 @@
|
||||||
|
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if(!$isEligibleForApplication)
|
||||||
|
|
||||||
|
<script>toastr.error("You do not have permission to view this page.", "Access denied")</script>
|
||||||
|
|
||||||
|
@endif
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
<div class="modal fade" tabindex="-1" id="confirm" role="dialog" aria-labelledby="modalConfirmLabel" aria-hidden="true">
|
@if($isEligibleForApplication)
|
||||||
<div class="modal-dialog" role="document">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title" id="modalConfirmLabel">Please confirm</h5>
|
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
||||||
<span aria-hidden="true">×</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body">
|
|
||||||
|
|
||||||
<p>Are you sure you want to submit your application? Please review each of your answers carefully before doing so.</p>
|
<div class="modal fade" tabindex="-1" id="confirm" role="dialog" aria-labelledby="modalConfirmLabel" aria-hidden="true">
|
||||||
<p class="text-bold">Please note: Applications CANNOT be modified once they're submitted!</p>
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="modalConfirmLabel">Please confirm</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
</div>
|
<p>Are you sure you want to submit your application? Please review each of your answers carefully before doing so.</p>
|
||||||
<div class="modal-footer">
|
<p class="text-bold">Please note: Applications CANNOT be modified once they're submitted!</p>
|
||||||
<button type="button" class="btn btn-success" onclick="document.getElementById('submitApplicationForm').submit()"><i class="fas fa-check-double"></i> Accept & Send</button>
|
|
||||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">Review</button>
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-success" onclick="document.getElementById('submitApplicationForm').submit()"><i class="fas fa-check-double"></i> Accept & Send</button>
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Review</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
||||||
<div class="callout callout-success">
|
<div class="callout callout-success">
|
||||||
|
|
||||||
<p class="text-bold">You are applying for: {{$vacancy->vacancyName}}</p>
|
<p class="text-bold">You are applying for: {{$vacancy->vacancyName}}</p>
|
||||||
|
|
||||||
<p>We're glad you've decided to apply. Generally, applications take 48 hours to be processed and reviewed. Depending on the circumstances and the volume of applications, you may receive an answer in a shorter time.</p>
|
<p>We're glad you've decided to apply. Generally, applications take 48 hours to be processed and reviewed. Depending on the circumstances and the volume of applications, you may receive an answer in a shorter time.</p>
|
||||||
<p>Please fill out the form below. Keep all answers concise and complete. Please keep in mind that the age requirement is <b>at least 18 years old</b>.</p>
|
<p>Please fill out the form below. Keep all answers concise and complete. Please keep in mind that the age requirement is <b>at least 18 years old</b>.</p>
|
||||||
<p class="text-bold">Asking about your application will result in instant denial. Everything you need to know is here.</p>
|
<p class="text-bold">Asking about your application will result in instant denial. Everything you need to know is here.</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col">
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="card">
|
||||||
|
|
||||||
<div class="col">
|
<div class="card-header">
|
||||||
|
|
||||||
|
<div class="card-title"><h4>{{$vacancy->forms->formName}}</h4></div>
|
||||||
|
|
||||||
<div class="card">
|
</div>
|
||||||
|
|
||||||
<div class="card-header">
|
<div class="card-body">
|
||||||
|
|
||||||
<div class="card-title"><h4>{{$vacancy->forms->formName}}</h4></div>
|
<form action="{{route('saveApplicationForm', ['vacancySlug' => $vacancy->vacancySlug])}}" method="POST" id="submitApplicationForm">
|
||||||
|
@csrf
|
||||||
|
@foreach($preprocessedForm['fields'] as $fieldName => $field)
|
||||||
|
|
||||||
</div>
|
@switch ($field['type'])
|
||||||
|
|
||||||
<div class="card-body">
|
@case('textarea')
|
||||||
|
|
||||||
<form action="{{route('saveApplicationForm', ['vacancySlug' => $vacancy->vacancySlug])}}" method="POST" id="submitApplicationForm">
|
<div class="form-group mt-2 mb-2">
|
||||||
@csrf
|
|
||||||
@foreach($preprocessedForm['fields'] as $fieldName => $field)
|
|
||||||
|
|
||||||
@switch ($field['type'])
|
<label for="{{$fieldName}}">{{$field['title']}}</label>
|
||||||
|
<textarea class="form-control" rows="7" name="{{$fieldName}}" id="{{$fieldName}}">
|
||||||
@case('textarea')
|
|
||||||
|
|
||||||
<div class="form-group mt-2 mb-2">
|
|
||||||
|
|
||||||
<label for="{{$fieldName}}">{{$field['title']}}</label>
|
|
||||||
<textarea class="form-control" rows="7" name="{{$fieldName}}" id="{{$fieldName}}">
|
|
||||||
|
|
||||||
</textarea>
|
</textarea>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@break
|
@break
|
||||||
|
|
||||||
@case('textbox')
|
@case('textbox')
|
||||||
|
|
||||||
<div class="form-group mt-2 mb-2">
|
<div class="form-group mt-2 mb-2">
|
||||||
|
|
||||||
<label for="{{$fieldName}}">{{$field['title']}}</label>
|
<label for="{{$fieldName}}">{{$field['title']}}</label>
|
||||||
<input type="text" name="{{$fieldName}}" id="{{$fieldName}}" class="form-control">
|
<input type="text" name="{{$fieldName}}" id="{{$fieldName}}" class="form-control">
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@break
|
@break
|
||||||
|
|
||||||
@endswitch
|
@endswitch
|
||||||
|
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-footer text-center">
|
<div class="card-footer text-center">
|
||||||
|
|
||||||
<button type="button" class="btn btn-success" onclick="$('#confirm').modal('show')"><i class="fas fa-paper-plane"></i> Send</button>
|
<button type="button" class="btn btn-success" onclick="$('#confirm').modal('show')"><i class="fas fa-paper-plane"></i> Send</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -132,6 +142,15 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
@else
|
||||||
|
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
|
||||||
|
<p class="text-bold">Access denied</p>
|
||||||
|
|
||||||
|
<p>Your account is not permitted to submit another application. Please wait {{$eligibilityDaysRemaining}} more days before trying to submit an application.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endif
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
|
|
@ -40,4 +40,16 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col">
|
||||||
|
<div class="alert alert-info">
|
||||||
|
|
||||||
|
<p>Your current application eligibility status: <span class="badge badge-warning">{{($isEligibleForApplication) ? 'Eligibile' : 'Ineligible' }}</span></p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
@stop
|
@stop
|
||||||
|
|
|
@ -48,8 +48,16 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-footer text-center">
|
<div class="card-footer text-center">
|
||||||
|
@auth
|
||||||
|
<button {{($isEligibleForApplication) ? '' : 'disabled'}} type="button" class="btn btn-success" onclick="window.location.href='{{route('renderApplicationForm', ['vacancySlug' => $position->vacancySlug])}}'">Apply</button>
|
||||||
|
@if(!$isEligibleForApplication)
|
||||||
|
<span class="badge-warning badge"><i class="fa fa-info"></i> Ineligible ({{$eligibilityDaysRemaining}} days remaining)</span>
|
||||||
|
@endif
|
||||||
|
@endauth
|
||||||
|
|
||||||
<button type="button" class="btn btn-success" onclick="window.location.href='{{route('renderApplicationForm', ['vacancySlug' => $position->vacancySlug])}}'">Apply</button>
|
@guest
|
||||||
|
<button type="button" class="btn btn-success" onclick="window.location.href='{{route('renderApplicationForm', ['vacancySlug' => $position->vacancySlug])}}'">Apply</button>
|
||||||
|
@endguest
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,14 @@ use Illuminate\Support\Facades\Route;
|
||||||
*/
|
*/
|
||||||
Auth::routes();
|
Auth::routes();
|
||||||
|
|
||||||
Route::get('/','HomeController@index');
|
Route::get('/','HomeController@index')->middleware('eligibility');
|
||||||
Route::post('/form/contact', 'ContactController@create')
|
Route::post('/form/contact', 'ContactController@create')
|
||||||
->name('sendSubmission');
|
->name('sendSubmission');
|
||||||
|
|
||||||
|
|
||||||
Route::group(['middleware' => 'auth'], function(){
|
Route::group(['middleware' => 'auth'], function(){
|
||||||
|
|
||||||
Route::get('/dashboard', 'DashboardController@index');
|
Route::get('/dashboard', 'DashboardController@index')->middleware('eligibility');
|
||||||
|
|
||||||
Route::group(['prefix' => '/applications'], function (){
|
Route::group(['prefix' => '/applications'], function (){
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ Route::group(['middleware' => 'auth'], function(){
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group(['prefix' => 'apply'], function (){
|
Route::group(['prefix' => 'apply', 'middleware' => ['eligibility']], function (){
|
||||||
|
|
||||||
Route::get('positions/{vacancySlug}', 'ApplicationController@renderApplicationForm')
|
Route::get('positions/{vacancySlug}', 'ApplicationController@renderApplicationForm')
|
||||||
->name('renderApplicationForm');
|
->name('renderApplicationForm');
|
||||||
|
|
Loading…
Reference in New Issue