you have to have somthing like this:
old password: _____________________
new password: ____________________
confirm new password:________________
right??
so first you have to make a method in UsersController called changePassword(){}
and a view in foldes Users called change_password.ctp
in the change password you have to put:
public function changePassword($id = null) {
if ($this->data) {
if ($this->User->save($this->data))
$this->Session->setFlash('Password changed successfully');
else
$this->Session->setFlash('The password was not changed');
} else {
$this->data = $this->User->read(null, $id);
}
}
in change_password.ctp:
<?php echo $this->Form->create();?>
<?php echo $this->Form->input('id');?>
<?php echo $this->Form->input('current_password',array('type'=>'password'));?>
<?php echo $this->Form->input('password',array('label'=>'New password','value'=>''));?>
<?php echo $this->Form->input('password_confirmation',array('label'=>'confirm your password','type'=>'password', 'value'=>''));?>
<?php echo $this->Form->end('change');?>
in User model put:
public $validate = array(
'password' => array(
'Not empty' => array(
'rule' => 'notEmpty', 'message' => 'please enter your password'
),
'Match passwords' => array(
'rule' => 'matchPasswords',
'message' => 'your passwords do not match'
)
),
'password_confirmation' => array(
'Not empty' => array(
'rule' => 'notEmpty', 'message' => 'please confirm your password'
)
),
'current_password' => array(
'notempty' => array('rule' => 'notEmpty', 'message' => 'please enter your old password'),
'check password' => array('rule' => 'checkPassword',
'message' => 'your password is not correct')
)
);
public function matchPasswords($data) {
if ($data['password'] == $this->data['User']['password_confirmation'])
return true;
$this->invalidate('password_confirmation', 'your passwords do not match');
return false;
}
public function checkPassword($data) {
$user1=new User();
$user=$user1->read(null, $this->data['User']['id']);
$current_password=AuthComponent::password($data['current_password']);
if($current_password==$user['User']['password']){
return true;
}
return false;
}
On Tuesday, December 25, 2012 4:24:10 PM UTC+2, sweety wrote:
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
No comments:
Post a Comment