chore: reformat code.

This commit is contained in:
James Cole
2023-06-21 12:34:58 +02:00
parent 8d87abde64
commit 3dcb35710b
799 changed files with 23319 additions and 22173 deletions

View File

@@ -61,8 +61,8 @@ class ForgotPasswordController extends Controller
/**
* Send a reset link to the given user.
*
* @param Request $request
* @param UserRepositoryInterface $repository
* @param Request $request
* @param UserRepositoryInterface $repository
*
* @return Factory|RedirectResponse|View
*/

View File

@@ -128,10 +128,41 @@ class LoginController extends Controller
$this->sendFailedLoginResponse($request);
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return $this->username;
}
/**
* Get the failed login response instance.
*
* @param Request $request
*
* @return void
*
* @throws ValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
$exception = ValidationException::withMessages(
[
$this->username() => [trans('auth.failed')],
]
);
$exception->redirectTo = route('login');
throw $exception;
}
/**
* Log the user out of the application.
*
* @param Request $request
* @param Request $request
*
* @return RedirectResponse|Redirector|Response
*/
@@ -168,7 +199,7 @@ class LoginController extends Controller
/**
* Show the application's login form.
*
* @param Request $request
* @param Request $request
*
* @return Factory|Application|View|Redirector|RedirectResponse
* @throws FireflyException
@@ -213,35 +244,4 @@ class LoginController extends Controller
return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField'));
}
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return $this->username;
}
/**
* Get the failed login response instance.
*
* @param Request $request
*
* @return void
*
* @throws ValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
$exception = ValidationException::withMessages(
[
$this->username() => [trans('auth.failed')],
]
);
$exception->redirectTo = route('login');
throw $exception;
}
}

View File

@@ -78,7 +78,7 @@ class RegisterController extends Controller
/**
* Handle a registration request for the application.
*
* @param Request $request
* @param Request $request
*
* @return Application|Redirector|RedirectResponse
* @throws FireflyException
@@ -114,6 +114,30 @@ class RegisterController extends Controller
return redirect($this->redirectPath());
}
/**
* @return bool
* @throws FireflyException
*/
protected function allowedToRegister(): bool
{
// is allowed to register?
$allowRegistration = true;
try {
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
$singleUserMode = true;
}
$userCount = User::count();
$guard = config('auth.defaults.guard');
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
$allowRegistration = false;
}
if ('web' !== $guard) {
$allowRegistration = false;
}
return $allowRegistration;
}
/**
* Show the application registration form if the invitation code is valid.
*
@@ -151,7 +175,7 @@ class RegisterController extends Controller
/**
* Show the application registration form.
*
* @param Request $request
* @param Request $request
*
* @return Factory|View
* @throws ContainerExceptionInterface
@@ -174,28 +198,4 @@ class RegisterController extends Controller
return view('auth.register', compact('isDemoSite', 'email', 'pageTitle'));
}
/**
* @return bool
* @throws FireflyException
*/
protected function allowedToRegister(): bool
{
// is allowed to register?
$allowRegistration = true;
try {
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$singleUserMode = true;
}
$userCount = User::count();
$guard = config('auth.defaults.guard');
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
$allowRegistration = false;
}
if ('web' !== $guard) {
$allowRegistration = false;
}
return $allowRegistration;
}
}

View File

@@ -73,7 +73,7 @@ class ResetPasswordController extends Controller
/**
* Reset the given user's password.
*
* @param Request $request
* @param Request $request
*
* @return Factory|JsonResponse|RedirectResponse|View
* @throws ValidationException
@@ -117,8 +117,8 @@ class ResetPasswordController extends Controller
*
* If no token is present, display the link request form.
*
* @param Request $request
* @param null $token
* @param Request $request
* @param null $token
*
* @return Factory|View
* @throws FireflyException

View File

@@ -54,7 +54,7 @@ class TwoFactorController extends Controller
}
/**
* @param Request $request
* @param Request $request
*
* @return RedirectResponse|Redirector
*/
@@ -99,20 +99,26 @@ class TwoFactorController extends Controller
}
/**
* @param string $mfaCode
* Each MFA history has a timestamp and a code, saving the MFA entries for 5 minutes. So if the
* submitted MFA code has been submitted in the last 5 minutes, it won't work despite being valid.
*
* @param string $mfaCode
* @param array $mfaHistory
*
* @return bool
*/
private function addToMFAHistory(string $mfaCode): void
private function inMFAHistory(string $mfaCode, array $mfaHistory): bool
{
/** @var array $mfaHistory */
$mfaHistory = Preferences::get('mfa_history', [])->data;
$entry = [
'time' => time(),
'code' => $mfaCode,
];
$mfaHistory[] = $entry;
$now = time();
foreach ($mfaHistory as $entry) {
$time = $entry['time'];
$code = $entry['code'];
if ($code === $mfaCode && $now - $time <= 300) {
return true;
}
}
Preferences::set('mfa_history', $mfaHistory);
$this->filterMFAHistory();
return false;
}
/**
@@ -138,32 +144,26 @@ class TwoFactorController extends Controller
}
/**
* Each MFA history has a timestamp and a code, saving the MFA entries for 5 minutes. So if the
* submitted MFA code has been submitted in the last 5 minutes, it won't work despite being valid.
*
* @param string $mfaCode
* @param array $mfaHistory
*
* @return bool
* @param string $mfaCode
*/
private function inMFAHistory(string $mfaCode, array $mfaHistory): bool
private function addToMFAHistory(string $mfaCode): void
{
$now = time();
foreach ($mfaHistory as $entry) {
$time = $entry['time'];
$code = $entry['code'];
if ($code === $mfaCode && $now - $time <= 300) {
return true;
}
}
/** @var array $mfaHistory */
$mfaHistory = Preferences::get('mfa_history', [])->data;
$entry = [
'time' => time(),
'code' => $mfaCode,
];
$mfaHistory[] = $entry;
return false;
Preferences::set('mfa_history', $mfaHistory);
$this->filterMFAHistory();
}
/**
* Checks if code is in users backup codes.
*
* @param string $mfaCode
* @param string $mfaCode
*
* @return bool
*/
@@ -180,7 +180,7 @@ class TwoFactorController extends Controller
/**
* Remove the used code from the list of backup codes.
*
* @param string $mfaCode
* @param string $mfaCode
*/
private function removeFromBackupCodes(string $mfaCode): void
{