Yii框架:删除演示/管理员帐户

时间:2012-05-27 08:19:05

标签: php yii

所以我正在学习Yii框架,当你第一次创建sceleton应用程序时,内置的管理员/模拟帐户就有了这个功能。我想删除它们,因为即使在uplodet到我的网络服务器后我仍然可以使用它们登录。那么我在哪里可以删除它?

2 个答案:

答案 0 :(得分:12)

protected / components / 文件夹中,您将有一个文件 UserIdentity.php ,这些默认登录显示在哪里,您可以更改/删除它们。

您可以使用您的数据库对您的用户表进行身份验证,有点像这样:

class UserIdentity extends CUserIdentity
{
 private $_id;
 public function authenticate()
 {
     $record=User::model()->findByAttributes(array('username'=>$this->username));
     if($record===null)
         $this->errorCode=self::ERROR_USERNAME_INVALID;
     else if($record->password!==md5($this->password))
         $this->errorCode=self::ERROR_PASSWORD_INVALID;
     else
     {
         $this->_id=$record->id;
         $this->setState('title', $record->title);
         $this->errorCode=self::ERROR_NONE;
     }
     return !$this->errorCode;
 }

 public function getId()
 {
     return $this->_id;
 }
}

检查this article in the guide

答案 1 :(得分:6)

在protected / components下你会找到UserIdentity.php,用户及其密码将在使用数组的authenticate函数中声明。

public function authenticate()
{
    $users=array(
        // username => password
        'demo'=>'demo',
        'admin'=>'admin',
    );

有关如何在Yii中使用身份验证的更多具体信息可以在官方Yii文档的authentication and authorisation小节中找到

相关问题