534643315 2012-05-24 02:43:20 3299次浏览 6条回复 0 0 0
public function authenticate()
{
    Yii::import('application.vendors.*');
    require_once('ucenter.php');

    if (!empty($this->password))
        list($uid, $username, $password, $email) = uc_user_login(strtolower($this->username), $this->password);
    else
        list($uid, $username, $email) = uc_get_user($this->username);

//setcookie()..................验证登陆的时候使cookie过期,而在controller里 也同样调用了这个 authenticate()方法,造成用户被Yii授权后,cookie被清空,当再次执行controller里的方法时,此时用户已是登陆状态,而cookie为空,所以会执行注销操作!!setcookie()应该加在actionLogin()里,当用户提交登陆表单时清空cookie,然后验证通过后再重新产生一个cookie,这样才能实现用户从discuz登陆,再转到YII应用时也是登陆状态。

if ($uid > 0)
{
    $this->_id = $uid;
    $this->username = $username;
    $this->errorCode = self::ERROR_NONE;
    $member= CommonMember::model()->find('uid=? ',array($uid));
    $this->setState('member_type', $member->member_type); 
}
else if ($uid == -1)
{
    $this->errorCode = self::ERROR_USERNAME_INVALID;
}
else if ($uid == -2)
{
    $this->errorCode = self::ERROR_PASSWORD_INVALID;
}
else
{
    $this->errorCode == self::ERROR_NONE;
}

    return $this->errorCode == self::ERROR_NONE;
}
您需要登录后才可以回复。登录 | 立即注册