Sunday, November 30, 2008

Re: How to validate and update password of a user with affecting HABTM relations for the user?

I tried $this->Model->validate() in the controller, but for some
reason, 'password' and 'password_confirm' are not being passed to the
Model (I tried logging them in the "beforeValidate()" callback).
Do you have some sample code where I can see how to use $this->Model-
>validate() for editing the password?

Thanks.


On Dec 1, 1:36 am, thatsgreat2345 <thatsgreat2...@gmail.com> wrote:
> You can validate from the controller using $this->Model->validate();
>
> On Nov 30, 9:27 am, Milmar <milmarq...@gmail.com> wrote:
>
> > I was able to solve this by first using $this->User->save($this->data)
> > so that I can validate the fields in the model.
> > Then switching to the "saveField" function in the Model's "beforeSave
> > ()" callback so that the save would not affect the HABTM relations.
> > Here's the code for "beforeSave()":
>
> > function beforeSave() {
> >          //If operation is save and this is an edit(has ID,password,
> > and password_confirm),
> >          //   use the saveField command to save the password
> >          if(isset($this->data[$this->alias]['password']) && isset
> > ($this->data[$this->alias]['id']) &&
> >             isset($this->data[$this->alias]['password_confirm']))
> >          {
> >             return $this->saveField('password',$this->data[$this->alias]['password']);
>
> >          }
>
> >          $this->hashPasswords(null, true);
> >          return true;
>
> > }
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: