Sunday, November 29, 2009

Updating Record - Reset Password

Hi I'm having problem with this method,
it is not saving or updating,
can you please help me and tell me what is wrong with the code below.
I'm Using cakephp 1.2.5

public function reset_password()
{

if(!empty($this->data))
{
if(!empty($this->data['User']['email']))
{
$this->User->unBindAll();
$user = $this->User->findByEmail($this->data['User']['email']);
if(!empty($user))
{
$this->User->id = $user['User']['id'];
$data['User']['id'] = $user['User']['id'];
$data['User']['tmp_password'] = $this->generate_password(7);
$data['User']['password'] = $this->Auth->password($data['User']
['tmp_password']);
if($this->User->save($data))
{
$this->Session->setFlash('Password Successfully Changed<br /
>Please check you email.','flash');
}
}
else
{
$this->Session->setFlash('Email address is not on the
database.','flash');
}
}
else
{
$this->Session->setFlash('Email address cannot be
empty.','flash');
}
}
}

public function generate_password($len)
{
$pass = '';
$lchar = 0;
$char = 0;
for($i=0;$i<$len;$i++)
{
while($char==$lchar)
{
$char = rand(48, 109);
if($char>57)$char+=7;
if($char>90)$char+=6;
}
$pass .= chr($char);
$lchar = $char;
}
return $pass;
}

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 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: