X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/e743cd3f606fb8a2e432813f7c84fed1093f68c4..refs/pull/3391/head:/app/Auth/Access/Guards/ExternalBaseSessionGuard.php diff --git a/app/Auth/Access/Guards/ExternalBaseSessionGuard.php b/app/Auth/Access/Guards/ExternalBaseSessionGuard.php index d1fb0b606..99bfd2e79 100644 --- a/app/Auth/Access/Guards/ExternalBaseSessionGuard.php +++ b/app/Auth/Access/Guards/ExternalBaseSessionGuard.php @@ -2,10 +2,7 @@ namespace BookStack\Auth\Access\Guards; -use BookStack\Auth\User; -use BookStack\Auth\UserRepo; -use BookStack\Exceptions\LoginAttemptEmailNeededException; -use BookStack\Exceptions\LoginAttemptException; +use BookStack\Auth\Access\RegistrationService; use Illuminate\Auth\GuardHelpers; use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; use Illuminate\Contracts\Auth\StatefulGuard; @@ -18,8 +15,6 @@ use Illuminate\Contracts\Session\Session; * guard with 'remember' functionality removed. Basic auth and event emission * has also been removed to keep this simple. Designed to be extended by external * Auth Guards. - * - * @package Illuminate\Auth */ class ExternalBaseSessionGuard implements StatefulGuard { @@ -56,23 +51,23 @@ class ExternalBaseSessionGuard implements StatefulGuard protected $loggedOut = false; /** - * Repository to perform user-specific actions. + * Service to handle common registration actions. * - * @var UserRepo + * @var RegistrationService */ - protected $userRepo; + protected $registrationService; /** * Create a new authentication guard. * * @return void */ - public function __construct(string $name, UserProvider $provider, Session $session, UserRepo $userRepo) + public function __construct(string $name, UserProvider $provider, Session $session, RegistrationService $registrationService) { $this->name = $name; $this->session = $session; $this->provider = $provider; - $this->userRepo = $userRepo; + $this->registrationService = $registrationService; } /** @@ -89,7 +84,7 @@ class ExternalBaseSessionGuard implements StatefulGuard // If we've already retrieved the user for the current request we can just // return it back immediately. We do not want to fetch the user data on // every call to this method because that would be tremendously slow. - if (! is_null($this->user)) { + if (!is_null($this->user)) { return $this->user; } @@ -97,7 +92,7 @@ class ExternalBaseSessionGuard implements StatefulGuard // First we will try to load the user using the // identifier in the session if one exists. - if (! is_null($id)) { + if (!is_null($id)) { $this->user = $this->provider->retrieveById($id); } @@ -123,7 +118,8 @@ class ExternalBaseSessionGuard implements StatefulGuard /** * Log a user into the application without sessions or cookies. * - * @param array $credentials + * @param array $credentials + * * @return bool */ public function once(array $credentials = []) @@ -140,12 +136,13 @@ class ExternalBaseSessionGuard implements StatefulGuard /** * Log the given user ID into the application without sessions or cookies. * - * @param mixed $id + * @param mixed $id + * * @return \Illuminate\Contracts\Auth\Authenticatable|false */ public function onceUsingId($id) { - if (! is_null($user = $this->provider->retrieveById($id))) { + if (!is_null($user = $this->provider->retrieveById($id))) { $this->setUser($user); return $user; @@ -157,7 +154,8 @@ class ExternalBaseSessionGuard implements StatefulGuard /** * Validate a user's credentials. * - * @param array $credentials + * @param array $credentials + * * @return bool */ public function validate(array $credentials = []) @@ -165,12 +163,12 @@ class ExternalBaseSessionGuard implements StatefulGuard return false; } - /** * Attempt to authenticate a user using the given credentials. * - * @param array $credentials - * @param bool $remember + * @param array $credentials + * @param bool $remember + * * @return bool */ public function attempt(array $credentials = [], $remember = false) @@ -181,26 +179,24 @@ class ExternalBaseSessionGuard implements StatefulGuard /** * Log the given user ID into the application. * - * @param mixed $id - * @param bool $remember + * @param mixed $id + * @param bool $remember + * * @return \Illuminate\Contracts\Auth\Authenticatable|false */ public function loginUsingId($id, $remember = false) { - if (! is_null($user = $this->provider->retrieveById($id))) { - $this->login($user, $remember); - - return $user; - } - + // Always return false as to disable this method, + // Logins should route through LoginService. return false; } /** * Log a user into the application. * - * @param \Illuminate\Contracts\Auth\Authenticatable $user - * @param bool $remember + * @param \Illuminate\Contracts\Auth\Authenticatable $user + * @param bool $remember + * * @return void */ public function login(AuthenticatableContract $user, $remember = false) @@ -213,7 +209,8 @@ class ExternalBaseSessionGuard implements StatefulGuard /** * Update the session with the given ID. * - * @param string $id + * @param string $id + * * @return void */ protected function updateSession($id) @@ -267,7 +264,7 @@ class ExternalBaseSessionGuard implements StatefulGuard */ public function getName() { - return 'login_'.$this->name.'_'.sha1(static::class); + return 'login_' . $this->name . '_' . sha1(static::class); } /** @@ -293,7 +290,8 @@ class ExternalBaseSessionGuard implements StatefulGuard /** * Set the current user. * - * @param \Illuminate\Contracts\Auth\Authenticatable $user + * @param \Illuminate\Contracts\Auth\Authenticatable $user + * * @return $this */ public function setUser(AuthenticatableContract $user) @@ -304,5 +302,4 @@ class ExternalBaseSessionGuard implements StatefulGuard return $this; } - }