requireLogin and Ajax issues

My problem is that i’m trying to get the site to refresh the window to the login URL instead of drawing the login URL into the ajax update div when session expires while the user has a page loaded (ie., you leave the page up overnight or some such).

I thought this should work, but it goes through the CHttpRequest::redirect() which causes a header Location change and it loses the ajax status on the request in that process (at least that’s as close as I can figure what’s happening).

This is the change I made:


public funciton actionLogin()

{

    $model = new LoginForm;

    if (isset($_POST['ajax'] && $_POST['ajax'] ==='login-form')

    {

      // ... standard stuff here

    } 

   

    if ( $request = Yii::app()->getRequest() && $request->isAjaxRequest)

    {

       // ensure we're rendering this in a parent window, not an update div

       $this->renderPartial('loginRedirect', array(), false, true);

       Yii::app()->end();

    }

    ... //original code continues

}



Then the new views/site/ folder - loginRedirect.php


<script>

  window.location = '<?php echo $this->createAbsoluteUrl('site/login')?>';

</script> 

However, it’s rendering the full render(‘login’) NOT the partial page, within the div.

I can’t use the beforeAction method of the controller unless I change the access controller completely for every controller that may use ajax updates. This definitely does not appeal to me as a solution.

I don’t really want to have to extend CWebUser either if I don’t have to – so I’m wondering if there’s an elegant solution to this issue that I’m overlooking?

Any insight would be greatly appreciated.

I think CWebUser::loginRequired() is best place for this. I know you said you don’t want to do this if possible, but I see no better solution (though I’m not much into that ajax stuff).

I’ll go ahead and do that then. Thanks for the quick reply!!