Facebook登录显示未定义的索引:仅针对gmail用户的电子邮件

时间:2015-09-26 18:37:48

标签: facebook login gmail

我已经为我的网站登录了App和facebook。但我测试了它,它适用于其他类型的邮件。我现在尝试使用gmail,它显示: ErrorException [ Notice ]: Undefined index: email

我的方法是:

 public function action_fbLogin(){
      
        $facebook = new Facebook(array(
            'appId'  => 'MyAppId',
            'secret' => 'MySecret',
        ));

        $user = $facebook->getUser();
        if ($user) {

            $user_profile = $facebook->api('/me', array('fields' => 'id,email,name,first_name,last_name,picture')); 
         
            $user_id = Model_UserFunctions::checkIfUserExist($user_profile['email']); 
            if($user_id > 0)
            {
                
                Session::instance()->set('user', array(
                    'fb_id' => $user_profile['id'],
                    'user_id' => $user_id,
                    'pic' => $user_profile['picture'],
                    'email' => $user_profile['email'],
                    'first_name' =>  $user_profile['first_name'],
                    'last_name' =>  $user_profile['last_name'],
                ));
                
             
                $this->redirect('profile');
                exit;
            }
            $values = array(
                    'email' => $user_profile['email'],
                    'username' => $user_profile['email'],
                    'password' => '12345678'
                );
            $user = ORM::factory ( 'User' );
            $user->values($values);
            try
            {
                if($user->save()){
                    $user_new_id = $user->as_array();
                    $user_new_id = $user_new_id['id'];
                    Session::instance()->set('user', array(
                            'fb_id' => $user_profile['id'],
                            'user_id' => $user_new_id,
                            'pic' => $user_profile['picture'],
                            'email' => $user_profile['email'], 
                            'first_name' => $user_profile['first_name'],
                            'last_name' => $user_profile['last_name'],
                        ));
                    
                    $this->redirect('profile');
                }


            }
            catch (ORM_Validation_Exception $e)
            {
                $result = $e->errors('models');
                echo '<pre>';
                print_r($result);
                exit;
            }


        }
        else 
        {
            
            $this->redirect($facebook->getLoginUrl(array('id,email,name,first_name,last_name,picture'))); 
        }
        exit;
    
    }

我应该为我的gmail用户代码添加其他内容吗?提前谢谢!

编辑:我的logut方法是:

 public  function action_logout(){
        Session::instance()->delete('user');
        $this->redirect('/');
    }

也许问题是它没有注销。我不确定。虽然我使用不同的用户登录,但它向我显示了相同的用户数据。

0 个答案:

没有答案
相关问题