Login and Logout problem front end and back end separately

Hi all,

I’m creating my first Yii application. I have another problem in my hands. I have a developed the site to have back end and a front end. backed (CMS) is inside the protected/modules/CMS folder. All are working fine and the only problem I’m having is the login and the log out.

  1. I have used the Gii to generate my scrips and then customized it.

  2. I have a separate “Adminusers” database table and I’m logging in my users according to that (this is working fine)

  3. The only problem is I was looking to separate the “login” of the CMS from the front end site but it is still takings the front end’s “siteController” login and log out functions.

  4. I also successfully created a separate "LoginController" for the backed and even though it works after login it redirects to the front end.

below is the code of that "LoginController"




class LoginController extends Controller

{

	public function actionIndex()

	{

		$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 previous page if valid

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

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

		}

		// display the login form

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

	}

	public function actionLogout()

	{

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

		$this->redirect('admincms/login/index');

	}

}



I understand the redirection is done by




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

$this->redirect('admincms/login/index')



but when I use




$this->redirect('admincms/pages/index') it goes to domain/admincms/admincms/pages/index (double admin CMS is not a mistake)



when I use




$this->redirect('pages/index') it goes to domain/pages/index (which is the front end)



I want it to be redirected to domain/admincms/pages/index after login.

And also appreciate if you could direct me to a proper documentation about "redirection"

Please let me know if there is any other better way to separate the backed (CMS) login from the front end completely.

Thank you in advance

$this->redirect(‘admincms/pages/index’); builds the URL relatively to the place it is called.

What you need is :

$this->redirect(Yii::app()->createUrl(‘admincms/pages/index’))

OR

$this->redirect(’/admincms/pages/index’);

Beside this, i believe having two user tables matching two different login areas is too much for a website.

You could use the RBAC mechanism Yii provides and set permissions for each action is executed.

Hi twisted,

This was really helpful. Now my application is working perfectly.

Thanks a lot