Thanks very much for the code Cricket, it helped tonnes! I know have Auth functioning correctly - I still feel its a bit of a dark art but if it works it works.
Anyway thanks again for your help. Felix On 19 July 2010 00:31, cricket <[email protected]> wrote: > On Sun, Jul 18, 2010 at 4:47 AM, Felix Fennell <[email protected]> > wrote: >> Ok, I just tried setting the loginRedirect and still nothing happens, >> as in I'm not redirected, again there were no errors shown and I don't >> know if the login was successful. > > Set debug to 2 so that you can at least see if Auth is correctly > querying the DB. Also, you can check the session to see if you've been > logged in. Add this to AppController::beforeFilter(): > > $this->Auth->autoRedirect = false; > > It's true by default. This tells Cake that you want to put further > logic in your login() method. > > public function login() > { > if (!empty($this->data)) > { > die(debug($this->Auth->user())); > } > } > > >> The only difference now that loginRedirect is set is after I click >> login and am sent back to the login page the password field I think >> contains the hashed password of the user account logging in. > > Yes, the hashed password is one of the more annoying, and confusing, > things about Cake for me. I still don't completely understand what is > the proper way to deal with that. All I know is that I don't have the > problem anymore. What did I do to fix it? Beats me. > > For one app where I'm using a non-standard model for "User" I have the > following in AppController: > > function beforeFilter() > { > $this->Auth->userModel = 'Member'; > $this->Auth->authorize = 'controller'; > $this->Auth->fields = array( > 'username' => 'email', > 'password' => 'password' > ); > $this->Auth->loginAction = array( > 'controller' => 'members', > 'action' => 'login' > ); > $this->Auth->loginRedirect = array( > 'controller' => 'pages', > 'action' => 'display', > 'home' > ); > $this->Auth->logoutRedirect = array( > 'controller' => 'pages', > 'action' => 'display', > 'home' > ); > $this->Auth->autoRedirect = false; > $this->Auth->loginError = 'No matching user found.'; > > if (!$this->Session->read('Member')) > { > $this->Auth->authError = 'Please log in'; > } > } > > Member::login() contains some further logic, which is why I have > autoRedirect set to false. > > public function login() > { > if (!empty($this->data) && $member = $this->Auth->user()) > { > $expiration = strtotime($member['Member']['expiration']); > > /* change redirect if admin > */ > if (isset($member['Member']['admin']) && > $member['Member']['admin']) > { > $this->redirect(array( > 'admin' => 1, > 'controller' => 'pages', > 'action' => 'display', > 'admin_index' > )); > } > else if ($expiration < strtotime('now')) > { > $this->Auth->logout(); > $this->flash( > 'Your membership has expired.', > array('action' => 'renew_expired'), > 'flash_expiration' > ); > } > else if ($expiration < strtotime('+14 days')) > { > $this->flash( > 'Your membership will expire '. date('l, F j, > Y', $expiration), > null, > 'flash_expiration' > ); > } > > $this->redirect($this->Auth->redirect()); > } > } > > Note that I have a custom flash() method in AppController. > > Anyway, the login view uses my custom fields for the form elements. > > <tr> > <th><?= $form->label('Member.email', 'Email') ?></th> > <td><?= $form->input('Member.email', array('label' => false)) ?></td> > </tr> > <tr> > <th><?= $form->label('Member.password', 'Password') ?></th> > <td><?= $form->input('Member.password', array('value' => '', 'label' > => false)) ?> > </tr> > > So, it's a slightly different setup than yours but maybe you can find > something in there that will point to what's going wrong with your > app. But, first, I'd ensure that Auth is actually querying the DB and > also that your credentials are correct. > > 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 [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 > 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 [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
