Monday, December 28, 2009

Re: Cache MADNESS with Auth

HI CHAD,

YOU ARE THE GOD!!

So simple....

Thank you very much, yuor code excerpt is interesting!!

Dario

On 28 Dic, 14:37, Chad Smith <chadsmith...@gmail.com> wrote:
> Hello Dario,
>
> If the field is a tinyint (which most likely it is) then in Cake's
> mind 1 = true, 0 = false.  You changing it to 2 will confuse Cake and
> make it not know what to think.  You will need to change that field to
> int and then change the values to 2 if they are confirmed.
>
> When I was developinghttp://www.countycriminal.comhere's what I am
> using for the authentication of users:
>
> app/app_controller.php
> function beforeRender() {
>                 if(isset($this->params['admin']) && $this->params['admin'] ==
> 'admin'){
>                         if(!$this->checkUser($this->Session->read('admin_user'))){
>                                 $this->redirect('/administrators/login/');
>                         }else{
>                                 $this->layout = 'admin';
>                                 $this->set('IS_ADMIN',true);
>                         }
>                 }
>         }
>
>         function checkUser($user) {
>                 if((!is_array($user)) || (!isset($user['Administrator']['id']))){
>                         return false;
>                 } else {
>                         return true;
>                 }
>         }
>
> app/controllers/administrators_controller.php
> function login() {
>                 $this->layout = "admin";
>
>                 if(!empty($this->data)) {
>                         $user_login = $this->Administrator->find('first', array
> ('conditions' => array('username' => $this->data['administrators']
> ['username'], 'password' => $this->data['administrators']
> ['password'])));
>                         if(!empty($user_login)){
>                                 // Writes the session for the admin
>                                 $this->Session->write('admin_user', $user_login);
>                                 $last = $user_login['Administrator']['lastlogin'];
>                                 $user_login['Administrator']['lastlogin'] = date('Y-m-d H:i:s');
>                                 $this->Administrator->save($user_login);
>                                 $this->Session->setFlash(__('You have been login successfully.
> Last Login: '.date('l, F jS Y \a\t g:ia',strtotime($last)), true),
> 'default', array('class'=>'success'));
>                                 $this->redirect('/admin/');
>                         } else {
>                                 $this->Session->setFlash(__('The login was invalid, please try
> again.', true), 'default', array('class'=>'error'));
>                         }
>                 }
>         }
>
> As you can see the before render will check to see if it's an "admin"
> area and if so it checks to make sure the user is logged in.  If they
> are not it will send them to the administrators/login page which will
> then check their login.  If it's successful it will set the session
> and continue on.  If however, it's not successful it will send them
> back with a message that it failed to log them in.
>
> Take care hope this points you in the right direction,
> Chad
>
> On Dec 28, 8:10 am, "lacenaepro...@gmail.com"
>
>
>
> <lacenaepro...@gmail.com> wrote:
> > Hi,
>
> > I have this userscope Auth configuration in the AppController:
>
> > $this->Auth->userScope = array('User.confirmed' => '1');
>
> > Today I decided to change the value from 1 to 2. I changed the line
> > above and ALL THE RECORDS IN THE user table.
>
> > The Auth components now DOES NOT LOGIN the users. I cleared the cache
> > but nothing happens!!
>
> > I hate this cakephp behaviour. Every time I work with the Auth/Acl,
> > some sort of caching mechanism is causing problems.
>
> > Do you have any idea?
>
> > Thanks!!
>
> > Dario- Nascondi testo citato
>
> - Mostra testo citato -

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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: