feat: require that users link their discord to apply to certain vacancies
Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
parent
b9cc2aad46
commit
ce9184c386
9
app/Exceptions/DiscordAccountRequiredException.php
Normal file
9
app/Exceptions/DiscordAccountRequiredException.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class DiscordAccountRequiredException extends Exception
|
||||||
|
{
|
||||||
|
}
|
@ -23,11 +23,13 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Application;
|
use App\Application;
|
||||||
use App\Exceptions\ApplicationNotFoundException;
|
use App\Exceptions\ApplicationNotFoundException;
|
||||||
|
use App\Exceptions\DiscordAccountRequiredException;
|
||||||
use App\Exceptions\IncompleteApplicationException;
|
use App\Exceptions\IncompleteApplicationException;
|
||||||
use App\Exceptions\UnavailableApplicationException;
|
use App\Exceptions\UnavailableApplicationException;
|
||||||
use App\Exceptions\VacancyNotFoundException;
|
use App\Exceptions\VacancyNotFoundException;
|
||||||
use App\Facades\IP;
|
use App\Facades\IP;
|
||||||
use App\Services\ApplicationService;
|
use App\Services\ApplicationService;
|
||||||
|
use App\Vacancy;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
@ -91,6 +93,14 @@ class ApplicationController extends Controller
|
|||||||
return redirect()
|
return redirect()
|
||||||
->back()
|
->back()
|
||||||
->with('error', $ex->getMessage());
|
->with('error', $ex->getMessage());
|
||||||
|
|
||||||
|
} catch (DiscordAccountRequiredException $e) {
|
||||||
|
\Log::info('Redirecting user: ' . $e->getMessage(), [
|
||||||
|
'user' => Auth::user()->email
|
||||||
|
]);
|
||||||
|
|
||||||
|
request()->session()->put('discordApplicationRedirectedSlug', $vacancySlug);
|
||||||
|
return redirect(route('discordRedirect'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,6 @@ class DiscordController extends Controller
|
|||||||
|
|
||||||
public function discordCallback() {
|
public function discordCallback() {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$discordUser = Socialite::driver('discord')->user();
|
$discordUser = Socialite::driver('discord')->user();
|
||||||
@ -91,6 +90,10 @@ class DiscordController extends Controller
|
|||||||
Auth::login($oAuthUser, true);
|
Auth::login($oAuthUser, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (session()->has('discordApplicationRedirectedSlug')) {
|
||||||
|
return redirect(route('renderApplicationForm', ['vacancySlug' => session()->pull('discordApplicationRedirectedSlug')]));
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('dashboard');
|
->route('dashboard');
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Exceptions\DiscordAccountRequiredException;
|
||||||
use App\Notifications\ApplicationConfirmed;
|
use App\Notifications\ApplicationConfirmed;
|
||||||
use ContextAwareValidator;
|
use ContextAwareValidator;
|
||||||
use App\Application;
|
use App\Application;
|
||||||
@ -22,12 +23,18 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class ApplicationService
|
class ApplicationService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws DiscordAccountRequiredException
|
||||||
|
*/
|
||||||
public function renderForm($vacancySlug)
|
public function renderForm($vacancySlug)
|
||||||
{
|
{
|
||||||
$vacancyWithForm = Vacancy::with('forms')->where('vacancySlug', $vacancySlug)->get();
|
$vacancyWithForm = Vacancy::with('forms')->where('vacancySlug', $vacancySlug)->get();
|
||||||
|
|
||||||
$firstVacancy = $vacancyWithForm->first();
|
$firstVacancy = $vacancyWithForm->first();
|
||||||
|
|
||||||
|
if ($firstVacancy->requiresDiscord && !Auth::user()->hasDiscordConnection()) {
|
||||||
|
throw new DiscordAccountRequiredException('A discord account is required beyond this point.');
|
||||||
|
}
|
||||||
|
|
||||||
if (!$vacancyWithForm->isEmpty() && $firstVacancy->vacancyCount !== 0 && $firstVacancy->vacancyStatus == 'OPEN') {
|
if (!$vacancyWithForm->isEmpty() && $firstVacancy->vacancyCount !== 0 && $firstVacancy->vacancyStatus == 'OPEN') {
|
||||||
return view('dashboard.application-rendering.apply')
|
return view('dashboard.application-rendering.apply')
|
||||||
->with([
|
->with([
|
||||||
|
@ -67,6 +67,10 @@
|
|||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
|
|
||||||
|
@if($vacancy->requiresDiscord)
|
||||||
|
<p class="text-muted"><i class="fas fa-info-circle"></i> {{ __('Note: to apply for this position, you must sign in with your Discord account beforehand.') }}</p>
|
||||||
|
@endif
|
||||||
|
|
||||||
{!! $vacancy->vacancyFullDescription !!}
|
{!! $vacancy->vacancyFullDescription !!}
|
||||||
<p class="text-sm text-muted">
|
<p class="text-sm text-muted">
|
||||||
{{__('Last updated @ :vacancyUpdatedTimeValue', ['vacancyUpdatedTimeValue' => $vacancy->updated_at]) }}
|
{{__('Last updated @ :vacancyUpdatedTimeValue', ['vacancyUpdatedTimeValue' => $vacancy->updated_at]) }}
|
||||||
@ -257,7 +261,12 @@
|
|||||||
|
|
||||||
<div class="card-footer text-center">
|
<div class="card-footer text-center">
|
||||||
|
|
||||||
<button type="button" class="btn btn-primary btn-sm" onclick="window.location.href='{{ route('renderApplicationForm', ['vacancySlug' => $vacancy->vacancySlug]) }}'">{{__('Apply')}}</button>
|
|
||||||
|
@if ($vacancy->requiresDiscord && !Auth::user()->hasDiscordConnection())
|
||||||
|
<button type="button" style="background-color: #5865F2" class="btn btn-primary btn-sm" onclick="window.location.href='{{ route('renderApplicationForm', ['vacancySlug' => $vacancy->vacancySlug]) }}'"><i style="color: white" class="fab fa-discord"></i> {{__('Apply with Discord')}}</button>
|
||||||
|
@else
|
||||||
|
<button type="button" class="btn btn-primary btn-sm" onclick="window.location.href='{{ route('renderApplicationForm', ['vacancySlug' => $vacancy->vacancySlug]) }}'">{{__('Apply')}}</button>
|
||||||
|
@endif
|
||||||
<button type="button" class="btn btn-warning btn-sm" onclick="$('#{{ $vacancy->vacancySlug }}-details').modal('show')">{{__('Learn More')}}</button>
|
<button type="button" class="btn btn-warning btn-sm" onclick="$('#{{ $vacancy->vacancySlug }}-details').modal('show')">{{__('Learn More')}}</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user