/** Add a new user */ public function addAction() { $form = new EditAccountForm(); $form->setLegend('New account: '); $form->submit->setLabel('Create account details'); $form->username->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'username')); $form->password->setLabel('Your password: '******'config'); $salt = $config->auth->salt; $password = SHA1($salt . $form->getValue('password')); $insertData = array('username' => $form->getValue('username'), 'first_name' => $form->getValue('first_name'), 'last_name' => $form->getValue('last_name'), 'fullname' => $form->getValue('fullname'), 'email' => $form->getValue('email'), 'institution' => $form->getValue('institution'), 'role' => $form->getValue('role'), 'password' => $password, 'peopleID' => $form->getValue('peopleID'), 'created' => $this->getTimeForForms(), 'createdBy' => $this->getIdentityForForms()); foreach ($insertData as $key => $value) { if (is_null($value) || $value == "") { unset($insertData[$key]); } } $username = $form->getValue('username'); $users->insert($insertData); $imagepath = self::IMAGEPATH . $username; $smallimagepath = self::IMAGEPATH . $username . '/small/'; $mediumimagepath = self::IMAGEPATH . $username . '/medium/'; $displayimagepath = self::IMAGEPATH . $username . '/display/'; mkdir($imagepath); mkdir($smallimagepath); mkdir($mediumimagepath); mkdir($displayimagepath); $this->_flashMessenger->addMessage('You successfully added a new account'); $this->_redirect('/admin/users/account/username/' . $form->getValue('username')); } else { $form->populate($formData); } } }
/** Add a new user * @access public * @return void */ public function addAction() { $form = new EditAccountForm(); $form->setLegend('New account: '); $form->submit->setLabel('Create account details'); $form->username->addValidator('Db_NoRecordExists', false, array('table' => 'users', 'field' => 'username')); $form->institution->setRequired(true); $form->role->setRequired(true); $form->institution->setRequired(true); $form->email->setRequired(true); $this->view->form = $form; if ($this->_request->isPost()) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $salt = $this->_helper->config()->auth->salt; $password = SHA1($salt . $form->getValue('password')); $insertData = array('username' => $form->getValue('username'), 'first_name' => $form->getValue('first_name'), 'last_name' => $form->getValue('last_name'), 'fullname' => $form->getValue('fullname'), 'imagedir' => 'images/' . $form->getValue('username'), 'email' => $form->getValue('email'), 'institution' => $form->getValue('institution'), 'role' => $form->getValue('role'), 'password' => $password, 'peopleID' => $form->getValue('peopleID')); $username = $form->getValue('username'); $this->getUsers()->add($insertData); $directories = array(IMAGE_PATH . $username, IMAGE_PATH . $username . '/small/', IMAGE_PATH . $username . '/medium/', IMAGE_PATH . $username . '/display/', IMAGE_PATH . $username . '/zoom/'); foreach ($directories as $dir) { mkdir($dir, 0777); } $this->getFlash()->addMessage('You successfully added a new account'); $this->redirect('admin/users/account/username/' . $form->getValue('username')); } else { $form->populate($formData); } } }