@@ -6,9 +6,7 @@ use App\Absence;
|
||||
use App\Exceptions\AbsenceNotActionableException;
|
||||
use App\Http\Requests\StoreAbsenceRequest;
|
||||
use App\Http\Requests\UpdateAbsenceRequest;
|
||||
use App\Services\AbsenceService;
|
||||
use App\User;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Carbon;
|
||||
@@ -17,12 +15,28 @@ use Illuminate\Support\Facades\Auth;
|
||||
class AbsenceController extends Controller
|
||||
{
|
||||
|
||||
private AbsenceService $absenceService;
|
||||
/**
|
||||
* Determines whether someone already has an active leave of absence request
|
||||
*
|
||||
* @param User $user The user to check
|
||||
* @return bool Their status
|
||||
*/
|
||||
private function hasActiveRequest(Authenticatable $user): bool {
|
||||
|
||||
public function __construct (AbsenceService $absenceService) {
|
||||
$absences = Absence::where('requesterID', $user->id)->get();
|
||||
|
||||
$this->absenceService = $absenceService;
|
||||
foreach ($absences as $absence) {
|
||||
|
||||
// Or we could adjust the query (using a model scope) to only return valid absences;
|
||||
// If there are any, refuse to store more, but this approach also works
|
||||
// A model scope that only returns cancelled, declined and ended absences could also be implemented for future use
|
||||
if (in_array($absence->getRawOriginal('status'), ['PENDING', 'APPROVED']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +57,7 @@ class AbsenceController extends Controller
|
||||
* Display a listing of absences belonging to the current user.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @throws AuthorizationException
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function showUserAbsences()
|
||||
{
|
||||
@@ -62,14 +76,14 @@ class AbsenceController extends Controller
|
||||
/**
|
||||
* Show the form for creating a new absence request.
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('create', Absence::class);
|
||||
|
||||
return view('dashboard.absences.create')
|
||||
->with('activeRequest', $this->absenceService->hasActiveRequest(Auth::user()));
|
||||
->with('activeRequest', $this->hasActiveRequest(Auth::user()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,13 +96,21 @@ class AbsenceController extends Controller
|
||||
{
|
||||
$this->authorize('create', Absence::class);
|
||||
|
||||
if ($this->absenceService->hasActiveRequest(Auth::user())) {
|
||||
if ($this->hasActiveRequest(Auth::user())) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('You already have an active request. Cancel it or let it expire first.'));
|
||||
}
|
||||
|
||||
$absence = $this->absenceService->createAbsence(Auth::user(), $request);
|
||||
|
||||
$absence = Absence::create([
|
||||
'requesterID' => Auth::user()->id,
|
||||
'start' => $request->start_date,
|
||||
'predicted_end' => $request->predicted_end,
|
||||
'available_assist' => $request->available_assist == "on",
|
||||
'reason' => $request->reason,
|
||||
'status' => 'PENDING',
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->to(route('absences.show', ['absence' => $absence->id]))
|
||||
@@ -98,8 +120,7 @@ class AbsenceController extends Controller
|
||||
/**
|
||||
* Display the specified absence request.
|
||||
*
|
||||
* @param \App\Absence $absence
|
||||
* @throws AuthorizationException
|
||||
* @param \App\Absence $absence
|
||||
*/
|
||||
public function show(Absence $absence)
|
||||
{
|
||||
@@ -117,7 +138,7 @@ class AbsenceController extends Controller
|
||||
*
|
||||
* @param Absence $absence
|
||||
* @return RedirectResponse
|
||||
* @throws AuthorizationException
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function approveAbsence(Absence $absence): RedirectResponse
|
||||
{
|
||||
@@ -125,7 +146,7 @@ class AbsenceController extends Controller
|
||||
|
||||
try
|
||||
{
|
||||
$this->absenceService->approveAbsence($absence);
|
||||
$absence->setApproved();
|
||||
}
|
||||
catch (AbsenceNotActionableException $notActionableException)
|
||||
{
|
||||
@@ -145,7 +166,7 @@ class AbsenceController extends Controller
|
||||
*
|
||||
* @param Absence $absence
|
||||
* @return RedirectResponse
|
||||
* @throws AuthorizationException
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function declineAbsence(Absence $absence): RedirectResponse
|
||||
{
|
||||
@@ -153,7 +174,7 @@ class AbsenceController extends Controller
|
||||
|
||||
try
|
||||
{
|
||||
$this->absenceService->declineAbsence($absence);
|
||||
$absence->setDeclined();
|
||||
} catch (AbsenceNotActionableException $notActionableException)
|
||||
{
|
||||
return redirect()
|
||||
@@ -172,7 +193,7 @@ class AbsenceController extends Controller
|
||||
*
|
||||
* @param Absence $absence
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws AuthorizationException
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function cancelAbsence(Absence $absence): \Illuminate\Http\RedirectResponse
|
||||
{
|
||||
@@ -180,7 +201,7 @@ class AbsenceController extends Controller
|
||||
|
||||
try
|
||||
{
|
||||
$this->absenceService->cancelAbsence($absence);
|
||||
$absence->setCancelled();
|
||||
}
|
||||
catch (AbsenceNotActionableException $notActionableException)
|
||||
{
|
||||
@@ -204,7 +225,7 @@ class AbsenceController extends Controller
|
||||
{
|
||||
$this->authorize('delete', $absence);
|
||||
|
||||
if ($this->absenceService->removeAbsence($absence)) {
|
||||
if ($absence->delete()) {
|
||||
return redirect()
|
||||
->to(route('absences.index'))
|
||||
->with('success', __('Absence request deleted.'));
|
||||
|
@@ -23,15 +23,11 @@ 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;
|
||||
use App\Services\ApplicationService;
|
||||
use App\Vacancy;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -86,13 +82,6 @@ class ApplicationController extends Controller
|
||||
}
|
||||
|
||||
|
||||
public function discordApply(Request $request, $vacancySlug) {
|
||||
|
||||
$request->session()->put('discordApplicationRedirectedSlug', $vacancySlug);
|
||||
return redirect(route('discordRedirect'));
|
||||
|
||||
}
|
||||
|
||||
public function renderApplicationForm($vacancySlug)
|
||||
{
|
||||
try {
|
||||
@@ -102,47 +91,25 @@ class ApplicationController extends Controller
|
||||
return redirect()
|
||||
->back()
|
||||
->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'));
|
||||
} catch (IncompatibleAgeException $e) {
|
||||
|
||||
return redirect()
|
||||
->to(route('dashboard'))
|
||||
->with('error', $e->getMessage());
|
||||
|
||||
} catch (InvalidAgeException $e) {
|
||||
|
||||
return view('dashboard.application-rendering.add-age');
|
||||
}
|
||||
}
|
||||
|
||||
public function saveApplicationAnswers(Request $request, $vacancySlug)
|
||||
{
|
||||
if (Auth::user()->isEligible()) {
|
||||
try {
|
||||
$this->applicationService->fillForm(Auth::user(), $request->all(), $vacancySlug);
|
||||
try {
|
||||
|
||||
} catch (VacancyNotFoundException | IncompleteApplicationException | UnavailableApplicationException $e) {
|
||||
$this->applicationService->fillForm(Auth::user(), $request->all(), $vacancySlug);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', $e->getMessage());
|
||||
}
|
||||
} catch (VacancyNotFoundException | IncompleteApplicationException | UnavailableApplicationException $e) {
|
||||
|
||||
return redirect()
|
||||
->to(route('showUserApps'))
|
||||
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
||||
->back()
|
||||
->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->to(route('showUserApps'))
|
||||
->with('error', __('Your account is not eligible to submit a new application.'));
|
||||
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
||||
}
|
||||
|
||||
public function updateApplicationStatus(Request $request, Application $application, $newStatus)
|
||||
|
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Facades\Discord;
|
||||
use App\Facades\Options;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use Laravel\Socialite\Two\InvalidStateException;
|
||||
|
||||
class DiscordController extends Controller
|
||||
{
|
||||
|
||||
|
||||
public function discordRedirect() {
|
||||
return Socialite::driver('discord')
|
||||
->scopes(['email', 'guilds.join', 'guilds.members.read', 'guilds'])
|
||||
->redirect();
|
||||
}
|
||||
|
||||
public function discordCallback() {
|
||||
|
||||
try {
|
||||
|
||||
$discordUser = Socialite::driver('discord')->user();
|
||||
|
||||
} catch (InvalidStateException $stateException) {
|
||||
Log::warning('Invalid state for social authentication: ', [
|
||||
'message' => $stateException->getMessage(),
|
||||
'ua' => request()->userAgent(),
|
||||
'ip' => request()->ip()
|
||||
]);
|
||||
return redirect(route('discordRedirect'));
|
||||
}
|
||||
|
||||
$appUser = User::where('email', $discordUser->getEmail())->first();
|
||||
|
||||
if ($appUser) {
|
||||
|
||||
$appUser->discord_token = $discordUser->token;
|
||||
$appUser->discord_refresh_token = $discordUser->refreshToken;
|
||||
$appUser->discord_user_id = $discordUser->getId();
|
||||
$appUser->discord_pfp = $discordUser->getAvatar();
|
||||
$appUser->save();
|
||||
|
||||
Auth::login($appUser, true);
|
||||
|
||||
} else {
|
||||
|
||||
$oAuthUser = User::create([
|
||||
'uuid' => null,
|
||||
'name' => $discordUser->getName(),
|
||||
'email' => $discordUser->getEmail(),
|
||||
'email_verified_at' => now(), // verify the account since it came from a trusted provider
|
||||
'username' => $discordUser->getNickname(),
|
||||
'currentIp' => \request()->ip(),
|
||||
'registrationIp' => request()->ip(),
|
||||
'discord_user_id' => $discordUser->getId(),
|
||||
'discord_pfp' => $discordUser->getAvatar(),
|
||||
'discord_token' => $discordUser->token,
|
||||
'discord_refresh_token' => $discordUser->refreshToken
|
||||
]);
|
||||
|
||||
$oAuthUser->assignRole('user');
|
||||
|
||||
Auth::login($oAuthUser, true);
|
||||
}
|
||||
|
||||
if (session()->has('discordApplicationRedirectedSlug')) {
|
||||
return redirect(route('renderApplicationForm', ['vacancySlug' => session()->pull('discordApplicationRedirectedSlug')]));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('dashboard');
|
||||
}
|
||||
|
||||
}
|
@@ -26,11 +26,8 @@ use App\Services\AccountSuspensionService;
|
||||
use App\User;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Facades\IP;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
|
||||
class LoginController extends Controller
|
||||
@@ -79,14 +76,6 @@ class LoginController extends Controller
|
||||
$isLocked = $service->isLocked($user);
|
||||
|
||||
if ($isBanned || $isLocked) {
|
||||
|
||||
Log::alert('Restricted user attempting to login.', [
|
||||
'ip' => $request->ip(),
|
||||
'email' => $user->email,
|
||||
'isBanned' => $isBanned,
|
||||
'isLocked' => $isLocked
|
||||
]);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return $this->originalAttemptLogin($request);
|
||||
@@ -105,11 +94,17 @@ class LoginController extends Controller
|
||||
'prev' => $user->originalIP,
|
||||
'new' => $request->ip()
|
||||
]);
|
||||
$user->currentIp = $request->ip();
|
||||
$user->originalIP = $request->ip();
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function discordRedirect() {
|
||||
return Socialite::driver('discord')->redirect();
|
||||
}
|
||||
|
||||
public function discordCallback() {
|
||||
// TODO;
|
||||
}
|
||||
}
|
||||
|
@@ -23,13 +23,11 @@ namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Profile;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use App\User;
|
||||
use App\Facades\Options;
|
||||
use App\Facades\IP;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class RegisterController extends Controller
|
||||
@@ -64,6 +62,19 @@ class RegisterController extends Controller
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
public function showRegistrationForm()
|
||||
{
|
||||
$users = User::where('originalIP', \request()->ip())->get();
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($user && $user->isBanned()) {
|
||||
abort(403, 'You do not have permission to access this page.');
|
||||
}
|
||||
}
|
||||
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
@@ -95,14 +106,9 @@ class RegisterController extends Controller
|
||||
'uuid' => (Options::getOption('requireGameLicense') && Options::getOption('currentGame') == 'MINECRAFT') ? ['required', 'string', 'unique:users', 'min:32', 'max:32'] : ['nullable', 'string'],
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'dob' => ['required', 'string', 'date_format:Y-m-d', 'before:-13 years'],
|
||||
'acceptTerms' => ['required', 'accepted'],
|
||||
'password' => $password,
|
||||
], [
|
||||
'dob.before' => __('You must be 13 years of age or older in order to sign up for an account.'),
|
||||
'dob.required' => __('Please enter your date of birth.'),
|
||||
'uuid.required' => __('Please enter a valid (and Premium) Minecraft username! We do not support cracked users.'),
|
||||
'acceptTerms.required' => __('Please accept the Community Guidelines, Terms of Service and Privacy Policy to continue.')
|
||||
'uuid.required' => 'Please enter a valid (and Premium) Minecraft username! We do not support cracked users.',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -114,16 +120,12 @@ class RegisterController extends Controller
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
$ip = IP::shouldCollect() ? request()->ip() : '0.0.0.0';
|
||||
|
||||
$user = User::create([
|
||||
'uuid' => $data['uuid'] ?? "disabled",
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
'registrationIp' => $ip,
|
||||
'currentIp' => $ip,
|
||||
'dob' => $data['dob']
|
||||
'originalIP' => IP::shouldCollect() ? request()->ip() : '0.0.0.0',
|
||||
]);
|
||||
|
||||
$user->assignRole('user');
|
||||
|
88
app/Http/Controllers/BanController.php
Executable file
88
app/Http/Controllers/BanController.php
Executable file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Ban;
|
||||
use App\Events\UserBannedEvent;
|
||||
use App\Http\Requests\BanUserRequest;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BanController extends Controller
|
||||
{
|
||||
|
||||
protected $suspensionService;
|
||||
|
||||
public function __construct(AccountSuspensionService $suspensionService)
|
||||
{
|
||||
// Inject the service via DI
|
||||
$this->suspensionService = $suspensionService;
|
||||
}
|
||||
|
||||
public function insert(BanUserRequest $request, User $user)
|
||||
{
|
||||
if (config('demo.is_enabled')) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('This feature is disabled'));
|
||||
}
|
||||
|
||||
$this->authorize('create', [Ban::class, $user]);
|
||||
|
||||
|
||||
if (!$this->suspensionService->isSuspended($user)) {
|
||||
|
||||
$this->suspensionService->suspend($request->reason, $request->duration, $user, $request->suspensionType);
|
||||
$request->session()->flash('success', __('Account suspended.'));
|
||||
|
||||
} else {
|
||||
|
||||
$request->session()->flash('error', __('Account already suspended!'));
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function delete(Request $request, User $user)
|
||||
{
|
||||
if (config('demo.is_enabled')) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('This feature is disabled'));
|
||||
}
|
||||
|
||||
$this->authorize('delete', $user->bans);
|
||||
|
||||
if ($this->suspensionService->isSuspended($user)) {
|
||||
|
||||
$this->suspensionService->unsuspend($user);
|
||||
$request->session()->flash('success', __('Account unsuspended successfully!'));
|
||||
|
||||
} else {
|
||||
$request->session()->flash('error', __('This account isn\'t suspended!'));
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
64
app/Http/Controllers/ContactController.php
Executable file
64
app/Http/Controllers/ContactController.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright © 2020 Miguel Nogueira
|
||||
*
|
||||
* This file is part of Raspberry Staff Manager.
|
||||
*
|
||||
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Raspberry Staff Manager is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\FailedCaptchaException;
|
||||
use App\Http\Requests\HomeContactRequest;
|
||||
use App\Notifications\NewContact;
|
||||
use App\Services\ContactService;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
protected $users;
|
||||
|
||||
private $contactService;
|
||||
|
||||
public function __construct(User $users, ContactService $contactService)
|
||||
{
|
||||
$this->contactService = $contactService;
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
public function create(HomeContactRequest $request)
|
||||
{
|
||||
try {
|
||||
|
||||
$email = $request->email;
|
||||
$msg = $request->msg;
|
||||
$challenge = $request->input('captcha');
|
||||
|
||||
$this->contactService->sendMessage($request->ip(), $msg, $email, $challenge);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success',__('Message sent successfully! We usually respond within 48 hours.'));
|
||||
|
||||
} catch (FailedCaptchaException $ex) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', $ex->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,12 +24,10 @@ namespace App\Http\Controllers;
|
||||
use App\Application;
|
||||
use App\Events\ApplicationApprovedEvent;
|
||||
use App\Events\ApplicationDeniedEvent;
|
||||
use App\Services\AbsenceService;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DevToolsController extends Controller
|
||||
{
|
||||
@@ -107,16 +105,4 @@ class DevToolsController extends Controller
|
||||
->with('error', __('There were no expired suspensions (or no suspensions at all) to purge.'));
|
||||
|
||||
}
|
||||
|
||||
public function endAbsencesNow(AbsenceService $service)
|
||||
{
|
||||
$this->singleAuthorise();
|
||||
|
||||
$service->endExpired();
|
||||
Log::alert('(absence cleaner) Forcefully started absence expiration check!');
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', 'Cleaned up expired absences.');
|
||||
}
|
||||
}
|
||||
|
@@ -41,4 +41,11 @@ class HomeController extends Controller
|
||||
return view('home')
|
||||
->with('positions', $positions);
|
||||
}
|
||||
|
||||
public function pageGiveaway()
|
||||
{
|
||||
|
||||
return view('giveaway');
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -21,12 +21,8 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Exceptions\ProfileAlreadyExistsException;
|
||||
use App\Exceptions\ProfileCreationFailedException;
|
||||
use App\Exceptions\ProfileNotFoundException;
|
||||
use App\Facades\IP;
|
||||
use App\Http\Requests\ProfileSave;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use App\Services\ProfileService;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
@@ -36,12 +32,18 @@ use Spatie\Permission\Models\Role;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
private ProfileService $profileService;
|
||||
private $profileService;
|
||||
|
||||
public function __construct(ProfileService $profileService) {
|
||||
$this->profileService = $profileService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('dashboard.user.directory')
|
||||
->with('users', User::with('profile', 'bans')->paginate(9));
|
||||
}
|
||||
|
||||
public function showProfile()
|
||||
{
|
||||
// TODO: Come up with cleaner social media solution, e.g. social media object
|
||||
@@ -58,23 +60,26 @@ class ProfileController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function showSingleProfile(AccountSuspensionService $accountSuspensionService, User $user)
|
||||
public function showSingleProfile(User $user)
|
||||
{
|
||||
|
||||
if (is_null($user->profile)) {
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', "This user doesn't have a profile.");
|
||||
|
||||
}
|
||||
|
||||
$socialMediaProfiles = json_decode($user->profile->socialLinks, true);
|
||||
$createdDate = Carbon::parse($user->created_at);
|
||||
|
||||
$systemRoles = Role::all()->pluck('name')->all();
|
||||
$userRoles = $user->roles->pluck('name')->all();
|
||||
|
||||
$roleList = [];
|
||||
|
||||
foreach ($systemRoles as $role) {
|
||||
if (in_array($role, $userRoles)) {
|
||||
$roleList[$role] = true;
|
||||
} else {
|
||||
$roleList[$role] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$suspensionInfo = null;
|
||||
if ($accountSuspensionService->isSuspended($user))
|
||||
if ($user->isBanned())
|
||||
{
|
||||
$suspensionInfo = [
|
||||
|
||||
@@ -93,7 +98,8 @@ class ProfileController extends Controller
|
||||
'insta' => $socialMediaProfiles['links']['insta'] ?? 'UpdateMe',
|
||||
'discord' => $socialMediaProfiles['links']['discord'] ?? 'UpdateMe#12345',
|
||||
'since' => $createdDate->englishMonth.' '.$createdDate->year,
|
||||
'ipInfo' => IP::lookup($user->currentIp),
|
||||
'ipInfo' => IP::lookup($user->originalIP),
|
||||
'roles' => $roleList,
|
||||
'suspensionInfo' => $suspensionInfo
|
||||
]);
|
||||
} else {
|
||||
@@ -108,44 +114,4 @@ class ProfileController extends Controller
|
||||
->back()
|
||||
->with('success', __('Profile updated.'));
|
||||
}
|
||||
|
||||
|
||||
public function createProfile(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$this->profileService->createProfile($request->user());
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', $e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', __('Your profile has been created.'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function deleteProfile(Request $request)
|
||||
{
|
||||
|
||||
try {
|
||||
$this->profileService->deleteProfile($request->user());
|
||||
} catch (ProfileNotFoundException $e) {
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', $e->getMessage());
|
||||
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', __('Profile deleted successfully.'));
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -22,36 +22,22 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
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;
|
||||
use App\Http\Requests\DeleteUserRequest;
|
||||
use App\Http\Requests\FlushSessionsRequest;
|
||||
use App\Http\Requests\Remove2FASecretRequest;
|
||||
use App\Http\Requests\Reset2FASecretRequest;
|
||||
use App\Http\Requests\SearchPlayerRequest;
|
||||
use App\Http\Requests\SetNewPasswordRequest;
|
||||
use App\Http\Requests\UpdateUserRequest;
|
||||
use App\Notifications\ChangedPassword;
|
||||
use App\Notifications\EmailChanged;
|
||||
use App\Notifications\PasswordAdminResetNotification;
|
||||
use App\Notifications\TwoFactorResetNotification;
|
||||
use App\Services\AccountSuspensionService;
|
||||
use App\Services\DiscordService;
|
||||
use App\Traits\DisablesFeatures;
|
||||
use App\Traits\HandlesAccountDeletion;
|
||||
use App\Traits\ReceivesAccountTokens;
|
||||
use App\User;
|
||||
use Google2FA;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Http\Client\RequestException;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -59,20 +45,13 @@ use Spatie\Permission\Models\Role;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
use HandlesAccountDeletion, DisablesFeatures;
|
||||
use HandlesAccountDeletion;
|
||||
|
||||
|
||||
/**
|
||||
* Shows list of users
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function showUsers()
|
||||
{
|
||||
$this->authorize('viewPlayers', User::class);
|
||||
|
||||
return view('dashboard.administration.users')
|
||||
return view('dashboard.administration.players')
|
||||
->with([
|
||||
'users' => User::with('roles')->paginate('6'),
|
||||
'numUsers' => count(User::all()),
|
||||
@@ -80,15 +59,6 @@ class UserController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Searches for a player with the given search query.
|
||||
*
|
||||
* @deprecated Until Algolia implementation
|
||||
* @param SearchPlayerRequest $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function showPlayersLike(SearchPlayerRequest $request)
|
||||
{
|
||||
$this->authorize('viewPlayers', User::class);
|
||||
@@ -102,7 +72,7 @@ class UserController extends Controller
|
||||
if (! $matchingUsers->isEmpty()) {
|
||||
$request->session()->flash('success', __('There were :usersCount user(s) matching your search.', ['usersCount' => $matchingUsers->count()]));
|
||||
|
||||
return view('dashboard.administration.users')
|
||||
return view('dashboard.administration.players')
|
||||
->with([
|
||||
'users' => $matchingUsers,
|
||||
'numUsers' => count(User::all()),
|
||||
@@ -115,16 +85,6 @@ class UserController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the user account's settings page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
|
||||
*/
|
||||
public function showAccount(Request $request)
|
||||
{
|
||||
$QRCode = null;
|
||||
@@ -149,58 +109,6 @@ class UserController extends Controller
|
||||
->with('twofaQRCode', $QRCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show account management screen
|
||||
*
|
||||
* @param AccountSuspensionService $suspensionService
|
||||
* @param Request $request
|
||||
* @param User $user
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function showAcocuntManagement(AccountSuspensionService $suspensionService, Request $request, User $user)
|
||||
{
|
||||
|
||||
$this->authorize('adminEdit', $user);
|
||||
|
||||
$systemRoles = Role::all()->pluck('name')->all();
|
||||
$userRoles = $user->roles->pluck('name')->all();
|
||||
|
||||
$roleList = [];
|
||||
|
||||
foreach ($systemRoles as $role) {
|
||||
if (in_array($role, $userRoles)) {
|
||||
$roleList[$role] = true;
|
||||
} else {
|
||||
$roleList[$role] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return view('dashboard.user.manage')
|
||||
->with([
|
||||
'user' => $user,
|
||||
'roles' => $roleList,
|
||||
'isVerified' => $user->isVerified(),
|
||||
'isLocked' => $suspensionService->isLocked($user),
|
||||
'isSuspended' => $suspensionService->isSuspended($user),
|
||||
'hasDiscord' => $user->hasDiscordConnection(),
|
||||
'hasPassword' => $user->hasPassword(),
|
||||
'requireLicense' => Options::getOption('requireGameLicense'),
|
||||
'suspensionReason' => $suspensionService->getSuspensionReason($user),
|
||||
'suspensionDuration' => $suspensionService->getSuspensionDuration($user),
|
||||
'has2FA' => $user->has2FA(),
|
||||
'applications' => $user->applications()->get()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log out other sessions for the current user
|
||||
*
|
||||
* @param FlushSessionsRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\AuthenticationException
|
||||
*/
|
||||
public function flushSessions(FlushSessionsRequest $request)
|
||||
{
|
||||
// TODO: Move all log calls to a listener, which binds to an event fired by each significant event, such as this one
|
||||
@@ -219,14 +127,6 @@ class UserController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Change the current user's password
|
||||
*
|
||||
* @param ChangePasswordRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse|void
|
||||
*/
|
||||
public function changePassword(ChangePasswordRequest $request)
|
||||
{
|
||||
if (config('demo.is_enabled')) {
|
||||
@@ -255,80 +155,13 @@ class UserController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a new password for the user.
|
||||
*
|
||||
* @param SetNewPasswordRequest $request
|
||||
* @return Application|RedirectResponse|Redirector
|
||||
*/
|
||||
public function setPassword(SetNewPasswordRequest $request) {
|
||||
|
||||
if (!Auth::user()->hasPassword()) {
|
||||
|
||||
Auth::user()->password = Hash::make($request->newpass);
|
||||
Auth::user()->save();
|
||||
|
||||
Auth::logout();
|
||||
$request->session()->invalidate();
|
||||
$request->session()->regenerateToken();
|
||||
|
||||
return redirect(route('login'));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('Your account already has a password.'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets a user's password and removes their discord information from storage
|
||||
*
|
||||
* @param User $user
|
||||
* @param SetNewPasswordRequest $request
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function unlinkDiscordAccount(Request $request, DiscordService $discordService)
|
||||
{
|
||||
if ($request->user()->hasPassword()) {
|
||||
try {
|
||||
$discordService->revokeAccountTokens(Auth::user());
|
||||
Log::warning('Revoking social account tokens, user initiated', [
|
||||
'user' => Auth::user()->email
|
||||
]);
|
||||
} catch (RequestException $requestException) {
|
||||
|
||||
if ($requestException->getCode() == 401) {
|
||||
return redirect(route('discordRedirect'));
|
||||
}
|
||||
|
||||
Log::error('Error while trying to revoke Discord credentials', [$requestException->getMessage()]);
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('An unknown error ocurred. Please try again later.'));
|
||||
}
|
||||
|
||||
$request->session()->flash('success', __('Discord account unlinked successfully. Link it again by re-authorizing the app with the same account in the login screen, or through your account settings.'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('Please set a password for your account first before trying to unlink Discord.'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change the current user's email address
|
||||
*
|
||||
* @param ChangeEmailRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changeEmail(ChangeEmailRequest $request)
|
||||
{
|
||||
$this->disable();
|
||||
if (config('demo.is_enabled')) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('This feature is disabled'));
|
||||
}
|
||||
|
||||
$user = User::find(Auth::user()->id);
|
||||
|
||||
@@ -351,68 +184,13 @@ class UserController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the user's password and notifies them.
|
||||
*
|
||||
* @param User $user The user to remove the password for
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function forcePasswordReset(User $user) {
|
||||
|
||||
$this->authorize('adminEdit', $user);
|
||||
|
||||
if ($user->hasPassword()) {
|
||||
$user->notify(new PasswordAdminResetNotification());
|
||||
|
||||
$user->password = null;
|
||||
$user->save();
|
||||
|
||||
|
||||
Log::alert("Removed account password", [
|
||||
'target' => $user,
|
||||
'actor' => Auth::user()
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', __('Account password removed.'));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('This user doesn\'t have a password to reset.'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param DeleteUserRequest $request
|
||||
* @param User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function delete(DeleteUserRequest $request, User $user)
|
||||
{
|
||||
$this->disable();
|
||||
if (config('demo.is_enabled')) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', _('This feature is disabled'));
|
||||
}
|
||||
|
||||
$this->authorize('delete', $user);
|
||||
|
||||
@@ -426,19 +204,14 @@ class UserController extends Controller
|
||||
return redirect()->route('registeredPlayerList');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update a given user's details
|
||||
*
|
||||
* @param UpdateUserRequest $request
|
||||
* @param User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function update(UpdateUserRequest $request, User $user)
|
||||
{
|
||||
if (config('demo.is_enabled')) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('This feature is disabled'));
|
||||
}
|
||||
$this->authorize('adminEdit', $user);
|
||||
$this->disable();
|
||||
|
||||
// Mass update would not be possible here without extra code, making route model binding useless
|
||||
$user->email = $request->email;
|
||||
@@ -470,16 +243,6 @@ class UserController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate and add a 2FA secret for the current user
|
||||
*
|
||||
* @param Add2FASecretRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
|
||||
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
|
||||
*/
|
||||
public function add2FASecret(Add2FASecretRequest $request)
|
||||
{
|
||||
if (config('demo.is_enabled')) {
|
||||
@@ -522,13 +285,6 @@ class UserController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the current user's two factor secret key
|
||||
*
|
||||
* @param Remove2FASecretRequest $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function remove2FASecret(Remove2FASecretRequest $request)
|
||||
{
|
||||
Log::warning('SECURITY: Disabling two factor authentication (user initiated)', [
|
||||
@@ -544,94 +300,34 @@ class UserController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove the given user's two factor secret key
|
||||
*
|
||||
* @param Reset2FASecretRequest $request
|
||||
* @param User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function reset2FASecret(Reset2FASecretRequest $request, User $user) {
|
||||
// note: could invalidate other sessions for increased security
|
||||
if ($user->has2FA()) {
|
||||
Log::warning('SECURITY: Disabling two factor authentication (admin initiated)', [
|
||||
'initiator' => $request->user()->email,
|
||||
'target' => $user->email,
|
||||
'ip' => $request->ip(),
|
||||
]);
|
||||
|
||||
$user->twofa_secret = null;
|
||||
$user->password = null;
|
||||
$user->save();
|
||||
|
||||
$user->notify(new TwoFactorResetNotification());
|
||||
|
||||
public function terminate(Request $request, User $user)
|
||||
{
|
||||
$this->authorize('terminate', User::class);
|
||||
if (config('demo.is_enabled')) {
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', __('Two factor removed & user notified.'));
|
||||
->with('error', __('This feature is disabled'));
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', 'This user does not have two-factor authentication enabled.');
|
||||
}
|
||||
// TODO: move logic to policy
|
||||
if (! $user->isStaffMember() || $user->is(Auth::user())) {
|
||||
$request->session()->flash('error', __('You cannot terminate this user.'));
|
||||
|
||||
/**
|
||||
* Suspend the given user
|
||||
*
|
||||
* @param AccountSuspensionService $suspensionService
|
||||
* @param BanUserRequest $request
|
||||
* @param User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function suspend(AccountSuspensionService $suspensionService, BanUserRequest $request, User $user)
|
||||
{
|
||||
$this->authorize('create', [Ban::class, $user]);
|
||||
$this->disable();
|
||||
|
||||
if ($suspensionService->isSuspended($user))
|
||||
{
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('Account already suspended.'));
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
if ($request->suspensionType = "on") {
|
||||
$suspensionService->suspend($user, $request->reason, $request->duration);
|
||||
}
|
||||
else {
|
||||
$suspensionService->suspend($user, $request->reason);
|
||||
foreach ($user->roles as $role) {
|
||||
if ($role->name == 'user') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->removeRole($role->name);
|
||||
}
|
||||
|
||||
Log::info('User '.$user->name.' has just been demoted.');
|
||||
$request->session()->flash('success', __('User terminated successfully.'));
|
||||
|
||||
//TODO: Dispatch event
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsuspend the given user
|
||||
*
|
||||
* @param AccountSuspensionService $suspensionService
|
||||
* @param Request $request
|
||||
* @param User $user
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
*/
|
||||
public function unsuspend(AccountSuspensionService $suspensionService, Request $request, User $user)
|
||||
{
|
||||
$this->authorize('delete', $user->bans);
|
||||
$this->disable();
|
||||
|
||||
if ($suspensionService->isSuspended($user)) {
|
||||
|
||||
$suspensionService->unsuspend($user);
|
||||
$request->session()->flash('success', __('Account unsuspended successfully!'));
|
||||
|
||||
} else {
|
||||
$request->session()->flash('error', __('This account isn\'t suspended!'));
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -70,8 +70,6 @@ class VacancyController extends Controller
|
||||
'discordRoleID' => $request->discordRole,
|
||||
'vacancyFormID' => $request->vacancyFormID,
|
||||
'vacancyCount' => $request->vacancyCount,
|
||||
'requiresDiscord' => $request->requireDiscordAccount == 'on',
|
||||
'requiredAge' => $request->requiredAge
|
||||
|
||||
]);
|
||||
|
||||
@@ -144,8 +142,6 @@ class VacancyController extends Controller
|
||||
$vacancy->vacancyFullDescription = $request->vacancyFullDescription;
|
||||
$vacancy->vacancyDescription = $request->vacancyDescription;
|
||||
$vacancy->vacancyCount = $request->vacancyCount;
|
||||
$vacancy->requiresDiscord = $request->requireDiscordAccount == 'on';
|
||||
$vacancy->requiredAge = $request->requiredAge;
|
||||
|
||||
$vacancy->save();
|
||||
|
||||
@@ -157,18 +153,10 @@ class VacancyController extends Controller
|
||||
public function delete(Request $request, Vacancy $vacancy)
|
||||
{
|
||||
$this->authorize('delete', $vacancy);
|
||||
|
||||
if ($vacancy->teams->isEmpty()) {
|
||||
|
||||
$vacancy->delete();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', __('Vacancy deleted. All applications associated with it are now gone too.'));
|
||||
}
|
||||
$vacancy->delete();
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('error', __('Please detach any teams that may be using this vacancy first.'));
|
||||
->with('success', __('Vacancy deleted. All applications associated with it are now gone too.'));
|
||||
}
|
||||
}
|
||||
|
@@ -89,10 +89,10 @@ class Kernel extends HttpKernel
|
||||
'2fa' => \PragmaRX\Google2FALaravel\Middleware::class,
|
||||
'passwordexpiration' => \App\Http\Middleware\PasswordExpirationMiddleware::class,
|
||||
'passwordredirect' => \App\Http\Middleware\PasswordExpirationRedirectMiddleware::class,
|
||||
'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
|
||||
'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
|
||||
'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
|
||||
'localeCookieRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
|
||||
'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class,
|
||||
'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class,
|
||||
'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
|
||||
'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
|
||||
'localeCookieRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleCookieRedirect::class,
|
||||
'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class,
|
||||
];
|
||||
}
|
||||
|
@@ -22,11 +22,8 @@
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Application;
|
||||
use App\User;
|
||||
use Carbon\Carbon;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\View;
|
||||
@@ -36,42 +33,34 @@ class ApplicationEligibility
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @deprecated Deprecated in 0.9.0
|
||||
* @see User::isEligible()
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$eligible = false;
|
||||
$daysRemaining = __('N/A');
|
||||
$curtime = new Carbon(now());
|
||||
|
||||
if (Auth::check()) {
|
||||
$applications = Application::where('applicantUserID', Auth::user()->id)->get();
|
||||
$eligible = true;
|
||||
|
||||
$lastApplication = Application::where('applicantUserID', Auth::user()->id)->latest()->first();
|
||||
$daysRemaining = 0;
|
||||
|
||||
if (is_null($lastApplication)) {
|
||||
View::share('isEligibleForApplication', true);
|
||||
View::share('eligibilityDaysRemaining', 0);
|
||||
if (! $applications->isEmpty()) {
|
||||
foreach ($applications as $application) {
|
||||
$appTime = Carbon::parse($application->created_at);
|
||||
if ($appTime->isSameMonth($curtime)) {
|
||||
Log::warning('Notice: Application ID '.$application->id.' was found to be in the same month as today\'s time, making the user '.Auth::user()->name.' ineligible for application');
|
||||
$eligible = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
$allowedTime = Carbon::parse($applications->last()->created_at)->addMonth();
|
||||
$daysRemaining = $allowedTime->diffInDays(now());
|
||||
}
|
||||
|
||||
$daysRemaining = $lastApplication->created_at->addMonth()->diffInDays(now());
|
||||
if ($lastApplication->created_at->diffInMonths(now()) > 1 && in_array($lastApplication->applicationStatus, ['DENIED', 'APPROVED'])) {
|
||||
|
||||
$eligible = true;
|
||||
}
|
||||
|
||||
Log::debug('Perfomed application eligibility check', [
|
||||
'eligible' => $eligible,
|
||||
'daysRemaining' => $daysRemaining,
|
||||
'ipAddress' => Auth::user()->originalIP,
|
||||
'checkUserID' => Auth::user()->id
|
||||
]);
|
||||
|
||||
View::share('isEligibleForApplication', $eligible);
|
||||
View::share('eligibilityDaysRemaining', $daysRemaining);
|
||||
}
|
||||
|
@@ -21,21 +21,12 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Services\AccountSuspensionService;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
class Bancheck
|
||||
{
|
||||
private $suspensionService;
|
||||
|
||||
|
||||
public function __construct(AccountSuspensionService $suspensionService) {
|
||||
$this->suspensionService = $suspensionService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
@@ -46,11 +37,11 @@ class Bancheck
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$userIP = $request->ip();
|
||||
$anonymousUser = User::where('currentIp', $userIP)->get();
|
||||
$anonymousUser = User::where('ipAddress', $userIP)->get();
|
||||
|
||||
if (Auth::check() && $this->suspensionService->isSuspended($anonymousUser)) {
|
||||
if (Auth::check() && Auth::user()->isBanned()) {
|
||||
View::share('isBanned', true);
|
||||
} elseif (! $anonymousUser->isEmpty() && $this->suspensionService->isSuspended(User::find($anonymousUser->id))) {
|
||||
} elseif (! $anonymousUser->isEmpty() && User::find($anonymousUser->id)->isBanned()) {
|
||||
View::share('isBanned', true);
|
||||
} else {
|
||||
View::share('isBanned', false);
|
||||
|
@@ -21,7 +21,6 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Services\AccountSuspensionService;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -36,10 +35,10 @@ class ForceLogoutMiddleware
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if ((new AccountSuspensionService())->isSuspended(Auth::user())) {
|
||||
if (Auth::user()->isBanned()) {
|
||||
Auth::logout();
|
||||
$request->session()->flash('error', __('Your account is suspended. If you think this was a mistake, please contact an admin.'));
|
||||
|
||||
$request->session()->flash('error', __('Your account is suspended. You will not be able to login or register until the suspension is lifted.'));
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AdminPasswordResetRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
if (Auth::user()->has2FA()) {
|
||||
return [
|
||||
'currentPassword' => 'required|current_password:web',
|
||||
'otp' => 'required|integer|max:6',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'currentPassword' => 'required|current_password:web',
|
||||
];
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SetNewPasswordRequest extends FormRequest
|
||||
class HomeContactRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
@@ -13,11 +13,7 @@ class SetNewPasswordRequest extends FormRequest
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
if (\Auth::user()->hasDiscordConnection()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,7 +24,9 @@ class SetNewPasswordRequest extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'newpass' => 'required|string|min:10|confirmed',
|
||||
'email' => 'required|email',
|
||||
'msg' => 'required|string',
|
||||
'captcha' => 'required|string'
|
||||
];
|
||||
}
|
||||
}
|
@@ -44,6 +44,7 @@ class Remove2FASecretRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'currentPassword' => 'required|current_password',
|
||||
'consent' => 'required|accepted',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class Reset2FASecretRequest extends FormRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'currentPassword' => 'required|current_password',
|
||||
];
|
||||
}
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -46,7 +46,7 @@ class UpdateUserRequest extends FormRequest
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
'name' => 'required|string',
|
||||
'uuid' => 'nullable|max:32|min:32',
|
||||
'uuid' => 'required|max:32|min:32',
|
||||
'roles' => 'required_without_all',
|
||||
];
|
||||
}
|
||||
|
@@ -47,8 +47,6 @@ class VacancyEditRequest extends FormRequest
|
||||
'vacancyDescription' => 'required|string',
|
||||
'vacancyFullDescription' => 'nullable|string',
|
||||
'vacancyCount' => 'required|integer|min:1',
|
||||
'requireDiscordAccount' => 'required|string',
|
||||
'requiredAge' => 'required|integer|numeric|min:13|max:100'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -25,8 +25,6 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class VacancyRequest extends FormRequest
|
||||
{
|
||||
public mixed $requiresDiscordAccount;
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
@@ -48,12 +46,10 @@ class VacancyRequest extends FormRequest
|
||||
'vacancyName' => 'required|string',
|
||||
'vacancyDescription' => 'required|string',
|
||||
'vacancyFullDescription' => 'nullable|string',
|
||||
'permissionGroup' => 'nullable|string',
|
||||
'discordRole' => 'nullable|string',
|
||||
'permissionGroup' => 'required|string',
|
||||
'discordRole' => 'required|string',
|
||||
'vacancyCount' => 'required|integer',
|
||||
'vacancyFormID' => 'required|integer',
|
||||
'requireDiscordAccount' => 'required|string',
|
||||
'requiredAge' => 'required|integer|numeric|min:13|max:100'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user