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


PHP User::createOrUpdateGraphNode方法代码示例

本文整理汇总了PHP中app\User::createOrUpdateGraphNode方法的典型用法代码示例。如果您正苦于以下问题:PHP User::createOrUpdateGraphNode方法的具体用法?PHP User::createOrUpdateGraphNode怎么用?PHP User::createOrUpdateGraphNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\User的用法示例。


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

示例1: authenticateFromJavascript

 /**
  * Callback to log in users from Facebook. Be warned; it's messy.
  */
 public function authenticateFromJavascript(Request $request, LaravelFacebookSdk\LaravelFacebookSdk $fb)
 {
     // Try to grab the Facebook API token that the SDK should give us
     try {
         $token = $fb->getJavaScriptHelper()->getAccessToken();
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // Failed to obtain access token; error out
         return Redirect::to('/login')->withErrors([$e->getMessage()]);
     }
     if (!$token) {
         // If the token is falsy... uhh, what the hell
         return Redirect::to('/login')->withErrors(["You haven't logged into Facebook correctly."]);
     }
     if (!$token->isLongLived()) {
         // OAuth 2.0 client handler. This is... a thing.
         $oauth_client = $fb->getOAuth2Client();
         // Extend the access token.
         try {
             $token = $oauth_client->getLongLivedAccessToken($token);
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             return Redirect::to('/login')->withErrors([$e->getMessage()]);
         }
     }
     // Keep the User Access Token in Session storage, so we can use it for this request
     $data = $request->all();
     Session::put('fb_user_access_token', (string) $token);
     if (isset($data["from"])) {
         Session::put('fb_logged_in_from', (string) $data["from"]);
     }
     // Use the user's access token by default for this request
     $fb->setDefaultAccessToken($token);
     try {
         // Request Facebook user data
         $response = $fb->get('/me?fields=id,name,email,location,bio,picture.width(800).height(800)');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         return Redirect::back()->withErrors([$e->getMessage()]);
     }
     // get a Graph User object
     $facebook_user = $response->getGraphUser();
     try {
         $user = User::where('facebook_id', $facebook_user["id"])->firstOrFail();
     } catch (ModelNotFoundException $e) {
         $facebook_user["username"] = $facebook_user["id"];
         $user = User::createOrUpdateGraphNode($facebook_user);
     }
     // Use the Graph User to create a Laravel User with their data
     Auth::login($user);
     if (!$user->username) {
         $user->username = $user->facebook_id;
         $user->save();
         return Redirect::to('/user/editProfile')->with('message', 'Almost set up! Please fill out your profile...');
     }
     // Log the user into Laravel
     return Redirect::back();
 }
开发者ID:TheJokersThief,项目名称:Eve,代码行数:58,代码来源:FacebookController.php

示例2: getJsCallback

 public function getJsCallback($auxToken)
 {
     $fb = App::make('SammyK\\LaravelFacebookSdk\\LaravelFacebookSdk');
     // Obtain an access token.
     try {
         $token = $fb->getJavaScriptHelper()->getAccessToken();
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         // Failed to obtain access token
         dd($e->getMessage());
     }
     // Access token will be null if the user denied the request
     // or if someone just hit this URL outside of the OAuth flow.
     if (!$token) {
         $token = $auxToken;
         //return redirect( $fb->getLoginUrl(['email']) );
     }
     $fb->setDefaultAccessToken($token);
     // Save for later
     Session::put('fb_user_access_token', (string) $token);
     // Get basic info on the user from Facebook.
     try {
         $response = $fb->get('/me?fields=id,name,email,picture.type(large)');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     $user = User::createOrUpdateGraphNode($facebook_user);
     $arrContextOptions = array("ssl" => array("verify_peer" => false, "verify_peer_name" => false));
     $img = ImageIntervention::make(file_get_contents($user->url, false, stream_context_create($arrContextOptions)));
     $img->fit(100);
     $img->save(base_path() . '/public/images/profilePhotos/thumb_100_' . md5($user->id) . '.jpg', 100);
     $img = ImageIntervention::make(file_get_contents($user->url, false, stream_context_create($arrContextOptions)));
     $img->fit(50);
     $img->save(base_path() . '/public/images/profilePhotos/thumb_50_' . md5($user->id) . '.jpg', 100);
     // Log the user into Laravel
     Auth::login($user);
     //maybe this need to redirect back to the originating page
     if (Session::has('profileId')) {
         return redirect('/profile/index/' . Session::get('profileId'));
     } else {
         return redirect('/register');
     }
 }
开发者ID:ElasticOrange,项目名称:canon-orasul-respira-foto,代码行数:46,代码来源:FacebookController.php

示例3: fbCallback

 public function fbCallback(\SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb)
 {
     // Obtain an access token.
     try {
         $token = $fb->getAccessTokenFromRedirect();
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Access token will be null if the user denied the request
     // or if someone just hit this URL outside of the OAuth flow.
     if (!$token) {
         // Get the redirect helper
         $helper = $fb->getRedirectLoginHelper();
         if (!$helper->getError()) {
             abort(403, 'Unauthorized action.');
         }
         // User denied the request
         dd($helper->getError(), $helper->getErrorCode(), $helper->getErrorReason(), $helper->getErrorDescription());
     }
     if (!$token->isLongLived()) {
         // OAuth 2.0 client handler
         $oauth_client = $fb->getOAuth2Client();
         // Extend the access token.
         try {
             $token = $oauth_client->getLongLivedAccessToken($token);
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             dd($e->getMessage());
         }
     }
     $fb->setDefaultAccessToken($token);
     // Save for later
     Session::put('fb_user_access_token', (string) $token);
     // Get basic info on the user from Facebook.
     try {
         $response = $fb->get('/me?fields=id,name,email,picture{url}');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     $user = User::createOrUpdateGraphNode($facebook_user);
     // Log the user into Laravel
     Auth::login($user);
     return redirect('/success')->with('message', $facebook_user);
 }
开发者ID:abada,项目名称:videoGame,代码行数:47,代码来源:NavidadController.php

示例4: login

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function login(Request $request, SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb)
 {
     //test if token for FB login is enough
     $token = $request->token;
     //	return $token;
     // does not work since $token is string but should be token
     //		if (! $token->isLongLived()) {
     //			// OAuth 2.0 client handler
     //			$oauth_client = $fb->getOAuth2Client();
     //
     //			// Extend the access token.
     //			try {
     //				$token = $oauth_client->getLongLivedAccessToken($token);
     //			} catch (Facebook\Exceptions\FacebookSDKException $e) {
     //				dd($e->getMessage());
     //			}
     //		}
     //this is for not include $token in the get calls
     $fb->setDefaultAccessToken($token);
     // Get basic info on the user from Facebook.
     try {
         $response = $fb->get('/me?fields=id,email');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     try {
         $profileresponse = $fb->get('/me?fields=id,name,gender');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     $mecanex_user = $profileresponse->getGraphUser();
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     $user = User::createOrUpdateGraphNode($facebook_user);
     //store profile data in mecanex_users table
     $id = $user->id;
     $facebook_id = $user->facebook_user_id;
     $fullname = $mecanex_user->getName();
     $fullname = explode(" ", $fullname);
     $name = $fullname[0];
     $surname = $fullname[1];
     $gender = $mecanex_user->getGender();
     if ($gender == 'female') {
         $gender_id = 2;
     } else {
         $gender_id = 1;
     }
     $fbuser = MecanexUser::firstOrNew(array('facebook_user_id' => $facebook_id));
     $fbuser->user_id = $id;
     $fbuser->facebook_user_id = $facebook_id;
     $fbuser->gender_id = $gender_id;
     $fbuser->name = $name;
     $fbuser->surname = $surname;
     $fbuser->save();
     // Log the user into Laravel
     Auth::login($user);
     // create records in table users_terms-scores once a mecanex user has been created
     $terms = Term::all();
     foreach ($terms as $term) {
         $fbuser->term()->sync([$term->id => ['user_score' => 0]], false);
     }
     $response = 'User was saved';
     $statusCode = 201;
     return response($response, $statusCode)->header('Content-Type', 'application/json');
 }
开发者ID:skafetzo,项目名称:SPtool,代码行数:72,代码来源:FacebookApiController.php

示例5: login

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function login(Request $request, SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb)
 {
     //test if token for FB login is enough
     $token = $request->token;
     //			return $token;
     // does not work since $token is string but should be token
     //		if (! $token->isLongLived()) {
     //			// OAuth 2.0 client handler
     //			$oauth_client = $fb->getOAuth2Client();
     //
     //			// Extend the access token.
     //			try {
     //				$token = $oauth_client->getLongLivedAccessToken($token);
     //			} catch (Facebook\Exceptions\FacebookSDKException $e) {
     //				dd($e->getMessage());
     //			}
     //		}
     //this is for not include $token in the get calls
     $fb->setDefaultAccessToken($token);
     // Get basic info on the user from Facebook.
     try {
         $response = $fb->get('/me?fields=id,email');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     try {
         $profileresponse = $fb->get('/me?fields=id,name,gender');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     $mecanex_user = $profileresponse->getGraphUser();
     $existing_mecanex_user = MecanexUser::where('email', '=', $facebook_user["email"])->get()->first();
     $existing_user = User::where('email', '=', $facebook_user["email"])->get()->first();
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     if ($existing_user == null) {
         $facebook_user["username"] = "fb_" . $facebook_user["id"];
         $user = User::createOrUpdateGraphNode($facebook_user);
     } else {
         $facebook_user["username"] = $existing_user->username;
         $user = $existing_user;
         $user->facebook_user_id = $facebook_user["id"];
         $user->save();
     }
     //store profile data in mecanex_users table
     $id = $user->id;
     $facebook_id = $user->facebook_user_id;
     if ($existing_mecanex_user == null) {
         $username = "fb_" . $user->facebook_user_id;
     } else {
         $username = $existing_mecanex_user->username;
     }
     $email = $user->email;
     $fullname = $mecanex_user->getName();
     $fullname = explode(" ", $fullname);
     $name = $fullname[0];
     $surname = $fullname[1];
     $gender = $mecanex_user->getGender();
     if ($gender == 'female') {
         $gender_id = 2;
     } else {
         $gender_id = 1;
     }
     $fbuser = MecanexUser::firstOrNew(array('email' => $email));
     $fbuser->username = $username;
     $fbuser->user_id = $id;
     $fbuser->facebook_user_id = $facebook_id;
     $fbuser->gender_id = $gender_id;
     $fbuser->name = $name;
     $fbuser->surname = $surname;
     $fbuser->email = $email;
     $fbuser->save();
     // Log the user into Laravel
     Auth::login($user);
     // create records in table users_terms-scores once a mecanex user has been created
     if ($existing_mecanex_user == null) {
         $terms = Term::all();
         $total_terms = count($terms);
         foreach ($terms as $term) {
             $fbuser->term()->sync([$term->id => ['user_score' => 0]], false);
             $fbuser->profilescore()->sync([$term->id => ['profile_score' => 0]], false);
         }
         for ($i = 1; $i <= $total_terms; $i++) {
             for ($j = $i + 1; $j <= $total_terms; $j++) {
                 $mec_matrix = new MecanexUserTermHomeTermNeighbour();
                 $mec_matrix->mecanex_user_id = $fbuser->id;
                 $mec_matrix->term_home_id = $i;
                 $mec_matrix->term_neighbor_id = $j;
                 $mec_matrix->link_score = 0.05;
                 $mec_matrix->save();
             }
         }
     }
//.........这里部分代码省略.........
开发者ID:vinPopulaire,项目名称:SPtool,代码行数:101,代码来源:FacebookApiController.php

示例6: callback

 public function callback(SammyK\LaravelFacebookSdk\LaravelFacebookSdk $fb)
 {
     //		$token = $fb->getAccessTokenFromRedirect();
     //		dd($token);
     // Obtain an access token.
     try {
         $token = $fb->getAccessTokenFromRedirect();
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Access token will be null if the user denied the request
     // or if someone just hit this URL outside of the OAuth flow.
     if (!$token) {
         // Get the redirect helper
         $helper = $fb->getRedirectLoginHelper();
         if (!$helper->getError()) {
             abort(403, 'Unauthorized action.');
         }
         // User denied the request
         //				echo '<p>Error: ' . $helper->getError();
         //				echo '<p>Code: ' . $helper->getErrorCode();
         //				echo '<p>Reason: ' . $helper->getErrorReason();
         //				echo '<p>Description: ' . $helper->getErrorDescription();
         //				exit ;
         dd($helper->getError(), $helper->getErrorCode(), $helper->getErrorReason(), $helper->getErrorDescription());
     }
     $fb->setDefaultAccessToken($token);
     if (!$token->isLongLived()) {
         // OAuth 2.0 client handler
         $oauth_client = $fb->getOAuth2Client();
         // Extend the access token.
         try {
             $token = $oauth_client->getLongLivedAccessToken($token);
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             dd($e->getMessage());
         }
     }
     //this is for not include $token in the get calls
     $fb->setDefaultAccessToken($token);
     // Get basic info on the user from Facebook.
     try {
         $response = $fb->get('/me?fields=id,email');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     try {
         $profileresponse = $fb->get('/me?fields=id,name,gender');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     $mecanex_user = $profileresponse->getGraphUser();
     $existing_mecanex_user = MecanexUser::where('facebook_user_id', '=', $facebook_user["id"])->get()->first();
     $existing_user = User::where('facebook_user_id', '=', $facebook_user["id"])->get()->first();
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     if ($existing_user == null) {
         $facebook_user["username"] = "fb_" . $facebook_user["id"];
     } else {
         $facebook_user["username"] = $existing_user->username;
     }
     $user = User::createOrUpdateGraphNode($facebook_user);
     //store profile data in mecanex_users table
     $id = $user->id;
     $facebook_id = $user->facebook_user_id;
     if ($existing_mecanex_user == null) {
         $username = "fb_" . $user->facebook_user_id;
     } else {
         $username = $existing_mecanex_user->username;
     }
     $email = $user->email;
     $fullname = $mecanex_user->getName();
     $fullname = explode(" ", $fullname);
     $name = $fullname[0];
     $surname = $fullname[1];
     $gender = $mecanex_user->getGender();
     if ($gender == 'female') {
         $gender_id = 2;
     } else {
         $gender_id = 1;
     }
     $fbuser = MecanexUser::firstOrNew(array('facebook_user_id' => $facebook_id));
     $fbuser->username = $username;
     $fbuser->user_id = $id;
     $fbuser->facebook_user_id = $facebook_id;
     $fbuser->gender_id = $gender_id;
     $fbuser->name = $name;
     $fbuser->surname = $surname;
     $fbuser->email = $email;
     $fbuser->save();
     // Log the user into Laravel
     Auth::login($user);
     if ($existing_mecanex_user == null) {
         // create records in table users_terms-scores once a mecanex user has been created
         $terms = Term::all();
         $total_terms = count($terms);
         foreach ($terms as $term) {
             $fbuser->term()->sync([$term->id => ['user_score' => 0]], false);
             $fbuser->profilescore()->sync([$term->id => ['profile_score' => 0]], false);
//.........这里部分代码省略.........
开发者ID:vinPopulaire,项目名称:SPtool,代码行数:101,代码来源:FacebookLoginController.php

示例7: fbcallback

 public function fbcallback()
 {
     try {
         $token = Facebook::getAccessTokenFromRedirect();
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Access token will be null if the user denied the request
     // or if someone just hit this URL outside of the OAuth flow.
     if (!$token) {
         // Get the redirect helper
         $helper = Facebook::getRedirectLoginHelper();
         if (!$helper->getError()) {
             abort(403, 'Unauthorized action.');
         }
         // User denied the request
         dd($helper->getError(), $helper->getErrorCode(), $helper->getErrorReason(), $helper->getErrorDescription());
     }
     if (!$token->isLongLived()) {
         // OAuth 2.0 client handler
         $oauth_client = Facebook::getOAuth2Client();
         // Extend the access token.
         try {
             $token = $oauth_client->getLongLivedAccessToken($token);
         } catch (Facebook\Exceptions\FacebookSDKException $e) {
             dd($e->getMessage());
         }
     }
     Facebook::setDefaultAccessToken($token);
     // Save for later
     Session::put('fb_user_access_token', (string) $token);
     // Get basic info on the user from Facebook.
     try {
         $response = Facebook::get('/me?fields=id,email,verified');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     // Convert the response to a `Facebook/GraphNodes/GraphUser` collection
     $facebook_user = $response->getGraphUser();
     try {
         $response = Facebook::get('/me?fields=first_name,last_name,name');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     $facebook_profile = $response->getGraphUser();
     try {
         $response = Facebook::get('/me?fields=name');
     } catch (Facebook\Exceptions\FacebookSDKException $e) {
         dd($e->getMessage());
     }
     $facebook_link = $response->getGraphUser();
     $facebook_link = preg_replace('/\\s+/', '', $facebook_link['name']);
     // Create the user if it does not exist or update the existing entry.
     // This will only work if you've added the SyncableGraphNodeTrait to your User model.
     // Create a New User If User Doest Not Exist Yet thru Email
     $data = ['id' => $facebook_user['id'], 'email' => $facebook_user['email'], 'facebook_user_id' => $facebook_user['id'], 'active' => $facebook_user['verified'], 'username' => $facebook_link, 'access_token' => $token];
     $user = User::createOrUpdateGraphNode($data);
     $profile = $user->profile;
     // If User Doesnt Have Profile Create A New One!
     if (!$profile->exists()) {
         $profile = $user->profile()->firstOrNew(['first_name' => $facebook_profile['first_name'], 'last_name' => $facebook_profile['last_name'], 'display_name' => $facebook_profile['name']]);
         $user->profile()->save($profile);
     }
     $links = $user->links;
     // If User Doesnt Have Links Create a New One!
     if (empty($links)) {
         $link = $user->links()->firstOrNew(['link' => $facebook_link]);
         $user->links()->save($link);
     }
     // if User Has No Role Yet Add a Role!
     if (!$user->isNot('customer')) {
         $role = $user->assign('customer');
         $ability1 = \Bouncer::allow($user)->to('add-order', Order::class);
         $ability2 = \Bouncer::allow($user)->to('edit-order', Order::class);
         $ability3 = \Bouncer::allow($user)->to('delete-order', Order::class);
         $ability4 = \Bouncer::allow($user)->to('view-itemOrder', ItemOrder::class);
     }
     // Log the user into Laravel
     $cookie = \Cookie::forget('sponsor');
     \Auth::login($user);
     return redirect('/edit-profile')->withCookie($cookie);
 }
开发者ID:xenxa,项目名称:essensanaturaleonline,代码行数:82,代码来源:AuthController.php


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