1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Apply fixes from StyleCI

This commit is contained in:
Dan Brown
2021-06-26 15:23:15 +00:00
committed by StyleCI Bot
parent 3a402f6adc
commit 934a833818
349 changed files with 3655 additions and 2625 deletions

View File

@ -31,7 +31,6 @@ class ConfirmEmailController extends Controller
$this->userRepo = $userRepo;
}
/**
* Show the page to tell the user to check their email
* and confirm their address.
@ -44,6 +43,7 @@ class ConfirmEmailController extends Controller
/**
* Shows a notice that a user's email address has not been confirmed,
* Also has the option to re-send the confirmation email.
*
* @return View
*/
public function showAwaiting()
@ -53,10 +53,13 @@ class ConfirmEmailController extends Controller
/**
* Confirms an email via a token and logs the user into the system.
*
* @param $token
* @return RedirectResponse|Redirector
*
* @throws ConfirmationEmailException
* @throws Exception
*
* @return RedirectResponse|Redirector
*/
public function confirm($token)
{
@ -65,6 +68,7 @@ class ConfirmEmailController extends Controller
} catch (Exception $exception) {
if ($exception instanceof UserTokenNotFoundException) {
$this->showErrorNotification(trans('errors.email_confirmation_invalid'));
return redirect('/register');
}
@ -72,6 +76,7 @@ class ConfirmEmailController extends Controller
$user = $this->userRepo->getById($exception->userId);
$this->emailConfirmationService->sendConfirmation($user);
$this->showErrorNotification(trans('errors.email_confirmation_expired'));
return redirect('/register/confirm');
}
@ -91,16 +96,17 @@ class ConfirmEmailController extends Controller
return redirect('/');
}
/**
* Resend the confirmation email
* Resend the confirmation email.
*
* @param Request $request
*
* @return View
*/
public function resend(Request $request)
{
$this->validate($request, [
'email' => 'required|email|exists:users,email'
'email' => 'required|email|exists:users,email',
]);
$user = $this->userRepo->getByEmail($request->get('email'));
@ -108,10 +114,12 @@ class ConfirmEmailController extends Controller
$this->emailConfirmationService->sendConfirmation($user);
} catch (Exception $e) {
$this->showErrorNotification(trans('auth.email_confirm_send_error'));
return redirect('/register/confirm');
}
$this->showSuccessNotification(trans('auth.email_confirm_resent'));
return redirect('/register/confirm');
}
}

View File

@ -34,11 +34,11 @@ class ForgotPasswordController extends Controller
$this->middleware('guard:standard');
}
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function sendResetLinkEmail(Request $request)
@ -59,6 +59,7 @@ class ForgotPasswordController extends Controller
if ($response === Password::RESET_LINK_SENT || $response === Password::INVALID_USER) {
$message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
$this->showSuccessNotification($message);
return back()->with('status', trans($response));
}

View File

