Returnurl

Hello,

I’m using BUM for my user management which works fine. But I’m struggling with the returnUrl.

After a successful login, the user should be redirected to entries/index (the controller entries is not part of BUM but part of the normal webapplication, i.e. protected/Controllers/EntriesController).

How can I achieve this behaviour using BUM as login mechanism?

Thanks and regards,

Peter

Hy,

If I understood correctly you want to redirect the users to entries/index after logIn, right?

In order to obtain this functionality you should:

1 extend UsersController of BUM module and rewrite the actionLogIn action; something like:




class testController extends UsersController

{

	/**

 	* @var string the default layout for the views. Defaults to '//layouts/column2', meaning

 	* using two-column layout. See 'protected/views/layouts/column2.php'.

 	*/

	public $layout='/layouts/prbtk2';

    

	public function accessRules()

	{

		return array(

			array('allow',  // 

				'actions'=>array('logIn'),

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

			),

			array('deny',  // deny all users

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

			),

		);

	}

    

	/**

 	* Displays the login page

 	*/

	public function actionLogIn()

	{

		$model = new LoginForm('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 previous page if valid

			if($model->validate() && $model->login())

                                     	$this->redirect(Yii::app()->createUrl("entries/index"));

		}

        

		// display the login form

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

	}


}



this line is important:

$this->redirect(Yii::app()->createUrl("entries/index"));

2 create the corresponding logIn view:

views/test/logIn

Just copy the logIn view form the BUM module (from BUM/views/users/login.php); don’t forget to remove the line where the module is accessed:

remove this lines:




if ($this->module->install) {

    ?><DIV class="message note">Or go to the install page; click <?php echo CHtml::link('here',array('install/index')); ?>.</DIV><?php

}



because now you are no longer into a module

3 change the logIn URL in your wiews/layouts/main.php to point to the new URL:


array('label'=>'Login', 'url'=>array('/test/login'), 'visible'=>Yii::app()->user->isGuest),

4 in your protected/config/main.php file, under components, change the loginUrl:





'components'=>array(

        

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

            

            'class' => 'PRBTKWebUser',

            'loginUrl' => array('//test/login'), // required

		),

...



now the users should be redirected to entries/index after log in.