You need this in all your controllers...
<code>
function beforeFilter()
{
//actions we allow without authentication, you can also put them
in the app_controller.php
$this->Auth->allow('index');
}
</code>
Add all the actions in your controller you want people to have access
to without authentication.
http://book.cakephp.org/view/247/AuthComponent-Methods
for more info
Russ
On Apr 30, 5:01 am, DatacenterHellas <[email protected]> wrote:
> Hello all ! ! !
>
> I'm new to CakePHP and I already have create a login system based on
> Auth Component. All are fine with that component, but the problem that
> I have is that if the user logou the system then he can't see any
> page. The Auth redirects automatic to login form. What can I do, for
> desplay pages that are not require login ? ? ?
>
> ie : index, about, contact us must be public pages. Do not require
> login.
> add new article, edit articles, manage users must be private.
>
> How to select witch page must be private and witch must be public.
>
> My Code :
>
> AppController :
>
> class AppController extends Controller
> {
> var $name = "App";
> var $helpers = array('javascript','html','form');
> var $components = array('Auth','newArticle');
>
> function beforeRender()
> {
> $this->set('articles', $this->newArticle->getLatest());
> }
>
> }
>
> class UsersController extends AppController
> {
> var $name = "Users";
>
> function beforeFilter()
> {
> $this->Auth->allow('register', 'login', 'logout');
> }
>
> function register()
> {
> if(!empty($this->data))
> {
> $this->data['User']['password_confirm'] =
> $this->Auth->password
> ($this->data['User']['password_confirm']);
> $this->User->create();
> if($this->User->save($this->data))
> {
>
> $this->redirect(array('controller'=>'Pages','action'=>'index'));
> }
> }
> }
>
> function login()
> {
> if(!empty($this->data))
> {
> $usr = $this->Auth->login($this->data);
> if(!empty($usr))
> {
> $this->set('data',$this->Auth->user());
>
> $this->redirect(array('controller'=>'Pages','action'=>'index'));
> }
> else
> {
> $this->Session->setFlash("Η είσοδος απέτιχε");
>
> $this->redirect(array('controller'=>'Users','action'=>'login'));
> }
> }
> }
>
> function logout()
> {
> $this->Auth->logout();
>
> $this->redirect(array('controller'=>'Pages','action'=>'index'));
> }
>
> }
>
> class ArticlesController extends AppController
> {
> var $name = "Articles";
> var $paginate = array(
> 'limit' => 5,
> 'order' => array(
> 'Article.id' => 'DESC'
> )
> );
>
> function add()
> {
> if(!empty($this->data))
> {
> $this->Article->create();
>
> if($this->Article->save($this->data))
> {
>
> $this->redirect(array('controller'=>'Pages','action'=>'index'));
> }
> else
> {
> $this->Session->setFlash('Σφάλμα κατά την
> αποθήκευση');
> }
> }
> }
>
> function view()
> {
> $artcl = $this->Article->find('first',
> array('conditions'=>array
> ('Article.id'=>$this->params['named']['artid'])));
> $this->set('article', $artcl['Article']);
> }
>
> function showAll()
> {
> $artcl = $this->paginate('Article');
> $this->set('data', $artcl);
> }
>
> }
>
> class ProfilesController extends AppController
> {
> var $name = "Profiles";
>
> function view()
> {
> $pfl = $this->Profile->find('first', array('conditions'=>array
> ('User.id'=>$this->Session->read('Auth.User.id'))));
> $this->set('data', $pfl);
> }
>
> function edit()
> {
> if(!empty($this->data))
> {
> if($this->Profile->save($this->data))
> {
>
> $this->redirect(array('controller'=>'Profiles','action'=>'view'));
> }
> else
> {
> $this->Session->setFlash('Error');
> }
> }
> else
> {
> $pfl = $this->Profile->find('first',
> array('conditions'=>array
> ('User.id'=>$this->Session->read('Auth.User.id'))));
> $this->set('data', $pfl);
> }
> }
>
> function add()
> {
> if(!empty($this->data))
> {
> if($this->Profile->save($this->data))
> {
>
> $this->redirect(array('controller'=>'Profiles','action'=>'view'));
> }
> else
> {
> $this->Session->setFlash('Error');
> }
> }
> else
> {
> $pfl = $this->Profile->User->find('all',
> array('conditions'=>array
> ('User.id'=>$this->Session->read('Auth.User.id'))));
> $this->set('data', $pfl);
> }
> }
>
> }
>
> class PagesController extends AppController {
>
> var $name = 'Pages';
> var $uses = null;
>
> function index()
> {
> }
>
> }
>
> class ArticlesController extends AppController
> {
> var $name = "Articles";
> var $paginate = array(
> 'limit' => 5,
> 'order' => array(
> 'Article.id' => 'DESC'
> )
> );
>
> function add()
> {
> if(!empty($this->data))
> {
> $this->Article->create();
>
> if($this->Article->save($this->data))
> {
>
> $this->redirect(array('controller'=>'Pages','action'=>'index'));
> }
> else
> {
> $this->Session->setFlash('Σφάλμα κατά την
> αποθήκευση');
> }
> }
> }
>
> function view()
> {
> $artcl = $this->Article->find('first',
> array('conditions'=>array
> ('Article.id'=>$this->params['named']['artid'])));
> $this->set('article', $artcl['Article']);
> }
>
> function showAll()
> {
> $artcl = $this->paginate('Article');
> $this->set('data', $artcl);
> }
>
> }
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---