@ -30,7 +30,7 @@ class LoginController extends Controller
use AuthenticatesUsers;
/**
* Redirection paths
* Redirection paths.
*/
protected $redirectTo = '/';
protected $redirectPath = '/';
@ -74,8 +74,8 @@ class LoginController extends Controller
if ($request->has('email')) {
session()->flashInput([
'email' => $request->get('email'),
'password' => (config('app.env') === 'demo') ? $request->get('password', '') : ''
'email' => $request->get('email'),
'password' => (config('app.env') === 'demo') ? $request->get('password', '') : '',
]);
}
@ -89,18 +89,19 @@ class LoginController extends Controller
}
return view('auth.login', [
'socialDrivers' => $socialDrivers,
'authMethod' => $authMethod,
'socialDrivers' => $socialDrivers,
'authMethod' => $authMethod,
]);
}
/**
* Handle a login request to the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
* @param \Illuminate\Http\Request $request
*
* @throws \Illuminate\Validation\ValidationException
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|\Illuminate\Http\JsonResponse
*/
public function login(Request $request)
{
@ -115,6 +116,7 @@ class LoginController extends Controller
$this->fireLockoutEvent($request);
Activity::logFailedLogin($username);
return $this->sendLockoutResponse($request);
}
@ -124,6 +126,7 @@ class LoginController extends Controller
}
} catch (LoginAttemptException $exception) {
Activity::logFailedLogin($username);
return $this->sendLoginAttemptExceptionResponse($exception, $request);
}
@ -133,14 +136,16 @@ class LoginController extends Controller
$this->incrementLoginAttempts($request);
Activity::logFailedLogin($username);
return $this->sendFailedLoginResponse($request);
}
/**
* The user has been authenticated.
*
* @param \Illuminate\Http\Request $request
* @param mixed $user
* @param \Illuminate\Http\Request $request
* @param mixed $user
*
* @return mixed
*/
protected function authenticated(Request $request, $user)
@ -155,16 +160,18 @@ class LoginController extends Controller
Theme::dispatch(ThemeEvents::AUTH_LOGIN, auth()->getDefaultDriver(), $user);
$this->logActivity(ActivityType::AUTH_LOGIN, $user);
return redirect()->intended($this->redirectPath());
}
/**
* Validate the user login request.
*
* @param \Illuminate\Http\Request $request
* @return void
* @param \Illuminate\Http\Request $request
*
* @throws \Illuminate\Validation\ValidationException
*
* @return void
*/
protected function validateLogin(Request $request)
{
@ -203,10 +210,11 @@ class LoginController extends Controller
/**
* Get the failed login response instance.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
* @param \Illuminate\Http\Request $request
*
* @throws \Illuminate\Validation\ValidationException
*
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function sendFailedLoginResponse(Request $request)
{

View File

@ -64,20 +64,22 @@ class RegisterController extends Controller
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|min:2|max:255',
'email' => 'required|email|max:255|unique:users',
'name' => 'required|min:2|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:8',
]);
}
/**
* Show the application registration form.
*
* @throws UserRegistrationException
*/
public function getRegister()
{
$this->registrationService->ensureRegistrationAllowed();
$socialDrivers = $this->socialAuthService->getActiveDrivers();
return view('auth.register', [
'socialDrivers' => $socialDrivers,
]);
@ -85,6 +87,7 @@ class RegisterController extends Controller
/**
* Handle a registration request for the application.
*
* @throws UserRegistrationException
*/
public function postRegister(Request $request)
@ -102,23 +105,27 @@ class RegisterController extends Controller
if ($exception->getMessage()) {
$this->showErrorNotification($exception->getMessage());
}
return redirect($exception->redirectLocation);
}
$this->showSuccessNotification(trans('auth.register_success'));
return redirect($this->redirectPath());
}
/**
* Create a new user instance after a valid registration.
* @param array $data
*
* @param array $data
*
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}

View File

@ -40,7 +40,8 @@ class ResetPasswordController extends Controller
* Get the response for a successful password reset.
*
* @param Request $request
* @param string $response
* @param string $response
*
* @return \Illuminate\Http\Response
*/
protected function sendResetResponse(Request $request, $response)
@ -48,6 +49,7 @@ class ResetPasswordController extends Controller
$message = trans('auth.reset_password_success');
$this->showSuccessNotification($message);
$this->logActivity(ActivityType::AUTH_PASSWORD_RESET_UPDATE, user());
return redirect($this->redirectPath())
->with('status', trans($response));
}
@ -55,8 +57,9 @@ class ResetPasswordController extends Controller
/**
* Get the response for a failed password reset.
*
* @param \Illuminate\Http\Request $request
* @param string $response
* @param \Illuminate\Http\Request $request
* @param string $response
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
*/
protected function sendResetFailedResponse(Request $request, $response)

View File

