Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过facebook登录时根据pk设置用户id_Facebook_Yii - Fatal编程技术网

通过facebook登录时根据pk设置用户id

通过facebook登录时根据pk设置用户id,facebook,yii,Facebook,Yii,我可以使用facebook登录/注销我的web应用程序。但问题是,当用户需要在我的应用程序上更新他的个人资料时,他不能。据说他只能浏览自己的网页。发生这种情况的唯一方法是可能未设置用户标识。但我不知道如何纠正这一点。当我尝试Yii::app()->user->user\u id时,id实际上是正确的id,这是用户模型中的主键。那么,为什么他不能更新自己的页面呢 在我的facebookUserIdentity中: public function authenticate()

我可以使用facebook登录/注销我的web应用程序。但问题是,当用户需要在我的应用程序上更新他的个人资料时,他不能。据说他只能浏览自己的网页。发生这种情况的唯一方法是可能未设置用户标识。但我不知道如何纠正这一点。当我尝试
Yii::app()->user->user\u id
时,id实际上是正确的id,这是用户模型中的主键。那么,为什么他不能更新自己的页面呢

在我的facebookUserIdentity中:

    public function authenticate() 
        {
            if($this->getIsAccessTokenValid() && $this->setFBUser())
            {
                $this->_user = $this->getUserFromDatabase();
                if($this->_user === false)
                    return false;

                $this->setState('isUser', false);
                $this->setState('isAdmin', false);
                $this->setState('isShop', false);
                $this->setState('isSuper', false);
                $this->setState('user',$this->_user);

                $this->_id = $this->_FBUser['id'];
//I've tried doing something like $this->_id = Yii::app()->user->user_id; or like $this->_user->user_id; ?
                $this->_name = $this->_FBUser['name'];

                return true;
            }
            else {
                return false;
            }
        }
正在从数据库获取用户:

protected function getUserFromDatabase()
    {
        $FBUser = $this->_FBUser;

        if($FBUser)
        {
            $user = User::model()->findByAttributes (array('oauth_uid'=>$FBUser['id']));
            if(!$user)
            {
                $user = new User;
                $user->oauth_uid = $FBUser['id'];
                $user->username = $FBUser['id'];
                $user->first_name = $FBUser['first_name'];
              //other info etc

                $user->image = "https://graph.facebook.com/" . $FBUser['id'] . "/picture?type=large";
            }
            else 
            {
                if ($user->oauth_permission == 'n')
                {
                    $this->errorMessage = self::ERROR_LOGIN_DISABLE;
                    return false;
                }
                $user->last_login_date =  date('Y-m-d H:i:s');
            }
            if($user->save())
            {
                return $user;
            }
            else 
                $this->errorMessage = CJSON::encode ( $user->getErrors());
            return false;
        }
        else {
            $this->errorMessage = "Failed getting facebook user data";
            return false;
        }
    }
最后,控制器页面规则:

public function accessRules()
{
$params=array();
$id=Yii::app()->request->getParam('id'); 
$params['model']=$this->loadModel($id);
return array(
    //stuff
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update','RemoveImage'),
'roles'=>array('admin','super','owner'=>$params),
),
    //stuff