hi
*true 1.3*
class AppController extends Controller {
public function beforeFilter(){
if ($this->Auth->User()){
}else{
if($this->params['isAjax']){
$allowed = false;
foreach($this->Auth->allowedActions as $action){
if($action == $this->params['action']){
$allowed = true;
}
}
if(!$allowed){
$return['login'] = true;
echo json_encode($return);
}
}
}
}
}
class TestsController extends AppController{
public function beforeFilter() {
$this->Auth->allow('add'); // responseText: "{"login":"is allowed"}"
// $this->Auth->allow('add'); // responseText: "{"login":true}"
parent::beforeFilter();
}
public function add(){
if(!isset($return)){
$return['login'] = 'is allowed';
}
$this->set('return',$return);
$this->render('ajax_view','ajax');
}
}
Best regards!
2012/8/31 romel javier gomez herrera <[email protected]>
> hi, chris.
>
> *2.0*
> class AppController extends Controller {
> public function beforeFilter(){
> if ($this->Auth->User()){
> }else{
> if($this->request->isAjax()){
> $allowed = false;
> foreach($this->Auth->allowedActions as $action){
> if($action == $this->request->params['action']){
> $allowed = true;
> }
> }
> if(!$allowed){
> $return['login'] = true;
> echo json_encode($return);
> }
> }
> }
> }
>
> }
>
>
>
>
> class TestsController extends AppController{
>
> public function beforeFilter() {
> $this->Auth->allow('add'); // responseText: "{"login":"is allowed"}"
> // $this->Auth->allow('add'); // responseText: "{"login":true}"
> parent::beforeFilter();
> }
>
> public function add(){
> if(!isset($return)){
> $return['login'] = 'is allowed';
> }
> $this->set('return',$return);
> $this->render('ajax_view','ajax');
> }
>
> }
>
>
> *1.3*
>
> class AppController extends Controller {
> public function beforeFilter(){
> if ($this->Auth->User()){
> }else{
> if($this->request->isAjax()){
> $allowed = false;
> foreach($this->Auth->allowedActions as $action){
> if($action == $this->params['action']){
> $allowed = true;
> }
> }
> if(!$allowed){
> $return['login'] = true;
> echo json_encode($return);
> }
> }
> }
> }
>
> }
>
>
>
>
> class TestsController extends AppController{
>
> public function beforeFilter() {
> $this->Auth->allow('add'); // responseText: "{"login":"is allowed"}"
> // $this->Auth->allow('add'); // responseText: "{"login":true}"
> parent::beforeFilter();
> }
>
> public function add(){
> if(!isset($return)){
> $return['login'] = 'is allowed';
> }
> $this->set('return',$return);
> $this->render('ajax_view','ajax');
> }
>
> }
>
> Best regards!
>
> 2012/8/31 Chris Cinelli <[email protected]>
>
>> We have this is a problem, too. Last Romel's solution sounds pretty good.
>> I would like though that this can be the default behavior (ex: putting it
>> in AppController::beforeFilter). But I want that all the actions specified
>> by $this->Auth->allow(...) do not to emit the {"login":true}
>>
>> One option is to call $this->Auth->allow(...) before parent::beforeFilter()
>> in the derived controllers and having something (?) that tells if the
>> current action is in the allow list.
>> However an optional solution should be able to work even if
>> parent::beforeFilter() is called before Auth->allow.
>>
>> Should not this be a feature of the AuthComponent?
>>
>> Best,
>> Chris
>>
>>
>> On Fri, Aug 31, 2012 at 6:02 AM, romel javier gomez herrera <
>> [email protected]> wrote:
>>
>>> hi
>>>
>>> http://book.cakephp.org/1.3/en/view/967/isAjax
>>>
>>> <?php class AppController extends Controller {
>>>
>>> public function beforeFilter(){
>>> if ($this->Auth->User()){
>>> }else{
>>> if($this->params['isAjax']){
>>> // if the session expired
>>> $return['login'] = true;
>>> echo json_encode($return); // responseText: "{"login":true}"
>>> }
>>> }
>>> }
>>> } ?>
>>>
>>> Best regards!
>>>
>>>
>>> 2012/8/31 Florin Trifu <[email protected]>
>>>
>>>> Thank you!
>>>>
>>>> This is how I have tried in the first place but it is not working.
>>>> $this->RequestHandler->isAjax() is null or false, so it will never execute
>>>> the conditional code.
>>>>
>>>> Best regards!
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "CakePHP" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>>>>
>>>>
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "CakePHP" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>>>
>>>
>>>
>>
>>
>>
>> --
>> --Everything should be made as simple as possible, but not simpler
>> (Albert Einstein)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "CakePHP" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>>
>>
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.