本文整理汇总了PHP中Facebook::parseSignedRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::parseSignedRequest方法的具体用法?PHP Facebook::parseSignedRequest怎么用?PHP Facebook::parseSignedRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook
的用法示例。
在下文中一共展示了Facebook::parseSignedRequest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_fb_login
/**
* Logowanie / Rejestracja FB
*/
public function action_fb_login()
{
$response = array('status' => 'error', 'checkmail' => 'none', 'userid' => 'false');
//jeśli nie ma posta
if ($this->request->method() != Request::POST) {
echo json_encode($response);
exit;
}
$data = $this->request->post();
$signed_request = $data['signed_request'];
$access_token = $data['at'];
Session::instance()->set('signed_request', $signed_request);
Session::instance()->set('access_token', $access_token);
//ładowanie obiektu FB
$config = Kohana::$config->load('app');
$facebook = new Facebook(array('appId' => $config->app_id, 'secret' => $config->secret));
$facebook->setAccessToken($access_token);
$authed = $facebook->parseSignedRequest($signed_request);
//jeśli nie ma user_id
if (!isset($authed['user_id'])) {
echo json_encode($response);
exit;
}
$user = ORM::factory('User')->where('fb_id', '=', $authed['user_id'])->find();
if ($user->loaded()) {
//jeśli użytkownik o danym FB_ID jest w bazie, loguj
$response['status'] = 'user_exist';
Auth::instance()->force_login($user);
} else {
//jeśli nie ma, pobierz dane
$user_data_fb = $facebook->api('/me?fields=id,first_name,last_name,name,email,gender');
$user_data_fb['fb_id'] = $user_data_fb['id'];
unset($user_data_fb['id']);
if (!isset($user_data_fb['email'])) {
$user_data_fb['email'] = '';
}
$user = ORM::factory('User')->where('email', '=', $user_data_fb['email'])->where('email', '!=', '')->find();
if ($user->loaded()) {
//jeśli jest mail w bazie, zaktualizuj konto
$user->fb_id = $user_data_fb['fb_id'];
$user->first_name = $user_data_fb['first_name'];
$user->last_name = $user_data_fb['last_name'];
if ($user->name == '') {
$user->name = $user_data_fb['name'];
}
$user->gender = $user_data_fb['gender'];
if ($user->avatar == '' || $user->avatar == URL::base(true) . "media/user/logo.png") {
$user->avatar = 'https://graph.facebook.com/' . $user_data_fb['fb_id'] . '/picture?width=500&height=500';
}
$user->save();
$response['status'] = 'user_update';
} else {
//jeśli nie ma, utwórz konto
$user_data_fb['avatar'] = 'https://graph.facebook.com/' . $user_data_fb['fb_id'] . '/picture?width=500&height=500';
$user_data_fb['role'] = 50;
$user_data_fb['created'] = date("Y-m-d H:i:s");
$id = ORM::factory('User')->register($user_data_fb);
$user = ORM::factory('User', $id);
$response['status'] = 'user_create';
if ($user_data_fb['email'] === '') {
$response['checkmail'] = 'no_mail';
}
}
Auth::instance()->force_login($user);
}
$response['userid'] = $this->logged_in ? Auth::instance()->get_user()->id : 'false';
echo json_encode($response);
exit;
}