当前位置: 首页>>代码示例>>PHP>>正文


PHP Facades\Socialite类代码示例

本文整理汇总了PHP中Laravel\Socialite\Facades\Socialite的典型用法代码示例。如果您正苦于以下问题:PHP Socialite类的具体用法?PHP Socialite怎么用?PHP Socialite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Socialite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handleFbCallback

 public function handleFbCallback()
 {
     $fb_user = Socialite::driver('facebook')->user();
     $user = User::firstOrCreate(['firstname' => $fb_user->user['first_name'], 'lastname' => $fb_user->user['last_name'], 'email' => $fb_user->email]);
     Auth::login($user, true);
     return Redirect::to('/books');
 }
开发者ID:a1ex7,项目名称:librauth,代码行数:7,代码来源:AuthController.php

示例2: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Socialite::extend('google2', function () {
         $config = $this->app['config']['services.google'];
         return Socialite::buildProvider(\App\GoogleProvider::class, $config);
     });
 }
开发者ID:baopham,项目名称:gdrive-comments,代码行数:12,代码来源:AppServiceProvider.php

示例3: facebookCallback

 public function facebookCallback()
 {
     try {
         $facebook = Socialite::driver('facebook')->scopes(['email'])->user();
         // 確認使用者有提供 Email
         if (null === $facebook->getEmail()) {
             throw new OAuthException();
         }
         // 如果 Email 不存在,創見帳號,如 Email 已存在,則略過此步驟
         if (null === ($account = Account::where('email', '=', $facebook->getEmail())->first(['id']))) {
             $account = Account::create(['email' => $facebook->getEmail(), 'password' => str_random(32)]);
             if (!$account->exists) {
                 throw new ModelNotFoundException();
             }
             $account->load(['user'])->getRelation('user')->update(['nickname' => $facebook->getName() . '@facebook']);
         }
         \Auth::loginUsingId($account->getAttribute('id'), true);
         return redirect()->route('home');
     } catch (ClientException $e) {
         $data = ['您似乎並未允許本網站存取您的資料', false];
     } catch (InvalidStateException $e) {
         $data = ['似乎出了點狀況,請嘗試重新登入', false];
     } catch (ModelNotFoundException $e) {
         $data = ['網站似乎出了點狀況,請稍候再嘗試', false];
     } catch (OAuthException $e) {
         $data = ['您似乎並未允許本網站存取您的信箱', true];
     } catch (\Exception $e) {
         $data = ['網站似乎出了點狀況,請稍候再嘗試', false];
         \Log::error('Non-catch exception.', ['code' => $e->getCode(), 'message' => $e->getMessage()]);
     }
     return view('errors.oauthFailed', ['message' => $data[0], 'invalidEmail' => $data[1]]);
 }
开发者ID:BePsvPT,项目名称:CCU,代码行数:32,代码来源:OAuthController.php

示例4: handle

 /**
  * 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);
     }
 }
开发者ID:jbmadking,项目名称:bottlestore,代码行数:12,代码来源:FindOrCreateSocialiteUser.php

示例5: handleGoogleProviderCallback

 /**
  * Obtain the user information from Google.
  *
  * @param Request $request
  * @return Socialite ->user()
  */
 public function handleGoogleProviderCallback(Request $request)
 {
     if ($request->get('error') == "access_denied") {
         return redirect('/');
     }
     $authorizationCode = $request->get('code');
     $googleTokens = Tokens::getGoogleTokens($authorizationCode);
     //return var_dump($googleTokens);
     $user = Socialite::driver('google')->getUserByToken($googleTokens->access_token);
     $email = $user['emails'][0]['value'];
     $name = $user['name']['givenName'] . " " . $user['name']['familyName'];
     $avatar = $user['image']['url'];
     if (!GoogleUser::existsByEmailAndId($email, Auth::user()->id) && isset($googleTokens->refresh_token)) {
         GoogleUser::create(['user_id' => Auth::user()->id, 'email' => $email, 'names' => $name, 'avatar' => $avatar, 'googleAccessToken' => $googleTokens->access_token, 'googleRefreshToken' => $googleTokens->refresh_token, 'uriCode' => $authorizationCode, 'expireValue' => $googleTokens->expires_in]);
         return redirect('/availability/google')->with(['message' => 'You have linked this profile (' . $email . ')']);
     } elseif (GoogleUser::existsByEmailAndId($email, Auth::user()->id) && isset($googleTokens->refresh_token)) {
         $id = GoogleUser::where('email', '=', $email)->where('user_id', '=', Auth::user()->id)->select('id')->first()->pluck('id')['id'];
         GoogleUser::updateTokens($id, ['googleAccessToken' => $googleTokens->access_token, 'googleRefreshToken' => $googleTokens->refresh_token, 'uriCode' => $authorizationCode, 'expireValue' => $googleTokens->expires_in]);
         return redirect('/availability/google')->with(['message' => 'You already have this profile (' . $email . '). Data is updated.']);
     } elseif (GoogleUser::existsByEmailAndId($email, Auth::user()->id) && !isset($googleTokens->refresh_token)) {
         return redirect('/availability/google')->with(['message' => 'You already have this profile (' . $email . ')']);
     } elseif (!GoogleUser::existsByEmailAndId($email, Auth::user()->id) && !isset($googleTokens->refresh_token)) {
         return redirect('/availability/google')->withErrors(['Missing refresh token. Contact the administrator.']);
     } else {
         return var_dump($authorizationCode, $googleTokens, $user);
         abort(500, "Auth error. Contact the admin");
     }
     return redirect('/availability/google');
 }