@ -7,7 +7,6 @@ use BookStack\Http\Controllers\Controller;
class Saml2Controller extends Controller
{
protected $samlService;
/**
@ -50,8 +49,9 @@ class Saml2Controller extends Controller
public function metadata()
{
$metaData = $this->samlService->metadata();
return response()->make($metaData, 200, [
'Content-Type' => 'text/xml'
'Content-Type' => 'text/xml',
]);
}
@ -63,6 +63,7 @@ class Saml2Controller extends Controller
{
$requestId = session()->pull('saml2_logout_request_id', null);
$redirect = $this->samlService->processSlsResponse($requestId) ?? '/';
return redirect($redirect);
}
@ -77,6 +78,7 @@ class Saml2Controller extends Controller
$user = $this->samlService->processAcsResponse($requestId);
if ($user === null) {
$this->showErrorNotification(trans('errors.saml_fail_authed', ['system' => config('saml2.name')]));
return redirect('/login');
}

View File

@ -18,7 +18,6 @@ use Laravel\Socialite\Contracts\User as SocialUser;
class SocialController extends Controller
{
protected $socialAuthService;
protected $registrationService;
@ -34,16 +33,19 @@ class SocialController extends Controller
/**
* Redirect to the relevant social site.
*
* @throws SocialDriverNotConfigured
*/
public function login(string $socialDriver)
{
session()->put('social-callback', 'login');
return $this->socialAuthService->startLogIn($socialDriver);
}
/**
* Redirect to the social site for authentication intended to register.
*
* @throws SocialDriverNotConfigured
* @throws UserRegistrationException
*/
@ -51,11 +53,13 @@ class SocialController extends Controller
{
$this->registrationService->ensureRegistrationAllowed();
session()->put('social-callback', 'register');
return $this->socialAuthService->startRegister($socialDriver);
}
/**
* The callback for social login services.
*
* @throws SocialSignInException
* @throws SocialDriverNotConfigured
* @throws UserRegistrationException
@ -70,7 +74,7 @@ class SocialController extends Controller
if ($request->has('error') && $request->has('error_description')) {
throw new SocialSignInException(trans('errors.social_login_bad_response', [
'socialAccount' => $socialDriver,
'error' => $request->get('error_description'),
'error' => $request->get('error_description'),
]), '/login');
}
@ -85,6 +89,7 @@ class SocialController extends Controller
if ($this->socialAuthService->driverAutoRegisterEnabled($socialDriver)) {
return $this->socialRegisterCallback($socialDriver, $socialUser);
}
throw $exception;
}
}
@ -103,11 +108,13 @@ class SocialController extends Controller
{
$this->socialAuthService->detachSocialAccount($socialDriver);
session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => Str::title($socialDriver)]));
return redirect(user()->getEditUrl());
}
/**
* Register a new user after a registration callback.
*
* @throws UserRegistrationException
*/
protected function socialRegisterCallback(string $socialDriver, SocialUser $socialUser)
@ -118,9 +125,9 @@ class SocialController extends Controller
// Create an array of the user data to create a new user instance
$userData = [
'name' => $socialUser->getName(),
'email' => $socialUser->getEmail(),
'password' => Str::random(32)
'name' => $socialUser->getName(),
'email' => $socialUser->getEmail(),
'password' => Str::random(32),
];
// Take name from email address if empty
@ -134,6 +141,7 @@ class SocialController extends Controller
$this->logActivity(ActivityType::AUTH_LOGIN, $user);
$this->showSuccessNotification(trans('auth.register_success'));
return redirect('/');
}
}

View File

@ -34,6 +34,7 @@ class UserInviteController extends Controller
/**
* Show the page for the user to set the password for their account.
*
* @throws Exception
*/
public function showSetPassword(string $token)
@ -51,12 +52,13 @@ class UserInviteController extends Controller
/**
* Sets the password for an invited user and then grants them access.
*
* @throws Exception
*/
public function setPassword(Request $request, string $token)
{
$this->validate($request, [
'password' => 'required|min:8'
'password' => 'required|min:8',
]);
try {
@ -81,8 +83,10 @@ class UserInviteController extends Controller
/**
* Check and validate the exception thrown when checking an invite token.
* @return RedirectResponse|Redirector
*
* @throws Exception
*
* @return RedirectResponse|Redirector
*/
protected function handleTokenException(Exception $exception)
{
@ -92,6 +96,7 @@ class UserInviteController extends Controller
if ($exception instanceof UserTokenExpiredException) {
$this->showErrorNotification(trans('errors.invite_token_expired'));
return redirect('/password/email');
}