I have an edit profile form where the user can enter password and
password1 box if they want it to change..
In my model i have a regex for a valid password. My passwords are
md5'd and i want to be able to make sure its a valid password before
doing the save.. And after i make sure it validates, i want to md5
it. I've noticed a lot of people user the beforeValidate method for
extra validation.. i dont think thats what i want though since i want
to do the validation, then change the data.. then i really dont need
to do it again..
What is the best way to set this up. Right now i thought i could just
call validate like this
$this->User->validate($this->data);
in the controller before saving.... Then if it validates i md5 the
password and call save.. Unfortunately i'm getting an error, it says
my sql statement is just the word
'validate'
instead of update ......
I have no idea why. I set the id for the $this->User->id before
trying to validate.
this is what i ahve so far
function edit_profile() {
$this->User->id = $this->Session->read('User.id');
if (empty($this->data))
{
$this->data = $this->User->read();
}
else
{
$ok = false;
$u = &$this->data['User'];
$p1 = &$u['password'];
$p2 = &$u['password1'];
if ($p1 != $p2)
{
$this->set('error', "Passwords do not match");
} else {
if (empty($p1)) {
unset($this->data['User']['password']);
$ok =
$this->User->validate($this->data);
} else {
$ok =
$this->User->validate($this->data);
}
#die("WTF");
if ($ok) {
if ($this->User->save($this->data,
false)) {
$this->flash("Your profile has
been saved.", '/users/profile');
} else {
$this->flash("ERROR: Your
profile has not been saved.", '/users/
profile');
}
} else {
$this->flash("ERROR: Your profile has
not been saved.", '/users/
profile');
}
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---