Hi there, trying to learn cakephp and loving it for the most part. But
just when I thought I'd finally figured out the acl and auth
components things started to get a bit weird.

A couple of nights ago I finally got everything working only to
discover that after an hour or two I had managed to break it somehow
and I was being denied permission to go to a certain action which I
should have been allowed to access (every other action that I expected
to be allowed seemed to work fine). So I went over everything I had
changed but couldn't spot the culprit, in fact I was pretty sure that
any changes I had made since it last worked had been changed back. So
after a couple of hours head scratching it all of a sudden seemed to
work again without me changing anything (at least thats how it
seemed).

Anyway, now it's not working again and I really don't think I have
touched anything since it was working. Although I have noticed that I
don't think it is clearing the session etc when I logout as it should
- could that be something to do with it?

I guess it's probably something I'm doing, cakephp seems to work fine
for everyone else. But I can't for the life of me figure it out. Is
there something I'm not aware of that could be causing this problem?

here's my beforefilter in my app_controller
    function beforeFilter() {
        //Configure AuthComponent
        $this->Auth->authorize = 'actions';
                $this->Auth->fields =
array('username'=>'email','password'=>'password');
                $this->Auth->actionPath = 'controllers/';
        $this->Auth->loginAction = array('controller' => 'users',
'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'pages',
'action' => 'home');
        $this->Auth->loginRedirect = array('controller' =>
'campaigns', 'action' => 'regcampaign');
                $this->Auth->loginError = 'Invalid e-mail / password 
combination.
Please try again';
                $this->Auth->allow(array('display'));
                $this->set('loggedIn', $this->Auth->user('id'));
    }

and here's my register function in my users_controller which is meant
to redirect a user to the regcampaign action in my
campaigns_controller
        function register() {
                if ($this->Session->read('Auth.User')) {
                        $this->redirect(array('controller' => 'campaigns', 
'action' =>
'regcampaign'));
                } else {
                        if(!empty($this->data)) {
                                if(isset($this->data['User']['password2'])) {
                                        $this->data['User']['password2hashed'] 
= $this->Auth-
>password($this->data['User']['password2']);
                                }
                                if($this->User->save($this->data)) {
                                        $this->Session->setFlash('Your 
registration was successful');
                                        $firstlast = 
$this->data['User']['first_name'] . '_' . $this-
>data['User']['last_name'];
                                        $this->Session->write('user.email', 
$this->data['User']
['email']);
                                        $this->Session->write('user.name', 
$firstlast);
                                        $parent = 
$this->Acl->Aro->findByAlias('Users');
                                        $aro = new Aro();
                                        $aro->create();
                                        $aro->save(array('alias' => 
$this->data['User']['email'], 'model'
=> 'User', 'foreign_key' => $this->User->id, 'parent_id' =>
$parent['Aro']['id']));
                                        $this->Acl->Aro->save();
                                        //get the current users data and log 
him in
                                        $data = $this->User->read();
                                        $this->Auth->login($data);
                                        $this->redirect(array('controller' => 
'campaigns', 'action' =>
'regcampaign'));
                                } else {
                                        $this->data['User']['password'] = '';
                                        //$this->data['User']['password2'] = '';
                                        $this->Session->setFlash(__('The user 
could not be saved. Please,
try again.', true));
                                }
                        }
                }
        }

here's the regcampaign function which is the action which I'm being
denied permission to
        function regcampaign() {
                $alias = 'regcampaign';
                if ($this->Acl->check($this->Session->read('user.email'), 
$alias,
'create')) {
                        if (!empty($this->data)) {
                                $this->Campaign->create();
                                if ($this->Campaign->save($this->data)) {
                                        //$user = 
$this->Session->read('user.email');
                                        $name = 
$this->Session->read('user.name');
                                        $parent = 
$this->Acl->Aco->findByAlias('Campaigns');
                                        $alias = $name . '_' . 
$this->Campaign->id;
                                        $aco = new Aco();
                                        $aco->create();
                                        $aco->save(array('alias' => $alias, 
'model' => 'Campaign',
'foreign_key' => $this->Campaign->id, 'parent_id' => $parent['Aco']
['id']));
                                        $this->Acl->allow('users', $alias, 
'read');
                                        
$this->Acl->allow($this->Session->read('user.email'), $alias);
                                        //$this->Session->setFlash(__('The 
campaign has been saved',
true));
                                        $this->redirect(array('action' => 
'index'));
                                } else {
                                        $this->Session->setFlash(__('The 
campaign could not be saved.
Please, try again.', true));
                                }
                        }
                } else {
                        $this->Session->setFlash(__('You don\'t have permission 
to register
a new campaign'));
                        $this->redirect(array('action'=>'index'));
                }
                $users = $this->Campaign->User->find('list');
                $charities = $this->Campaign->Charity->find('list');
                $this->set(compact('users', 'charities'));
        }

Like I said before this was all working at one point.

Any help at all would be most appreciated, I've been fiddling with
this for a couple of days and it's really doing my nut in

thanks

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to