forked from miguel456/rbrecruiter
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,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::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,10 +22,18 @@
|
|||
|
||||
@endif
|
||||
|
||||
@if(!$isEligibleForApplication)
|
||||
|
||||
<script>toastr.error("You do not have permission to view this page.", "Access denied")</script>
|
||||
|
||||
@endif
|
||||
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
|
||||
@if($isEligibleForApplication)
|
||||
|
||||
<div class="modal fade" tabindex="-1" id="confirm" role="dialog" aria-labelledby="modalConfirmLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
|
@ -134,4 +142,15 @@
|
|||
|
||||
</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
|
||||
|
|
|
@ -40,4 +40,16 @@
|
|||
</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
|
||||
|
|
|
@ -48,8 +48,16 @@
|
|||
</div>
|
||||
|
||||
<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
|
||||
|
||||
@guest
|
||||
<button type="button" class="btn btn-success" onclick="window.location.href='{{route('renderApplicationForm', ['vacancySlug' => $position->vacancySlug])}}'">Apply</button>
|
||||
@endguest
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -14,14 +14,14 @@ use Illuminate\Support\Facades\Route;
|
|||
*/
|
||||
Auth::routes();
|
||||
|
||||
Route::get('/','HomeController@index');
|
||||
Route::get('/','HomeController@index')->middleware('eligibility');
|
||||
Route::post('/form/contact', 'ContactController@create')
|
||||
->name('sendSubmission');
|
||||
|
||||
|
||||
Route::group(['middleware' => 'auth'], function(){
|
||||
|
||||
Route::get('/dashboard', 'DashboardController@index');
|
||||
Route::get('/dashboard', 'DashboardController@index')->middleware('eligibility');
|
||||
|
||||
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')
|
||||
->name('renderApplicationForm');
|
||||
|
|
Loading…
Reference in New Issue