feat: allow users to set their age
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
9
app/Exceptions/IncompatibleAgeException.php
Normal file
9
app/Exceptions/IncompatibleAgeException.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class IncompatibleAgeException extends Exception
|
||||
{
|
||||
}
|
9
app/Exceptions/InvalidAgeException.php
Normal file
9
app/Exceptions/InvalidAgeException.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidAgeException extends Exception
|
||||
{
|
||||
}
|
@@ -24,7 +24,9 @@ namespace App\Http\Controllers;
|
||||
use App\Application;
|
||||
use App\Exceptions\ApplicationNotFoundException;
|
||||
use App\Exceptions\DiscordAccountRequiredException;
|
||||
use App\Exceptions\IncompatibleAgeException;
|
||||
use App\Exceptions\IncompleteApplicationException;
|
||||
use App\Exceptions\InvalidAgeException;
|
||||
use App\Exceptions\UnavailableApplicationException;
|
||||
use App\Exceptions\VacancyNotFoundException;
|
||||
use App\Facades\IP;
|
||||
@@ -108,6 +110,15 @@ class ApplicationController extends Controller
|
||||
|
||||
request()->session()->put('discordApplicationRedirectedSlug', $vacancySlug);
|
||||
return redirect(route('discordRedirect'));
|
||||
} catch (IncompatibleAgeException $e) {
|
||||
|
||||
return redirect()
|
||||
->to(route('dashboard'))
|
||||
->with('error', $e->getMessage());
|
||||
|
||||
} catch (InvalidAgeException $e) {
|
||||
|
||||
return view('dashboard.application-rendering.add-age');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ use App\Ban;
|
||||
use App\Facades\IP;
|
||||
use App\Facades\Options;
|
||||
use App\Http\Requests\Add2FASecretRequest;
|
||||
use App\Http\Requests\AddDobRequest;
|
||||
use App\Http\Requests\BanUserRequest;
|
||||
use App\Http\Requests\ChangeEmailRequest;
|
||||
use App\Http\Requests\ChangePasswordRequest;
|
||||
@@ -385,6 +386,22 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a user's date of birth if they don't have one.
|
||||
*
|
||||
* @param AddDobRequest $request
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function addDob(AddDobRequest $request) {
|
||||
|
||||
Auth::user()->dob = $request->dob;
|
||||
Auth::user()->save();
|
||||
|
||||
return redirect()
|
||||
->back();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete the given user's account
|
||||
*
|
||||
|
25
app/Http/Requests/AddDobRequest.php
Normal file
25
app/Http/Requests/AddDobRequest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AddDobRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'dob' => 'required|string|date_format:Y-m-d|before:-13 years',
|
||||
];
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
if (is_null(Auth::user()->dob)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -4,7 +4,10 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Exceptions\DiscordAccountRequiredException;
|
||||
use App\Exceptions\IncompatibleAgeException;
|
||||
use App\Exceptions\InvalidAgeException;
|
||||
use App\Notifications\ApplicationConfirmed;
|
||||
use Carbon\Carbon;
|
||||
use ContextAwareValidator;
|
||||
use App\Application;
|
||||
use App\Events\ApplicationDeniedEvent;
|
||||
@@ -25,12 +28,21 @@ class ApplicationService
|
||||
{
|
||||
/**
|
||||
* @throws DiscordAccountRequiredException
|
||||
* @throws IncompatibleAgeException
|
||||
* @throws InvalidAgeException
|
||||
*/
|
||||
public function renderForm($vacancySlug)
|
||||
{
|
||||
$vacancyWithForm = Vacancy::with('forms')->where('vacancySlug', $vacancySlug)->get();
|
||||
$firstVacancy = $vacancyWithForm->first();
|
||||
|
||||
if (is_null(Auth::user()->dob)) {
|
||||
throw new InvalidAgeException("User must have added their age to apply for this vacancy.");
|
||||
} elseif(Carbon::parse(Auth::user()->dob)->age < $firstVacancy->requiredAge) {
|
||||
throw new IncompatibleAgeException("Sorry, you must be {$firstVacancy->requiredAge} or older to apply to {$firstVacancy->vacancyName}.");
|
||||
}
|
||||
|
||||
|
||||
if ($firstVacancy->requiresDiscord && !Auth::user()->hasDiscordConnection()) {
|
||||
throw new DiscordAccountRequiredException('A discord account is required beyond this point.');
|
||||
}
|
||||
|
Reference in New Issue
Block a user