Sop*_*oph 10 authentication logging yii
我开始在已经过身份验证的用户和没有经过身份验证的用户之间做出一些区别.为此,我正在使用
Yii::app()->user->id;
Run Code Online (Sandbox Code Playgroud)
但是,在确定的视图中,我输入以下代码:
<?php
if(Yii::app()->user->isGuest) {
print("Welcome back Guest!");
print("Your id is ".Yii::app()->user->id);
} else {
print("Welcome back ".Yii::app()->user->name);
print("Your id is ".Yii::app()->user->id);
}?>
Run Code Online (Sandbox Code Playgroud)
我总是得到"欢迎回来的客人!",无论我是否已登录(成功).如果我已登录,则会显示欢迎消息以及用户的ID!
编辑
@ briiC.lv嘿..对于迟到的回复感到抱歉,我希望你还在关注这个!我没有扩展给定的UserIdentity类.这是强制性的吗?因为我仍然没有得到很好的整体授权方面的问题,我认为这将是最好给它们提供了一流的尝试,然后用我自己的功能扩展.不管怎么样,接下来我后我的UserIdentity类与它的小的调整.也许问题出在这里?
<?php class UserIdentity extends CUserIdentity{
private $_id;
public function authenticate()
{
$user = Users::model()->findAll('username=\''.$this->username.'\' AND password=\''.$this->encryptedPassword.'\'');
if(!isset($user[0]))
{
return false;
}
else
{
$this->setState('id', $user[0]->id);
$this->username = $user[0]->username;
$this->errorCode=self::ERROR_NONE;
return true;
}
}
public function getId()
{
return $this->_id;
}
Run Code Online (Sandbox Code Playgroud)
}
这是我按照你的建议开始记录时得到的输出; 成功登录后立即获得此输出.
[05:23:21.833][trace][vardump] CWebUser#1 (
[allowAutoLogin] => true
[guestName] => 'Guest'
[loginUrl] => array ( '0' => '/site/login' )
[identityCookie] => null
[authTimeout] => null
[autoRenewCookie] => false
[autoUpdateFlash] => true
[CWebUser:_keyPrefix] => '0f4431ceed8f17883650835e575b504b'
[CWebUser:_access] => array()
[behaviors] => array()
[CApplicationComponent:_initialized] => true
[CComponent:_e] => null
[CComponent:_m] => null
)
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢!
也许你可以尝试更难调试:将消息更改为以下内容:
if(Yii::app()->user->isGuest) {
print("Not logged");
} else {
print_r(Yii::app()->user);
print("Welcome ".Yii::app()->user->name);
print("Your id is ".Yii::app()->user->id);
}
Run Code Online (Sandbox Code Playgroud)
并在config/main.php文件中检查会话变量
...
'session' => array(
'autoStart'=>true,
),
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46352 次 |
| 最近记录: |