Yii Framework Forum: requireLogin and Ajax issues - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

requireLogin and Ajax issues Reguire Login not recognizing ajax request status Rate Topic: -----

#1 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 14 April 2010 - 12:57 PM

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.
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 14 April 2010 - 01:24 PM

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).
1

#3 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 14 April 2010 - 01:26 PM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users