/**
  * Autneticat
  *
  * @param $provider
  * @return bool
  */
 public function authenticate($provider)
 {
     $socialUser = $this->social->with($provider)->stateless()->user();
     if (!$socialUser) {
         return false;
     }
     $identity = $this->oauth->findByProviderNameAndId($socialUser->id, $provider);
     if ($identity) {
         $this->oauth->update($identity, ['token' => $socialUser->token]);
         $this->auth->loginUsingId($identity->user_id, true);
         return true;
     }
     $user = $this->user->findByEmail($socialUser->email);
     if (!is_null($user)) {
         $this->oauth->create(['provider_id' => $socialUser->id, 'provider' => $provider, 'user_id' => $user->id, 'token' => $socialUser->token]);
         $this->user->update($user, ['status' => 1]);
         $this->auth->login($user, true);
         return true;
     }
     if (!setting('registration', true)) {
         return false;
     }
     // Just create the user
     $newUser = $this->user->create(['name' => $this->emailToName($socialUser->email), 'email' => $socialUser->email, 'password' => '', 'status' => 1, 'avatar' => $socialUser->avatar]);
     event(new UserCreatedThroughOAuth($newUser));
     $this->oauth->create(['provider_id' => $socialUser->id, 'provider' => $provider, 'user_id' => $newUser->id, 'token' => $socialUser->token]);
     $this->auth->login($newUser, true);
     return true;
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->user->authenticateApiV1($request->header('Authorization')) !== false) {
         $this->auth->loginUsingId($this->user->authenticateApiV1($request->header('Authorization')));
     } else {
         return response('Invalid API token.', 401);
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         $session = LegacySession::loadFromRequest($request);
         if ($session !== null) {
             $request->session()->flush();
             $request->session()->regenerateToken();
             $this->auth->loginUsingId($session->session_user_id, $session->session_autologin);
         }
     }
     return $next($request);
 }
 /**
  * Handle user connected via social auth.
  *
  * @param  \Orchestra\OAuth\User  $model
  * @param  array  $data
  * @param  \Illuminate\Contracts\Auth\Guard  $auth
  *
  * @return void
  */
 public function handle(Eloquent $model, array $data, Guard $auth)
 {
     if ($auth->check()) {
         return;
     }
     if (!is_null($id = $this->getAuthenticatedUser($model))) {
         $auth->loginUsingId($id, true);
     }
 }
 /**
  * @param $token
  * @param TokenRepository $tokens
  * @param ResetPasswordRequest $request
  * @param Guard $guard
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update($token, TokenRepository $tokens, ResetPasswordRequest $request, Guard $guard)
 {
     $token = $tokens->findTokenByValue($token);
     if ($token) {
         $user = $this->dispatch(new ResetPassword($request->get('email'), $token, $request->get('password'), $request->get('password_confirmation')));
         if ($user) {
             $guard->loginUsingId($user->id);
             return redirect('admin/start');
         }
     }
     //always redirect to signin if we get here.
     //the request was validated for correct input, so if the reset was no success,
     //we simply bail out for security reasons.
     return redirect()->to(store_route('store.auth.signin.index'))->withSuccess(Lang::get('users::front.request-handled'));
 }
Exemple #6
0
 /**
  * Handle a login request to the application.
  *
  * @param AuthRequest $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(AuthRequest $request)
 {
     $throttles = in_array(ThrottlesLogins::class, class_uses_recursive(get_class($this)));
     if ($throttles && $this->hasTooManyLoginAttempts($request)) {
         return $this->respondThrottled($request);
     }
     if (!$this->auth->once($request->only('email', 'password'))) {
         if ($throttles) {
             $this->incrementLoginAttempts($request);
         }
         return $this->respondLoginFail($request);
     }
     $user = $this->auth->getUser();
     if (!$user->activated) {
         $this->auth->logout();
         return $this->respondNotActivated($request, $user->activation_code);
     }
     $this->auth->loginUsingId($user->id, $request->has('remember'));
     if ($throttles) {
         $this->clearLoginAttempts($request);
     }
     event('UserHasLoggedIn', [$this->auth->user()]);
     return $this->respondLoginSuccess($request, $user);
 }
Exemple #7
0
 /**
  * @param UserRepositoryInterface $users
  * @param Guard $guard
  * @return mixed
  * @throws \Exception
  */
 public function handle(UserRepositoryInterface $users, Guard $guard)
 {
     $user = $users->findUserByConfirmationToken($this->token->id);
     if ($user) {
         if (!$user->confirmed) {
             $user->confirmed = 1;
         }
         //only reset the token if we actually found a user
         $user->confirmation_token_id = null;
         $user->save();
         $guard->loginUsingId($user->id);
     }
     //token can always be deleted
     $this->token->delete();
     return $user;
 }