the weirdest problem I encountered.

as you see above i’m tring to log in as admin/admin… but i can’t! below is the three files that’s responsible for this: SiteController.php, UserIdentity.php, and the index which has a log in function.

Site: Controller







	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('administrator'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update'),

				'users'=>array('administrator'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('administrator'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays the login page

	 */

	public function actionLogin()

	{

		$model=new LoginForm;

		

			// if it is ajax validation request

		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

		

		// collect user input data

		if(isset($_POST['LoginForm']))

		{

			$model->attributes=$_POST['LoginForm'];

			// validate user input and redirect to the admin page is it's a valid login.

			if($model->validate())

				//$this->redirect(Yii::app()->user->returnUrl);

				$this->redirect( Yii::app()->homeUrl . '/admin' );

		}

		// display the login form

		$this->render('login',array('model'=>$model));

	}


	/**

	 * Logout the current user and redirect to homepage.

	 */

	public function actionLogout()

	{

		Yii::app()->user->logout();

		$this->redirect(Yii::app()->homeUrl);

	}



UserIdentity.php


<?php


/**

 * UserIdentity represents the data needed to identity a user.

 * It contains the authentication method that checks if the provided

 * data can identity the user.

 */

class UserIdentity extends CUserIdentity

{

	/**

	 * Authenticates a user.

	 * This is a simple login, we store the info in the config for now

	 * Might change to a user table in the DB if needed

	 * @return boolean whether authentication succeeds.

	 */

	public function authenticate()

	{

		

	/*	$users=array(

    		// username => password

    	'demo'=>'demo',

    	'admin'=>'admin',

		);*/

		

		$user = (Yii::app()->params['username']);

		$pw   = (Yii::app()->params['password']);


		if(!isset($this->username) || $user !== $this->username)

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		else if($pw !== $this->password)

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		else

			$this->errorCode=self::ERROR_NONE;

		return !$this->errorCode;

	}

}

index.php [of admin]


<?php $this->pageTitle=Yii::app()->name; 


if(Yii::app()->user->isGuest)

            $this->actionLogin();


?>




Please help! thank you very much!

You are comparing the entered password to Yii::app()->params[‘password’] so check there what you have put as password (config/main.php).

it’s cool i got it. how do i erase this post?

Glad you solved it…

No need to erase this post… someone can have similar problem and find this post usefull…

I just wonder your code is written like this




 public function accessRules()

        {

                return array(

                        array('allow',  // allow all users to perform 'index' and 'view' actions

                                'actions'=>array('index','view'),

                                'users'=>array('administrator'),

                        ),

                        array('allow', // allow authenticated user to perform 'create' and 'update' actions

                                'actions'=>array('create','update'),

                                'users'=>array('administrator'),

                        ),

                        array('allow', // allow admin user to perform 'admin' and 'delete' actions

                                'actions'=>array('admin','delete'),

                                'users'=>array('administrator'),

                        ),

                        array('deny',  // deny all users

                                'users'=>array('*'),

                        ),

                );

        }



But you login as ‘admin’. Doesn’t that make the username “admin” can’t access anything?? Just curious~