Example #1
0
 /**
  * Constructor to enhance the base form to edit a user
  * 
  * @param array $groups
  * @param Admin_Model_DbRow_User $user
  */
 public function __construct(array $groups, Admin_Model_DbRow_User $user)
 {
     parent::__construct($groups);
     $this->addElement(new Zend_Form_Element_Hidden('id', array('value' => $user->get('id'), 'validators' => array('Int'))));
     $this->getElement('name')->setValue($user->get('name'));
     $this->getElement('username')->setValue($user->get('username'));
     $this->getElement('mail')->setValue($user->get('email'));
     $this->getElement('active')->setChecked($user->get('enabled') == 1 ? TRUE : FALSE);
     $this->getElement('group')->setValue($user->get('groupid'));
 }
 /**
  * Create form, so that the admin can change the users password
  *
  * @param Admin_Model_DbRow_User $user
  */
 public function __construct(Admin_Model_DbRow_User $user)
 {
     $this->addElements(array(new Zend_Form_Element_Password('pass1', array('required' => true, 'label' => 'Password:'******'attribs' => array('class' => 'text span-5'), 'validators' => array('notEmpty', array('StringLength', false, array(8, 64))))), new Zend_Form_Element_Password('pass2', array('required' => true, 'label' => 'Repeat Password:'******'attribs' => array('class' => 'text span-5'), 'validators' => array('notEmpty', array('StringLength', false, array(8, 64))))), new Zend_Form_Element_Hidden('id', array('required' => true, 'value' => $user->get('id'))), new Zend_Form_Element_Submit('changepass', array('label' => 'Save'))));
     parent::__construct();
 }
 /**
  * Change the Password for the selected user
  *
  * Password is a salted hash, salt is defined in app config
  *
  * @return array
  */
 public function saveEditUserPwAction()
 {
     $userModel = new Admin_Model_DbTable_Users();
     $userRow = new Admin_Model_DbRow_User($userModel->find($this->request->getParam('id')));
     if ($this->request->getParam('password_input', 1) === $this->request->getParam('password_confirm', 2) && $userRow->get('id')) {
         // the if uses differnt default values for getParam() so that null or '' cannot be set, if fields are not present
         $validate = new Zend_Validate();
         $validate->addValidator(new Zend_Validate_NotEmpty(), new Zend_Validate_StringLength(8));
         if ($validate->isValid($this->request->getParam('password_input'))) {
             $userModel->updatePassword(md5($this->request->getParam('password_input') . Zend_Registry::get('password_salt')), $userRow->get('id'));
             return $this->responseSuccess();
         } else {
             $error = $validate->getMessages();
         }
     } else {
         $error = array('Passwords are not the same or unkown user');
     }
     return $this->responseFailure('Failed Saving informations', $error);
 }
 /**
  * Change the password of an user
  *
  * @view /views/scripts/user/changepassword.phtml
  * @access public
  */
 public function changepasswordAction()
 {
     $userRow = new Admin_Model_DbRow_User($this->dbUser->find($this->checkUserIdParam()));
     $form = new Admin_Form_User_Changepassword($userRow);
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getParams()) && $this->getRequest()->getParam('pass1') === $this->getRequest()->getParam('pass2')) {
             $salt = Zend_Registry::get('password_salt');
             $hashpass = md5($this->getRequest()->getParam('pass1') . $salt);
             // do the update
             $this->dbUser->updatePassword($hashpass, $userRow->get('id'));
             $this->_redirect('admin/user/index');
         } else {
             $form->setDescription('Please fill both fields and ensure, that both passwords are equal');
         }
     }
     $this->view->form = $form;
 }