Yii Framework Forum: the weirdest problem I encountered. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

the weirdest problem I encountered. pls take a look... Rate Topic: -----

#1 User is offline   kael 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 13-September 10
  • Location:静岡、 静岡、 日本 と フィリピン

Posted 14 September 2010 - 08:16 PM

Posted Image

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!
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 September 2010 - 02:44 AM

You are comparing the entered password to Yii::app()->params['password'] so check there what you have put as password (config/main.php).
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   kael 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 140
  • Joined: 13-September 10
  • Location:静岡、 静岡、 日本 と フィリピン

Posted 15 September 2010 - 04:32 AM

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

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,353
  • Joined: 12-October 09
  • Location:Croatia

Posted 15 September 2010 - 04:39 AM

Glad you solved it...

No need to erase this post... someone can have similar problem and find this post usefull...
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 29 September 2010 - 05:52 AM

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~
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users