开发者ID:svetlinyotov,项目名称:Timeline_v2.0,代码行数:35,代码来源:AuthController.php

示例6: handleProviderCallback

 public function handleProviderCallback($provider, Request $request)
 {
     try {
         $user = Socialite::driver($provider)->user();
         if (!empty($request->session()->get('token'))) {
             $userPending = User::where('remember_token', $request->session()->get('token'))->first();
             if (empty($userPending) || $userPending->email != $user->email) {
                 if ($provider == 'google') {
                     $request->session()->flash('error', Lang::get("general.LoginGoogleFailed"));
                 } else {
                     $request->session()->flash('error', Lang::get("general.LoginFacebookFailed"));
                 }
                 return redirect('/create-account/' . $request->session()->get('token'));
             }
             $userPending->pending_company_id = null;
             $userPending->save();
         }
     } catch (\Exception $e) {
         if ($provider == 'google') {
             $request->session()->flash('error', Lang::get("general.LoginGoogleFailed"));
         } else {
             $request->session()->flash('error', Lang::get("general.LoginFacebookFailed"));
         }
         return redirect('/auth/login');
     }
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect('/');
 }
开发者ID:alientronics,项目名称:fleetany-web,代码行数:29,代码来源:SocialLoginController.php

示例7: getSocialHandle

 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     $userCheck = User::where('email', '=', $user->email)->first();
     // Create new user id doesn't exists
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $socialUser = User::create(['name' => $user->name, 'email' => $user->email, 'avatar' => $user->avatar]);
     }
     // End
     // Update social information
     if ($socialUser->google() and $provider == 'google') {
         $socialUser->google()->save($this->fillSocialData($user));
     }
     if ($socialUser->facebook() and $provider == 'facebook') {
         $socialUser->facebook()->save($this->fillSocialData($user));
     }
     if ($socialUser->twitter() and $provider == 'twitter') {
         $socialUser->twitter()->save($this->fillSocialData($user));
     }
     // End
     // Authenticate user
     Auth::login($socialUser);
     // End
     return redirect()->route('home');
 }
开发者ID:leloulight,项目名称:holidays-on-village,代码行数:28,代码来源:AuthController.php

示例8: callback

 public function callback(SocialAccountService $service, $provider)
 {
     $driver = Socialite::driver($provider);
     $user = $service->createOrGetUser($driver, $provider);
     Auth::login($user, true);
     return redirect()->intended('/');
 }
开发者ID:avil13,项目名称:lab.friends,代码行数:7,代码来源:SocialController.php

示例9: handleProviderCallback

 public function handleProviderCallback()
 {
     $user = Socialite::with('battlenet')->user();
     $authUser = $this->findOrCreateUser($user);
     Auth::login($authUser, true);
     return redirect()->route('home');
 }
开发者ID:Kehet,项目名称:wow-calendar,代码行数:7,代码来源:AuthController.php

示例10: google

 /**
  *
  * @param Request $request
  *
  * @return mixed
  */
 public function google(Request $request)
 {
     if ($request->has('redirectUri')) {
         config()->set("services.google.redirect", $request->get('redirectUri'));
     }
     $provider = Socialite::driver('google');
     $provider->stateless();
     $profile = $provider->user();
     $email = $profile->email;
     $name = $profile->name;
     $google_token = $profile->token;
     $google_id = $profile->id;
     $user = User::where('email', $email)->first();
     if (is_null($user)) {
         $data = ['email' => $email, 'name' => $name, 'password' => null, 'confirmation_code' => null, 'confirmed' => '1', 'social_auth_provider_access_token' => $google_token, 'google_id' => $google_id, 'social_auth_provider' => 'google', 'social_auth_provider_id' => $google_id];
         $user = User::create($data);
         $response = Response::json($user);
         return $response;
     } else {
         $user->google_id = $google_id;
         $user->social_auth_provider_access_token = $profile->token;
         $user->social_auth_provider_id = $profile->id;
         $user->social_auth_provider = 'google';
         $user->save();
         $response = Response::json($user);
         return $response;
     }
 }
