Friday, October 3, 2008

Re: Auth component and ajax forms

Did you check this var at the auth component?

/**
* The name of an optional view element to render when an Ajax request
is made
* with an invalid or expired session
*
* @var string
* @access public
*/
var $ajaxLogin = null;

Never tried it, but i guess is something meant to do what you need.

HTH,

CG

On Oct 2, 4:17 pm, RobertoSDN <roberto....@gmail.com> wrote:
> Hello, i am using ajax forms and i have a problem with the Auth
> component that works fine with the login action but not with others
> actions because only the login action has the bahavior to render a
> element to handle errors like bellow:
>
> if ($loginAction == $url) {
>    ...code} else {
>
>    if (!$this->user()) {
>         if (!$this->RequestHandler->isAjax()) {
>                 $this->Session->setFlash($this->authError, 'default', array(),
> 'auth');
>                 $this->Session->write('Auth.redirect', $url);
>                 $controller->redirect($loginAction);
>                 return false;
>         } elseif (!empty($this->ajaxLogin)) {
>                 $controller->viewPath = 'elements';
>                 echo $controller->render($this->ajaxLogin,   $this->RequestHandler->ajaxLayout);
>
>                 $this->_stop();
>                 return false;
>         } else {
>                 $controller->redirect(null, 403);
>         }
>    }
>
> }
>
> The problem is, when i make a request to an action that the function
> isAuthorized() returns false, the component redirect the render to a
> referer page that its layout is not a ajax layout and the view is the
> view's referer, would be a bad thing to replace the actual Auth code
> to this bellow?
>
> After this
> if ($this->isAuthorized($type)) {
>         return true;
>
> }
>
> put this
>
> if (!$this->RequestHandler->isAjax()) {
>         $this->Session->setFlash($this->authError, 'default', array(),
> 'auth');
>         $controller->redirect($controller->referer(), null, true);}else{
>
>         $controller->viewPath = 'elements';
>         echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
>
>         $this->_stop();
>         return false;
>
> }
>
> thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: