Text size +/-

23 Oct 07 _ Configuring the othAuth Component for Cake 1.2 pre-Beta


By casey
in CakePHP, Casey's Corner

After upgrading to the new CakePHP pre-beta that was released yesterday, I noticed that the excellent othAuth component 0.5.4.5, which we use here as part of our user Authentication process, was broken. Part of this was expected, as the new release of Cake has moved away from PHP defined constants, to the new Configure class. Essentially, the othAuth component was looking for the CAKE_ADMIN constant for admin routing, which no longer existed.

Here’s what I needed to do to make othAuth work again (I assume you’ve set up othAuth in the way described in the Bakery):

First, in your app_controller.php file, in the beforeFilter function, add this line above the rest of the othAuth initialization:


        $this->othAuthRestrictions[] = Configure::read('Routing.admin');

And remove any references to CAKE_ADMIN in the $othAuthRestrictions variable.

Then, in the oth_auth.php component, replace all references of:


     defined('CAKE_ADMIN')

to:


     Configure::read('Routing.admin')

and change all remaining occurrences of:


     CAKE_ADMIN

to:


     Configure::read('Routing.admin')

Most of these occur in if-then statements throughout the component.

The last thing I had to do was replace some model save actions. Specifically, if you’re using the standard othLogin, I needed to replace the following (line 328):


     $res = $UserModel->save($row,true,array($this->user_table_last_visit));

with two new lines:


     $UserModel->id = $row[$this->user_model]['id'];
     $res = $UserModel->saveField($this->user_table_last_visit,$row[$this->user_model][$this->user_table_last_visit],true);

Before, it was INSERT-ing a new entry with just the last visit information instead of updating the current user entry. When logging in a second time, I would receive a duplicate entry error from this. Switching from save to saveField helps guarantee that we’re UPDATE-ing the database, instead of INSERT-ing. I imagine you’d have to make a similar change if you use the naoLogin function.

After the above changes, everything worked once again.

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine


Comments are closed.