OK, it looks like one can't override login() with AuthComponent in
place. I was sure I could, and it doesn't make sense to me that I
can't. If someone knows otherwise, please advise.
So, I tried putting my code in isAuthorized().
AppController:
function beforeFilter()
{
$this->Auth->fields = array('username' => 'email', 'password' =>
'password');
$this->Auth->loginError = 'No matching user found.';
$this->Auth->loginAction = array('controller' => 'users', 'action' =>
'login');
$this->Auth->loginRedirect = array('controller' => 'pages', 'action'
=> 'display', 'home');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action'
=> 'login');
$this->Auth->authorize = 'controller';
if (isset($this->params['admin']) && $this->params['admin'])
{
$this->layout = 'admin';
}
}
UsersController:
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allowedActions = array('eula', 'register',
'reset_password');
}
public function login() {}
function isAuthorized()
{
$user = $this->Auth->user();
Debugger::log($user);
if (empty($user['User']['last_login']))
{
Debugger::log('redirecting ...');
$this->Auth->redirect(
array(
'controller' => 'users',
'action' => 'eula'
)
);
}
else
{
/* save the login time
*/
$user['User']['last_login'] = date('Y-m-d H:i:s');
$this->User->save($user);
$this->Session->write('Auth.User', $user['User']);
}
return true;
}
Now, I can't log in at all! I tried putting return true; just inside
isAuthorized() and still Auth is emitting AuthError. That makes no
sense at all.
On Thu, Apr 9, 2009 at 10:49 AM, brian <[email protected]> wrote:
> I need to direct first-time users to an EULA page for a client's
> extranet. I thought I'd check the last_login field in order to decide
> whether to redirect there or not. However, for some reason, I'm being
> logged in but none of my custom code is running.
>
> function beforeFilter()
> {
> parent::beforeFilter();
> $this->Auth->allowedActions = array('eula', 'register',
> 'reset_password');
> }
>
>
> public function login()
> {
> if (!empty($this->data))
> {
> if ($this->Auth->login($this->data))
> {
> $user = $this->Auth->user();
>
> if (empty($user['User']['last_login']))
> {
> $this->Auth->redirect(
> array(
> 'controller' => 'users',
> 'action' => 'eula'
> )
> );
> }
> else
> {
> /* save the login time
> */
> $user['User']['last_login'] = date('Y-m-d
> H:i:s');
> $this->User->save($user);
>
> $this->Session->write('Auth.User',
> $user['User']);
> }
> }
> else
> {
> $this->Session->setFlash($this->Auth->authError);
> }
> }
> }
>
>
> At first, I thought that the redirect() call was bad or something.
> But, if I toss in a die(debug('logged in')); right after the login()
> call, that doesn't run, either.
>
> So, how am I being logged in? I wondered if Cake's magic was getting
> in the way so I did this:
>
> public function login()
> {
> if (!empty($this->data))
> {
> die(debug('got data'));
>
> // ...
>
> This never fires, either. So, I then did this:
>
>
>
> public function login()
> {
> die(debug('wtf'));
>
> Guess what? This fires.
>
> Anyone got a tip for me?
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---