Unable to logout of Yii app & force page to redirect (Yii 1.x)

691 views Asked by At

I'm trying to get my Yii app to auto logout after a set number of seconds when a particular type of user is logged in.

I have made the following amends to my protected/components/WebUser.php file:

public function init() {
    parent::init();

    if (($user = $this->getState('userModel')) !== null) {
        $this->setUserData(unserialize($user));

        if ($this->isNonAdminUser()) {
            $this->authTimeout = 3600; // 1 hour timeout
        }
    }

    $this->updateAuthStatus();
}

// function automatically directly after $this->logout()
protected function afterLogout() {
    Yii::app()->request->redirect(('site/front/login'));

    //Yii::app()->request->redirect((Yii::app()->user->returnUrl));
}

This will basically logout a 'non admin user' out of the session after 1 hour of no activity - this works however I'd like to be able to 'force' them back to the homepage as well. I've tried to use the redirect function in the afterLogout() but it doesn't seem to do a redirect for some reason?

Any ideas why not?

Note - I am using Yii 1.x

1

There are 1 answers

0
hamed On

Try to use Yii::app()->user->homeUrl instead of Yii::app()->user->returnUrl inside afterLogout function.