Cakephp Auth Does Not Allow Timthumb to Work

Asked

Viewed 69 times

0

I have a gallery that worked properly, but after doing user restrictions with the Auth, thumbnails stopped showing the image, but when I delete function beforFilter(), public function isAuthorized($user) and the component Auth of AppController, works. How to fix this?

I’m using Cakephp 2.4.4 ,Timthumb 2 and fancybox 2.

Appcontroller

class AppController extends Controller {
public $components = array('DebugKit.Toolbar',
                            'Session','Auth' => array(
                                                'loginRedirect' => array('controller' => 'admins', 'action' => 'admin_index'),
                                                'logoutRedirect' => array('controller' => 'home', 'action' => 'index'),
                                                'authorize' => array('Controller')
                                                )
                        );

public function isAuthorized($user){
    if(isset($user['role']) && $user['role']==='admin'){
        return true; //admin pode acedeer a  todas as actions
    }
    return false; // os outros utilizadores não podem
}
function beforeFilter(){
    $this->Auth->allow('index','ShowImages','ShowShowbill','ShowVideos','login');

}
public $helpers = array('Html' ,
                        'Form' ,
                        'Timthumb.Timthumb',
                        'Paginator', 
                        'Session',
                        'Js',
                        'Fancybox.Fancybox');   


}

Galleriescontroller

    public function ShowImages(){
        $this->layout = 'default';
        $this->loadModel('GalleryImage');
        $gallery_images = $this->GalleryImage->find('all');
        $this->set('gallery_images', $gallery_images);
    //$image_display = $gallery_image['path']
    }

View

<h2>Galeria</h2>
<br>
<table width="100%">
<tr>
    <?php
        $i=0;
        foreach( $gallery_images as $gallery_image ):?>
    <td align="center" class="thumbnail" style="display:inline-block;">
    <?php
        $src3 =$this->webroot. 'img/gallery/' .$gallery_image['GalleryImage']['path'];
        //$src3 = 'img/gallery/' .$gallery_image['GalleryImage']['path'];
        $this->Fancybox->setProperties( array( 
            'class' => 'fancybox3',
            'className' => 'fancybox.image',
            'title'=>'Single Image',
            'rel' => 'gallery1'
            )
        );
        $this->Fancybox->setPreviewContent($this->Timthumb->image('/img/gallery/' . $gallery_image['GalleryImage']['path'] , array('width' => 267, 'height' => 189)));

        $this->Fancybox->setMainContent($src3);
        echo $this->Fancybox->output();
    ?>
    </td>
    <?php $i++;
        if($i==4){
            echo "</tr><tr>";
            $i=0;   
        }
    ?>
<?php endforeach ?>
</tr>

1 answer

0


The problem was caused by the Timthubmb plugin from Cakephp, having already been corrected. Also the files had some modifications however, being the allow('image') in the AppController, and the inclusion of the most relevant scripts in this case.

Appcontroller

class AppController extends Controller {
public $components = array('DebugKit.Toolbar',
                            'Session','Auth' => array(
                                                'loginRedirect' => array('controller' => 'admins', 'action' => 'admin_index'),
                                                'logoutRedirect' => array('controller' => 'home', 'action' => 'index'),
                                                'authorize' => array('Controller')
                                                )
                        );

public function isAuthorized($user){
    if(isset($user['role']) && $user['role']==='admin'){
        return true; //admin pode acedeer a  todas as actions
    }
    return false; // os outros utilizadores não podem
}
function beforeFilter(){
    $this->Auth->allow('index','ShowImages','ShowShowbill','ShowVideos','login','ShowContactUs','timthumb');
    $this->Auth->allow('image');
}
public $helpers = array('Html' ,
                        'Form' ,
                        'Timthumb.Timthumb',
                        'Paginator', 
                        'Session',
                        'Js',
                        'Fancybox.Fancybox');   


}

View

<h2>Galeria</h2>
<br>
<table width="100%">
<tr>
    <?php
        $i=0;
        foreach( $gallery_images as $gallery_image ):?>
    <td align="center" class="thumbnail" style="display:inline-block;">
    <?php
        $src3 =$this->webroot. 'img/gallery/' .$gallery_image['GalleryImage']['path'];
        //$src3 = 'img/gallery/' .$gallery_image['GalleryImage']['path'];
        $this->Fancybox->setProperties( array( 
            'class' => 'fancybox3',
            'className' => 'fancybox.image',
            'title'=>'Single Image',
            'rel' => 'gallery1'
            )
        );
        $this->Fancybox->setPreviewContent($this->Timthumb->image('/img/gallery/' . $gallery_image['GalleryImage']['path'] , array('width' => 267, 'height' => 189)));

        $this->Fancybox->setMainContent($src3);
        echo $this->Fancybox->output();
    ?>
    </td>
    <?php $i++;
        if($i==4){
            echo "</tr><tr>";
            $i=0;   
        }
    ?>
<?php endforeach ?>
</tr>

</table>

Galleriescontroller

    public function ShowImages(){
        $this->layout = 'default';
        $this->loadModel('GalleryImage');
        $gallery_images = $this->GalleryImage->find('all');
        $this->set('gallery_images', $gallery_images);

    //$image_display = $gallery_image['path']
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.