MyController::password PHP Method

password() public method

#
public password ( )
    public function password()
    {
        // cann't change password ,user has auth_source_id
        if ($this->current_user['auth_source_id']) {
            $this->Session->setFlash(__('This account uses an external authentication source. Impossible to change the password.'), 'default', array('class' => 'flash flash_notice'));
            $this->redirect('account');
        }
        if (!empty($this->request->data)) {
            if ($this->User->check_password($this->request->data['User']['password'], $this->current_user)) {
                $data = $this->request->data;
                $data['User']['id'] = $this->current_user['id'];
                $data['User']['password'] = $this->request->data['User']['new_password'];
                $data['User']['password_confirmation'] = $this->request->data['User']['new_password_confirmation'];
                if ($this->User->save($data)) {
                    $this->Session->setFlash(__('Password was successfully updated.'), 'default', array('class' => 'flash flash_notice'));
                    $this->redirect('account');
                }
            } else {
                $this->Session->setFlash(__('Wrong password'), 'default', array('class' => 'flash flash_error'));
            }
        }
    }