Exemple #1
0
 /**
  * Authenticate request with Basic.
  *
  * @param \Illuminate\Http\Request  $request
  * @param \Illuminate\Routing\Route $route
  *
  * @return mixed
  */
 public function authenticate(Request $request, Route $route)
 {
     $this->validateAuthorizationHeader($request);
     if ($user = $this->auth->getUser()) {
         return $user;
     }
     throw new UnauthorizedHttpException(null, 'Please log in before perform this query.');
 }
 /**
  * Handle the command.
  *
  * @param $command
  *
  * @throws \Tectonic\Shift\Modules\Authentication\Exceptions\InvalidAuthenticationCredentialsException
  * @throws \Tectonic\Shift\Modules\Authentication\Exceptions\UserAccountAssociationException
  * @return \Illuminate\Auth\UserInterface|null
  */
 public function handle($command)
 {
     // First check to see if the users credentials are valid.
     $userCredentialsAreValid = $this->authenticate->validate(['email' => $command->email, 'password' => $command->password]);
     // If user credential are invalid, throw exception.
     if (!$userCredentialsAreValid) {
         throw new InvalidAuthenticationCredentialsException();
     }
     // Find out if user has an account id with the current account
     $accountUser = $this->userRepository->getByEmailAndAccount($command->email, CurrentAccount::get());
     // If an account user is found, login and return user
     if ($accountUser) {
         $this->authenticate->login($accountUser, $command->remember);
         $user = $this->authenticate->getUser();
         // Raise an event, and dispatch
         $this->raise(new UserHasAuthenticated($user));
         $this->eventDispatcher->dispatch($this->releaseEvents());
         return $user;
     }
     // Login failed, throw exception
     throw new UserAccountAssociationException();
 }