everyone. I want to prevent user accessing login page after they have logged in. What is the best way to do that? Here's the code of config/main/php
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web',
'defaultController' => 'site/login')
And SiteContoller.php
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 previous page if valid
if($model->validate() && $model->login()){
$isAdmin = Yii::app()->user->getLevel() <=1; // or how you define admin in your case.
if ($isAdmin)
$this->redirect(array('user/view', 'id'=>Yii::app()->user->id));
else
//$id = Yii::app()->user->id;
$this->redirect(array('site/index'));
}
}
// display the login form
$this->render('login',array('model'=>$model));
}
In 'defaultController'=>'site/login'
I also want user not accessing login page after they close brower and reopen it. Is that possible? Thanks a lot