feat: added eligibility check to application save method
This commit addresses an issue where users could submit as many applications as they wanted by simply navigating to the previous page and resubmitting the form, therefore bypassing validation that was only existent in the front end. Fixes #20.
This commit is contained in:
@@ -96,20 +96,25 @@ class ApplicationController extends Controller
|
||||
|
||||
public function saveApplicationAnswers(Request $request, $vacancySlug)
|
||||
{
|
||||
try {
|
||||
if (Auth::user()->isEligible()) {
|
||||
try {
|
||||
$this->applicationService->fillForm(Auth::user(), $request->all(), $vacancySlug);
|
||||
|
||||
$this->applicationService->fillForm(Auth::user(), $request->all(), $vacancySlug);
|
||||
} catch (VacancyNotFoundException | IncompleteApplicationException | UnavailableApplicationException $e) {
|
||||
|
||||
} catch (VacancyNotFoundException | IncompleteApplicationException | UnavailableApplicationException $e) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', $e->getMessage());
|
||||
->to(route('showUserApps'))
|
||||
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->to(route('showUserApps'))
|
||||
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
||||
->with('error', __('Your account is not eligible to submit a new application.'));
|
||||
}
|
||||
|
||||
public function updateApplicationStatus(Request $request, Application $application, $newStatus)
|
||||
|
10
app/User.php
10
app/User.php
@@ -121,19 +121,17 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
|
||||
|
||||
public function isEligible(): bool {
|
||||
$eligible = false;
|
||||
$lastApplication = Application::where('applicantUserID', $this->id)->latest()->first();
|
||||
$lastApplication = Application::where('applicantUserID', $this->getAttribute('id'))->latest()->first();
|
||||
|
||||
if (is_null($lastApplication)) {
|
||||
$eligible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
||||
|
||||
$eligible = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return $eligible;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user