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:
parent
b96a20a0a9
commit
667425e4e3
@ -96,8 +96,8 @@ class ApplicationController extends Controller
|
|||||||
|
|
||||||
public function saveApplicationAnswers(Request $request, $vacancySlug)
|
public function saveApplicationAnswers(Request $request, $vacancySlug)
|
||||||
{
|
{
|
||||||
|
if (Auth::user()->isEligible()) {
|
||||||
try {
|
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) {
|
||||||
@ -112,6 +112,11 @@ class ApplicationController extends Controller
|
|||||||
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return redirect()
|
||||||
|
->to(route('showUserApps'))
|
||||||
|
->with('error', __('Your account is not eligible to submit a new application.'));
|
||||||
|
}
|
||||||
|
|
||||||
public function updateApplicationStatus(Request $request, Application $application, $newStatus)
|
public function updateApplicationStatus(Request $request, Application $application, $newStatus)
|
||||||
{
|
{
|
||||||
$messageIsError = false;
|
$messageIsError = false;
|
||||||
|
10
app/User.php
10
app/User.php
@ -121,19 +121,17 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
|
|
||||||
|
|
||||||
public function isEligible(): bool {
|
public function isEligible(): bool {
|
||||||
$eligible = false;
|
$lastApplication = Application::where('applicantUserID', $this->getAttribute('id'))->latest()->first();
|
||||||
$lastApplication = Application::where('applicantUserID', $this->id)->latest()->first();
|
|
||||||
|
|
||||||
if (is_null($lastApplication)) {
|
if (is_null($lastApplication)) {
|
||||||
$eligible = true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
||||||
|
return true;
|
||||||
$eligible = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $eligible;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user