1
votes

I've uploaded my Yii application to an Ubuntu 12.04 server running PHP5 and Apache2.x. The .htaccess file contains:

RewriteEngine on
RewriteBase /

The UserController.php in /protected/controllers contains:

 public function actionLogin()
{
    $model= new Users();

    // if it is ajax validation request
    if(isset($_POST['ajax']))
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }
//                print_r($_POST['Users']);
    // collect user input data
    if(isset($_POST['Users']))
    {
        $model->attributes=$_POST['Users'];


        // validate user input and redirect to the previous page if valid
        if($model->login())
            $this->redirect(Yii::app()->user->returnUrl);
    }
    // display the login form
    $this->render('login',array('model'=>$model));
}

When I login to the site, I receive an HTTP404 message. The apache2 error.log states

file does not exist /var/www/users

How can I rectify this 404 error?

UPDATE:
It doesn't appear that returnURL is valued. How do I setup returnUrl so that the user is redirected back to the previous page?

UPDATE2: Here is a snippet from config/main.php:

'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'rules'=>array(
            '<controller:\w+>/<id:\d+>'=>'<controller>/view',
            '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
            '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        ),

Here's the contents of the main .htacess file:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*)\?*$ admin.php/$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]

php_value upload_max_filesize 20M
php_value post_max_size 21M  

UPDATE: It looks like the root cause might be relative to the UserIdentity class being used to authenticate. Here's a snippet of the users model:

public function login()
{

        if($this->_identity===null)
        {
                $this->_identity=new UserIdentity($this->username,md5($this->password));
                $this->_identity->authenticate();
        }
        if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
        {
                $duration=$this->rememberMe ? 3600*24*30 : 60*20; // 30 days
                Yii::app()->user->login($this->_identity,$duration);
                return true;
        }
        else{
                $this->addError('password','Incorrect username or password.');
                return false;
        }
}

Would it be advisable to use CdbHttpSession insead of UserIdentity to accomplish login?

3
what do you have returnlUrl set to in the user module? - ernie
I can't seem to locate it. Would that be in the user model? - SidC

3 Answers

1
votes

I think there is a problem with your .htaccess and Yii main configuration.

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

I think if you have setup your config/main.php properly (can you put update the question with that ,specifically the urlManager part), You .htaccess needs to be

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
0
votes

Try changing

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

to

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

HTH

0
votes

You can explicitly set the returnUrl by using:

Yii::app()->user->setReturnUrl('controller/action');

Where you put it is up to you, I'd probably set it in the components/userIdentity.php class when you're validating the passwords etc, or you could set it in your $model->validate() method.