public passwordRequired ( ) : |
||
return |
public function passwordRequired()
{
$filter = $this->getInputFilter();
$filter->add(array('required' => true, 'validators' => array(array('name' => 'not_empty'))), 'password');
$filter->add(array('required' => true, 'validators' => array(array('name' => 'not_empty'))), 'password_confirm');
return $this;
}
/** * Edit user * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $userId = $this->getRouteMatch()->getParam('id'); $userModel = User\Model::fromId($userId); if (empty($userModel)) { $this->flashMessenger()->addErrorMessage("Can't edit this user"); return $this->redirect()->toRoute('config/user'); } $form = new UserForm(); $form->setAttribute('action', $this->url()->fromRoute('config/user/edit', array('id' => $userId))); $form->loadValues($userModel); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost()->toArray(); if (!empty($post['password'])) { $form->passwordRequired(); $form->getInputFilter()->get('password_confirm')->getValidatorChain()->addValidator(new Identical($post['password'])); } $form->setData($post); if ($form->isValid()) { $userModel->addData($post); $userModel->setActive(empty($post['active']) ? false : $post['active']); if (!empty($post['password'])) { $userModel->setPassword($post['password']); } $userModel->save(); $this->flashMessenger()->addSuccessMessage('This user has been saved'); return $this->redirect()->toRoute('config/user/edit', array('id' => $userId)); } $this->flashMessenger()->addErrorMessage('User can not be saved'); } return array('form' => $form); }