/**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     if (in_array($this->provider, $this->allowedProviders)) {
         $user = User::findByUserNameOrCreate(Socialite::with($this->provider)->user());
         $this->auth->login($user);
     }
 }
Ejemplo n.º 2
0
 public function handleProviderCallback()
 {
     $user = Socialite::with('battlenet')->user();
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect()->route('home');
 }
 public function getSocialRedirect($provider)
 {
     $providerKey = \Config::get('services.' . $provider);
     if (empty($providerKey)) {
         return view('pages.status')->with('error', 'No such provider');
     }
     return Socialite::with($provider)->redirect();
 }
Ejemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  * @Get("/{provider}/callback", as="social.login.getLogin")
  * @param string $provider
  * @return \Illuminate\Http\Response
  */
 public function getLogin($provider)
 {
     $userData = Socialite::with($provider)->user();
     Log::debug(print_r($userData, true));
     $user = User::firstOrCreate(['username' => $userData->nickname, 'email' => $userData->email]);
     Auth::login($user);
     return response()->redirectToRoute('articles.getIndex');
 }
Ejemplo n.º 5
0
 public function getSocialAuthCallback($provider = null)
 {
     if ($user = Socialite::with($provider)->user()) {
         dd($user);
     } else {
         return 'something went wrong';
     }
 }
Ejemplo n.º 6
0
 /**
  * Obtain the user information from Google.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     try {
         $user = Socialite::with('google2')->user();
     } catch (ClientException $e) {
         Log::error($e->getResponse()->getBody()->getContents());
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('/');
 }
 public function logged_in($type)
 {
     $userData = Socialite::with($type)->user();
     $email = $userData->email;
     if (empty($email)) {
         //Fallback on nickname for twitter
         $email = $userData->nickname;
     }
     //TODO: Save email/nickname in login column
     //TODO: Add displayname and ask for it after login
     //TODO: Ask for email after login
     $user = User::firstOrNew(['email' => $email, 'name' => $userData->name]);
     $user->save();
     Auth::login($user, true);
     return redirect('/');
 }
Ejemplo n.º 8
0
 public function handleProviderGoogleCallback()
 {
     $userSocilite = Socialite::with('google')->user();
     $data = ['name' => $userSocilite->name, 'email' => $userSocilite->email, 'password' => $userSocilite->token];
     $user = User::where('email', '=', $userSocilite->email)->first();
     if ($user) {
         Auth::login($user);
         return redirect('home')->with(['success', trans('messages.success.login')]);
     } else {
         if ($this->create($data)) {
             $user->roles()->attach(3);
             $user = User::where('email', '=', $userSocilite->email)->first();
             Auth::login($user, true);
             return redirect('home')->with(['success', trans('messages.success.login')]);
         }
         return redirect('home')->with(['error', trans('messages.error.login')]);
     }
 }
 public function facebook_handleProviderCallback()
 {
     $user = \Laravel\Socialite\Facades\Socialite::with('facebook')->stateless()->user();
     echo $user->getName();
     return view('facebook');
 }
Ejemplo n.º 10
0
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use Illuminate\Support\Facades\Route;
use Laravel\Socialite\Facades\Socialite;
use App\Developer;
Route::get('/', function () {
    $developers = Developer::all();
    return view("index", ["developers" => $developers]);
});
Route::get("redirect/github", function () {
    return Socialite::with("github")->redirect();
});
Route::get("connect/github", function () {
    $data = Socialite::with("github")->user();
    $developer = Developer::where("github_id", $data->id)->first();
    if (!$developer) {
        Developer::create(["github_id" => $data->id, "github_nickname" => $data->nickname, "github_name" => $data->name, "github_email" => $data->email, "github_avatar" => $data->avatar]);
    }
    return redirect("/");
});
Ejemplo n.º 11
0
 public function callback($slug)
 {
     if (Input::has('code')) {
         $provider = Provider::where('slug', '=', $slug)->firstOrFail();
         try {
             $extern_user = Socialite::with($slug)->user();
         } catch (InvalidStateException $e) {
             return Redirect::to('/auth/login')->withErrors(['授权失效']);
         }
         //检查是否已经连接过
         $identity = Identity::where('provider_id', '=', $provider->id)->where('extern_uid', '=', $extern_user->id)->first();
         if (is_null($identity)) {
             Session::put('connect_data', ['provider_id' => $provider->id, 'extern_uid' => $extern_user->id, 'nickname' => $extern_user->nickname]);
             return Redirect::to('/auth/landing');
         }
         //已经连接过,找出user_id, 直接登录
         $user = User::find($identity->user_id);
         if (!Auth::check()) {
             Auth::login($user, true);
             //event(new UserWasLoggedinEvent($user));
         }
         return Redirect::to('/')->withSuccess(sprintf('%s %s', trans('gitamin.awesome'), trans('gitamin.login.success_oauth', ['provider' => $provider->name])));
     }
 }
Ejemplo n.º 12
0
 public function pageFacebook()
 {
     $user = Socialite::with('facebook')->user();
     return response()->json($user);
 }
Ejemplo n.º 13
0
 public function getSocialite()
 {
     $type = $this->request()->segment(3);
     return Socialite::with($type)->redirect();
 }
Ejemplo n.º 14
0
 public function login($provider)
 {
     return Socialite::with($provider)->redirect();
 }
Ejemplo n.º 15
0
 public function callback($provider)
 {
     $provider = strtolower($provider);
     $oauthUser = Socialite::with($provider)->user();
     $uid = OAuthAccount::where('oauth_id', $oauthUser->getId())->where('oauth_type', $provider)->pluck('uid');
     if ($uid && ($user = Sentinel::findById($uid))) {
         Sentinel::login($user);
         return redirect($this->redirectPath());
     }
     // 如果当前第三方账号没有绑定我站账号,那么跳转到绑定账号的页面
     Session::put(self::OAUTH_USER, array('provider' => $provider, 'user' => $oauthUser));
     return redirect()->action('Auth\\AuthController@getBind');
 }
Ejemplo n.º 16
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function login()
 {
     return Socialite::with('qq')->redirect();
 }
Ejemplo n.º 17
0
 /**
  * Obtain the user information from GitHub.
  *
  * @return Response
  */
 public function handleProviderCallback()
 {
     $user = Socialite::with('facebook')->user();
     var_dump($user);
     // $user->token;
 }
