Re: login voodoo
Please don't apologise! It's all good. I just wanted to set the record straight for anyone who might come across the thread.Thanks again, this was driving me nuts. 2009/4/9 Jorge Horacio Cué Cantú : > Your wellcome, sorry for the small mistake. > > > 2009/4/9 brian >> >> 2009/4/9 Jorge Horacio Cué Cantú : >> > Hello, >> > >> > >> > Set >> > >> > $this->Auth->redirect = false >> > >> > in AppController::beforeFilter(). >> > >> > The the login() action will be called after a successful login. >> > >> >> Thanks, that's it (sort of). The var is actually >> $this->Auth->autoRedirect. >> >> So, for the record: >> >> 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->autoRedirect = false; >> $this->Auth->logoutRedirect = array('controller' => 'users', >> 'action' >> => 'login'); >> >> if (isset($this->params['admin']) && $this->params['admin']) >> { >> $this->layout = 'admin'; >> } >> } >> >> >> UsersController: >> public function login() >> { >> if ($user = $this->Auth->user()) >> { >> $this->User->id = $user['User']['id']; >> $this->User->saveField('last_login', date('Y-m-d H:i:s')); >> >> if (!$user['User']['eula_accepted']) >> { >> $this->redirect( >> array('controller' => 'users', 'action' => >> 'eula') >> ); >> } >> $this->redirect($this->Auth->loginRedirect); >> } >> } >> >> public function eula() >> { >> if (!empty($this->data) && $this->data['User']['eula_accepted']) >> { >> $this->User->id = $this->Auth->user('id'); >> $this->User->saveField('eula_accepted', 1); >> $this->Session->write('Auth.User.eula_accepted', 1); >> >> $this->redirect( >> array('controller' => 'pages', 'action' => >> 'display', 'home') >> ); >> } >> } >> >> Thanks again, Jorge! >> >> > > > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: login voodoo
Your wellcome, sorry for the small mistake. 2009/4/9 brian > > 2009/4/9 Jorge Horacio Cué Cantú : > > Hello, > > > > > > Set > > > > $this->Auth->redirect = false > > > > in AppController::beforeFilter(). > > > > The the login() action will be called after a successful login. > > > > Thanks, that's it (sort of). The var is actually $this->Auth->autoRedirect. > > So, for the record: > > 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->autoRedirect = false; > $this->Auth->logoutRedirect = array('controller' => 'users', > 'action' > => 'login'); > > if (isset($this->params['admin']) && $this->params['admin']) >{ >$this->layout = 'admin'; >} > } > > > UsersController: > public function login() > { >if ($user = $this->Auth->user()) >{ >$this->User->id = $user['User']['id']; >$this->User->saveField('last_login', date('Y-m-d H:i:s')); > >if (!$user['User']['eula_accepted']) >{ >$this->redirect( > array('controller' => 'users', 'action' => > 'eula') >); >} > $this->redirect($this->Auth->loginRedirect); >} > } > > public function eula() > { >if (!empty($this->data) && $this->data['User']['eula_accepted']) >{ >$this->User->id = $this->Auth->user('id'); >$this->User->saveField('eula_accepted', 1); >$this->Session->write('Auth.User.eula_accepted', 1); > >$this->redirect( > array('controller' => 'pages', 'action' => > 'display', 'home') > ); >} > } > > Thanks again, Jorge! > > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: login voodoo
2009/4/9 Jorge Horacio Cué Cantú : > Hello, > > > Set > > $this->Auth->redirect = false > > in AppController::beforeFilter(). > > The the login() action will be called after a successful login. > Thanks, that's it (sort of). The var is actually $this->Auth->autoRedirect. So, for the record: 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->autoRedirect = false; $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login'); if (isset($this->params['admin']) && $this->params['admin']) { $this->layout = 'admin'; } } UsersController: public function login() { if ($user = $this->Auth->user()) { $this->User->id = $user['User']['id']; $this->User->saveField('last_login', date('Y-m-d H:i:s')); if (!$user['User']['eula_accepted']) { $this->redirect( array('controller' => 'users', 'action' => 'eula') ); } $this->redirect($this->Auth->loginRedirect); } } public function eula() { if (!empty($this->data) && $this->data['User']['eula_accepted']) { $this->User->id = $this->Auth->user('id'); $this->User->saveField('eula_accepted', 1); $this->Session->write('Auth.User.eula_accepted', 1); $this->redirect( array('controller' => 'pages', 'action' => 'display', 'home') ); } } Thanks again, Jorge! --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: login voodoo
Hello, Set $this->Auth->redirect = false in AppController::beforeFilter(). The the login() action will be called after a successful login. Regards. 2009/4/9 brian > > Actually, yes, I did consider that and I think I will do it that way. > But that still leaves with this problem: how to check this field after > a successful login? > > On Thu, Apr 9, 2009 at 11:48 AM, Angry Coder wrote: > > > > Have you considered a separate column in your users table of > > "accepted_eula" or "eula_version_accepted" if you want to track which > > version of the EULA they have accepted? > > > > It would be easy then to force users to re-accept if it changes and > > you do not have to lose the "last_login" data if you wish to force a > > re-acceptance. > > > > Just thinking out loud here... > > > > > > > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: login voodoo
Actually, yes, I did consider that and I think I will do it that way. But that still leaves with this problem: how to check this field after a successful login? On Thu, Apr 9, 2009 at 11:48 AM, Angry Coder wrote: > > Have you considered a separate column in your users table of > "accepted_eula" or "eula_version_accepted" if you want to track which > version of the EULA they have accepted? > > It would be easy then to force users to re-accept if it changes and > you do not have to lose the "last_login" data if you wish to force a > re-acceptance. > > Just thinking out loud here... > > > --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: login voodoo
Have you considered a separate column in your users table of "accepted_eula" or "eula_version_accepted" if you want to track which version of the EULA they have accepted? It would be easy then to force users to re-accept if it changes and you do not have to lose the "last_login" data if you wish to force a re-acceptance. Just thinking out loud here... --~--~-~--~~~---~--~~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: login voodoo
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 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 cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---