feat: allow users to set their age
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
parent
ad4571db2a
commit
59351ef7bc
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.');
|
||||
}
|
||||
|
88
resources/views/dashboard/application-rendering/add-age.blade.php
Executable file
88
resources/views/dashboard/application-rendering/add-age.blade.php
Executable file
@ -0,0 +1,88 @@
|
||||
@extends('adminlte::page')
|
||||
|
||||
@section('title', config('app.name') . ' | ' . __('Account age update'))
|
||||
|
||||
@section('content_header')
|
||||
<h1>{{__('My account')}} / {{__('Apply')}} / {{__('Account age update')}}</h1>
|
||||
@stop
|
||||
|
||||
@section('js')
|
||||
|
||||
@if (session()->has('success'))
|
||||
|
||||
<script>
|
||||
toastr.success("{{session('success')}}")
|
||||
</script>
|
||||
|
||||
@elseif(session()->has('error'))
|
||||
|
||||
<script>
|
||||
toastr.error("{{session('error')}}")
|
||||
</script>
|
||||
|
||||
@endif
|
||||
|
||||
@if(!$isEligibleForApplication)
|
||||
|
||||
<script>toastr.error("{{__('Application access denied')}}")</script>
|
||||
|
||||
@endif
|
||||
|
||||
<script>
|
||||
flatpickr('#dob', {
|
||||
altInput: true,
|
||||
altFormat: "F j, Y",
|
||||
dateFormat: "Y-m-d",
|
||||
});
|
||||
</script>
|
||||
|
||||
@stop
|
||||
|
||||
@section('content')
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<x-alert title="{{ __('Date of birth required to continue') }}" alert-type="warning" icon="fa fa-exclamation-triangle">
|
||||
{{ __('Because you signed up using Discord, your age was not registered in our system. In order to continue applying for this position, please add your date of birth below. Please note that we don\'t accept registrations from users under 13 years of age.') }}
|
||||
</x-alert>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
|
||||
|
||||
<div class="col-md-6 offset-md-3">
|
||||
<x-card id="updateAge" card-title="Account age update" footer-style="">
|
||||
|
||||
<x-slot:cardHeader></x-slot:cardHeader>
|
||||
|
||||
<form id="addDob" method="post" action="{{ route('add-dob') }}">
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
<div class="form-group mb-4 mt-2">
|
||||
<label for="dob" class="sr-only">{{__('Date of birth')}}</label>
|
||||
<input type="text" class="form-control" name="dob" id="dob" placeholder="Date of birth">
|
||||
<span class="text-muted text-sm"><i class="fas fa-info-circle"></i> {!! __("<b>Why do we need this?</b> We use your age information to make sure you meet age requirements for certain positions, and to make sure that everyone is compliant with our terms of service.") !!} </span>
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
<x-slot:cardFooter>
|
||||
<button onclick="$('#addDob').submit()" type="button" class="btn btn-success"><i class="fas fa-save"></i> {{ __('Save and continue') }}</button>
|
||||
</x-slot:cardFooter>
|
||||
</x-card>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@stop
|
||||
|
||||
@section('footer')
|
||||
@include('breadcrumbs.dashboard.footer')
|
||||
@stop
|
@ -227,6 +227,8 @@ Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['lo
|
||||
->name('addPassword');
|
||||
Route::patch('/settings/account/unlink-oauth', [UserController::class, 'unlinkDiscordAccount'])
|
||||
->name('unlink-discord-account');
|
||||
Route::patch('settings/account/add-age', [UserController::class, 'addDob'])
|
||||
->name('add-dob');
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user