action call. As Auth do not know that field "password1" is also a
password it did not hashed. So you need to do it manually.
On Jan 4, 6:19 am, EwBoonTwo <gcull...@gmail.com> wrote:
> (Kind of) SOLUTION
>
> I've kept tinkering and noticed that the log in query was trying to
> use the unhashed password. So, I changed the register method from
> this:
> ...
> // log the user in to his new account
> $this->data['User']['password'] = $this->data['User']['password1'];
> ...
>
> to this:
> ...
> // log the user in to his new account
> $this->data['User']['password'] = $this->Auth->password($this->data
> ['User']['password1']);
> ...
>
> This did the trick. But, I'm surprised. I thought Auth was supposed to
> hash the password automagically. If I'm right about that, then I must
> be still doing something wrong and would love any insight.
>
> On Jan 3, 11:38 am, OohBunToo <gcull...@gmail.com> wrote:
>
>
>
> > Hey all,
>
> > I'm trying to set up a user registration system that uses the Auth
> > component. I've set up both the registration and login parts of my
> > site, and separately each work as expected (i.e. a user can register
> > and is saved to the database, and a user can log in separately once
> > registered). But, I can't get seem to get the Auth component to log in
> > users automatically once they've registered.
>
> > I've poured over Google searches, the cookbook, the API documentation,
> > but nothing seems to get me around my issue.
>
> > Here's the beforeFilter in my app_controller:
> > function beforeFilter() {
> > // Override the default fields used by Auth component
> > $this->Auth->fields = array(
> > 'username'=>'email',
> > 'password'=>'password'
> > );
>
> > Here are the beforeFilter and register methods in my users_controller:
> > function beforeFilter() {
> > parent::beforeFilter();
> > $this->Auth->allow(array('register', 'login', 'logout'));
>
> > }
>
> > function register() {
> > if($this->Session->read('User.signedIn')) {
> > $this->redirect(array('action'=>'account'));
> > }
>
> > if (!empty($this->data)) {
> > $this->User->create();
> > if ($this->User->save($this->data)) {
> > // log the user in to his new account
> > $this->data['User']['password'] = $this->data['User']
> > ['password1'];
> > $this->Session->setFlash(__('Hooray! The User has been
> > saved', true));
> > $this->Auth->login($this->data);
> > $this->redirect($this->Auth->redirect());
> > } else {
> > $this->Session->setFlash(__('Uh oh! That didn\'t work.
> > Please, try again.', true));
> > }
> > }
>
> > }
>
> > The redirect takes place, but the user isn't actually getting logged-
> > in. Instead, they're dropped onto the login form with the
> > "Hooray! ..." flash message as well as the "You are not authorized..."
> > Auth flash message. So, it's clear that the $this->Auth->login($this-
>
> > >data) line isn't doing what's expected.
>
> > I've confirmed that the $this->data array contains the right keys and
> > values using debug:
> > app/controllers/users_controller.php (line 31)
>
> > Array
> > (
> > [User] => Array
> > (
> > [email] => asdfi...@grr.com
> > [password1] => aaa
> > [password2] => aaa
> > [password] => aaa
> > )
> > )
>
> > So, I'm out of ideas. I really want to use the Auth component, but the
> > learning curve is giving me headaches. Any help will be hugely
> > appreciated!
No comments:
Post a Comment