开发者ID:Scaledesk,项目名称:gritwings,代码行数:34,代码来源:AuthController.php

示例11: getSocialAuthCallback

 public function getSocialAuthCallback($provider = null)
 {
     if ($user = Socialite::with($provider)->user()) {
         dd($user);
     } else {
         return 'something went wrong';
     }
 }
开发者ID:sangemi,项目名称:boon-v1,代码行数:8,代码来源:AuthController.php

示例12: getLogin

 /**
  * 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');
 }
开发者ID:picolit,项目名称:bbs,代码行数:14,代码来源:SocialLoginController.php

示例13: handleProviderCallback

 public function handleProviderCallback()
 {
     //notice we are not doing any validation, you should do it
     $user = Socialite::driver($provider)->user();
     // stroing data to our use table and logging them in
     $data = ['name' => $user->getName(), 'google' => $user->getEmail()];
     Auth::login(User::firstOrCreate($data));
     //after login redirecting to home page
     return redirect($this->redirectPath());
 }
开发者ID:ncs-jss,项目名称:elastic-heart,代码行数:10,代码来源:AuthController.php

示例14: handleProviderCallback

 public function handleProviderCallback($provider)
 {
     //notice we are not doing any validation, you should do it
     $user = Socialite::driver($provider)->user();
     // stroing data to our use table and logging them in
     $data = ['name' => $user->getName(), 'email' => $user->getEmail()];
     //   Auth::login(User::firstOrCreate($data));
     //after login redirecting to home page
     return "<h1>Hello " . $user->getName() . "</h1>";
 }
开发者ID:ncs-jss,项目名称:elastic-heart,代码行数:10,代码来源:AuthController.php

示例15: getSocialHandle

 public function getSocialHandle($provider)
 {
     $user = Socialite::driver($provider)->user();
     $socialUser = null;
     //Check is this email belongs to OZU
     if (!preg_match('/((ozu|ozyegin)\\.edu(\\.[a-zA-Z]+)?|\\.ac\\.[a-zA-Z]+)$/i', $user->email)) {
         return redirect()->route('auth.login')->with('message', 'You can only login with your.name@(ozu|ozyegin).edu.tr')->with('status', 'danger')->withInput();
     }
     //Check is this email present
     $userCheck = User::where('email', '=', $user->email)->first();
     if (!empty($userCheck)) {
         $socialUser = $userCheck;
     } else {
         $sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
         if (empty($sameSocialId)) {
             //There is no combination of this social id and provider, so create new one
             $newSocialUser = new User();
             $newSocialUser->email = $user->email;
             $parts = explode("@", $user->email);
             $username = explode(".", $parts[0]);
             $alt_name = ucfirst($username[0]);
             $alt_last = ucfirst($username[1]);
             $name = explode(' ', $user->name);
             $newSocialUser->first_name = isset($name[0]) && !empty($name[0]) ? $name[0] : $alt_name;
             $newSocialUser->last_name = isset($name[2]) ? $name[2] : (isset($name[1]) ? $name[1] : $alt_last);
             $newSocialUser->save();
             $socialData = new Social();
             $socialData->social_id = $user->id;
             $socialData->provider = $provider;
             $newSocialUser->social()->save($socialData);
             // Add role
             if (in_array($user->email, $this->privilegedEmails)) {
                 $role = Role::whereName('administrator')->first();
             } else {
                 $role = Role::whereName('user')->first();
             }
             $newSocialUser->assignRole($role);
             $socialUser = $newSocialUser;
         } else {
             //Load this existing social user
             $socialUser = $sameSocialId->user;
         }
     }
     $this->auth->login($socialUser, true);
     if ($this->auth->user()->hasRole('user')) {
         return redirect('/');
     }
     if ($this->auth->user()->hasRole('administrator')) {
         return redirect('/');
     }
     if ($this->auth->user()->hasRole('super')) {
         return redirect('/');
     }
     return App::abort(500);
 }
开发者ID:nouzun,项目名称:gamification,代码行数:55,代码来源:AuthController.php


注:本文中的Laravel\Socialite\Facades\Socialite类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。