Ejemplo n.º 18
0
 /**
  * 登录处理回调
  *
  * @param $social_type
  * @return bool
  */
 protected function callbackHandler($social_type)
 {
     $oauthUser = Socialite::with($social_type)->user();
     if ($user = $this->user->checkExists([$social_type . '_id' => $oauthUser->getId()])) {
         session()->put('user', $user);
         return true;
     }
     switch ($social_type) {
         case 'google':
             $info = ['email' => $oauthUser->getEmail(), 'google_id' => $oauthUser->getId()];
             break;
         case 'github':
             $info = ['email' => $oauthUser->getEmail(), 'github_id' => $oauthUser->getId()];
             break;
         case 'weibo':
             $info = ['weibo_id' => $oauthUser->getId()];
             break;
         case 'weixin':
             return false;
             break;
         case 'qq':
         default:
             $info = ['qq_id' => $oauthUser->getId()];
             break;
     }
     $info += ['username' => $social_type . '_' . dec62(time() . mt_rand(11111, 99999)), 'password' => bcrypt(time() . mt_rand(11111, 99999)), 'avatar' => $oauthUser->getAvatar() ?: ''];
     $user = $this->user->create($info);
     session()->put('user', $user);
     return true;
 }
Ejemplo n.º 19
0
 public function getTwittercallback()
 {
     $user = (array) Socialize::with('twitter')->user();
     if (empty($user)) {
         $this->authError('twitter');
     }
     //检查是否存在此$user->id
     $exist = $this->findBindInfoByid($user['id'], $this->twitterInt);
     if ($exist) {
         $this->actLogin($exist, $user);
     } else {
         $this->actRegistrar($user, 'twitter');
     }
 }
Ejemplo n.º 20
0
 /**
  * Obtain the user information from Google.
  *
  * @Get("/auth/google/callback")
  * @return Response
  */
 public function handleProviderCallback($provider)
 {
     try {
         $user = Socialite::with($provider)->user();
     } catch (Exception $e) {
         return Redirect::to($provider . '/google');
     }
     $authUser = $this->findOrCreateUser($user);
     if ($authUser->roles->isEmpty()) {
         return redirect('/user-unauthorized');
     } else {
         Auth::login($authUser, true);
     }
     return redirect('/#/');
 }
 public function redirectToProvider()
 {
     return Socialite::with('facebook')->redirect();
 }
Ejemplo n.º 22
0
 /**
  * @return string
  */
 public function handleProviderCallback()
 {
     $socialize_user = Socialite::with('facebook')->user();
     $provider_id = $socialize_user->getId();
     // unique facebook user id
     $user = User::where('provider_id', $provider_id)->first();
     // register (if no user)
     if (!$user) {
         $user = new User();
         $user->name = $socialize_user->getName();
         $user->email = $socialize_user->getEmail();
         $user->active = 1;
         $user->confirmation_token = null;
         $user->provider_id = $provider_id;
         $user->save();
     }
     // login
     Auth::loginUsingId($user->id);
     return redirect('/');
     //        return '<h2>'.$user->getName().'<h2>' . '<img src="'.$user->getAvatar().'">';
     //        exit();
 }