public function editAction() { $translator = \Zend_Registry::get('container')->getService('translator'); $form = new Admin_Form_User(); $form->user_type->setMultioptions($this->userTypeService->getOptions()); $form->author->setMultioptions(array('' => $translator->trans('None', array(), 'users')) + $this->_helper->service('author')->getOptions()); $user = $this->getUser(); $form->setDefaultsFromEntity($user); $request = $this->getRequest(); if ($request->isPost() && $form->isValid($request->getPost())) { try { $values = $form->getValues(); $values['attributes']['is_featured'] = $values['is_featured']; $values['attributes']['is_verified'] = $values['is_verified']; unset($values['is_featured']); unset($values['is_verified']); $this->userService->save($values, $user); $cacheService = \Zend_Registry::get('container')->get('newscoop.cache'); $cacheService->getCacheDriver()->deleteAll(); $this->_helper->flashMessenger($translator->trans("User saved", array(), 'users')); $this->_helper->redirector('edit', 'user', 'admin', array('user' => $user->getId())); } catch (\InvalidArgumentException $e) { switch ($e->getMessage()) { case 'username_conflict': $form->username->addError($translator->trans('Username is used already', array(), 'users')); break; case 'email_conflict': $form->email->addError($translator->trans('Email is used already', array(), 'users')); break; } } } $requestSymfony = \Zend_Registry::get('container')->getService('request'); $zendRouter = \Zend_Registry::get('container')->getService('zend_router'); $publicationMetadata = $requestSymfony->attributes->get('_newscoop_publication_metadata'); $baseUrl = $requestSymfony->getScheme() . '://' . $publicationMetadata['alias']['name'] . $zendRouter->assemble(array('controller' => 'images'), 'default', true); $this->view->form = $form; $this->view->user = $user; $this->view->image = $this->_helper->service('image')->getSrc('images/' . $user->getImage(), 80, 80, 'crop'); $this->view->baseImage = $baseUrl . '/' . $user->getImage(); $this->view->originalImage = $user->getImage(); $this->view->actions = array(array('label' => $translator->trans('Edit geolocation', array(), 'users'), 'module' => 'admin', 'controller' => 'user', 'action' => 'geolocation', 'class' => 'iframe', 'params' => array('user' => $user->getId())), array('label' => $translator->trans('Edit permissions', array(), 'users'), 'module' => 'admin', 'controller' => 'acl', 'action' => 'edit', 'params' => array('user' => $user->getId(), 'role' => $user->getRoleId()))); }
/** * Set staff groups * * @param Newscoop\Entity\User\Staff $staff * @return void */ public function setDefaultsFromEntity(Staff $staff) { parent::setDefaultsFromEntity($staff); if (!$this->isAdmin) { return; } $groups = array(); foreach ($staff->getGroups() as $group) { $groups[] = $group->getId(); } $this->setDefaults(array('groups' => $groups)); $this->getElement('groups')->setOrder(31); // $this->getElement('password_confirm')->getOrder() + 1 }
/** * The default action * * Displays the admin dashboard * * @return void */ public function indexAction() { $notes = new Model_Note(); $this->view->notes = $notes->getUsersNotes(); $content = new Model_Page(); $this->view->pages = $content->getCurrentUsersPages('create_date DESC', 5); $user = new Model_User(); $identity = $user->getCurrentUser(); $form = new Admin_Form_User(); $form->onlyIndexIndexActionElements(); $form->setAction($this->baseUrl . '/admin/user/update-my-account'); $firstName = $form->getElement('first_name'); $firstName->setValue($identity->first_name); $lastName = $form->getElement('last_name'); $lastName->setValue($identity->last_name); $email = $form->getElement('email'); $email->setValue($identity->email); $submit = $form->getElement('submitAdminUserForm'); $submit->setLabel($this->view->getTranslation('Update My Account')); $displayGroup = $form->getDisplayGroup('adminUserGroup'); $displayGroup->setLegend($this->view->getTranslation('My Account'))->setAttrib('class', 'formColumn'); $this->view->form = $form; }
public function editAction() { $form = new Admin_Form_User(); $form->user_type->setMultioptions($this->userTypeService->getOptions()); $form->author->setMultioptions(array('' => getGS('None')) + $this->_helper->service('author')->getOptions()); $user = $this->getUser(); $form->setDefaultsFromEntity($user); $request = $this->getRequest(); if ($request->isPost() && $form->isValid($request->getPost())) { try { $this->userService->save($form->getValues(), $user); $this->_helper->flashMessenger(getGS("User saved")); $this->_helper->redirector('edit', 'user', 'admin', array('user' => $user->getId())); } catch (\InvalidArgumentException $e) { switch ($e->getMessage()) { case 'username_conflict': $form->username->addError(getGS('Username is used already')); break; case 'email_conflict': $form->email->addError(getGS('Email is used already')); break; } } } $this->view->form = $form; $this->view->user = $user; $this->view->image = $this->_helper->service('image')->getSrc('images/' . $user->getImage(), 80, 80, 'crop'); $this->view->actions = array(array('label' => getGS('Edit permissions'), 'module' => 'admin', 'controller' => 'acl', 'action' => 'edit', 'params' => array('user' => $user->getId(), 'role' => $user->getRoleId())), array('label' => getGS('Edit subscriptions'), 'module' => 'admin', 'controller' => 'subscription', 'action' => 'index', 'class' => 'iframe', 'params' => array('user' => $user->getId()))); }
public function addAction() { $request = $this->getRequest(); $form = new Admin_Form_User(); $options = $request->getPost(); if ($request->isPost()) { /*---- email validation ----*/ $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.')))); /*-------------------------*/ if ($form->isValid($options)) { $model = new Application_Model_User(); $options['dob'] = $options['year'] . "-" . $options['month'] . "-" . $options['day']; $options['status'] = 'active'; $options['password'] = md5($options['password']); $options['preferredLanguage'] = 'English'; //$options['userLevelId'] =$options['userLevelId']; //$model->setOptions($options); // $id=$model->save(); /*--------- Upload image START -------------------------*/ $upload = new Zend_File_Transfer_Adapter_Http(); if ($upload->isValid('image')) { $upload->setDestination("media/picture/profile/"); try { $upload->receive('image'); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $file_name = $upload->getFileName('image'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "profile_" . $id . ".{$ext}"; $targetPath = 'media/picture/profile/' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $options['image'] = $target_file_name; /*--- Generate Thumbnail ---*/ $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(100, 100); $thumb->save($targetPath = 'media/picture/profile/thumb_' . $target_file_name); $model->setOptions($options); $model->setId($id); $id = $model->save(); } /*--------- Upload image END -------------------------*/ //$options['dob'] = $options['year']."-".$options['month']."-".$options['day']; //$model->setOptions($options); //$model->save(); $user = new Application_Model_User($options); $user_id = $user->save(); if ($user_id > 0) { /*---- default permission settings ----*/ $user->setDefaultPermissions($user_id); $user->setDefaultJournal($user_id); } $this->view->msg = "'User has been inserted successfully!"; $form->reset(); } else { $form->reset(); $form->populate($options); } } $this->view->form = $form; }
public function saveAction() { $messages = array(); $isValidEmail = true; $session = new Zend_Session_Namespace('data'); $form = new Admin_Form_User(); $table = new Tri_Db_Table('user'); $data = $this->_getAllParams(); if ($data['email'] && (!isset($data['id']) || !$data['id'])) { $row = $table->fetchRow(array('email = ?' => $data['email'])); if ($row) { $isValidEmail = false; $messages[] = 'Email existing'; } } if (!isset($data['id']) || !$data['id']) { $form->getElement('password')->setAllowEmpty(false); } if ($form->isValid($data) && $isValidEmail) { if (!$form->image->receive()) { $messages[] = 'Image fail'; } $data = $form->getValues(); if (!$form->image->getValue()) { unset($data['image']); } if (!$data['password']) { unset($data['password']); } if (isset($data['id']) && $data['id'] && Zend_Auth::getInstance()->hasIdentity()) { $row = $table->find($data['id'])->current(); $row->setFromArray($data); $id = $row->save(); } else { unset($data['id']); $row = $table->createRow($data); $id = $row->save(); $session->attempt = 0; $data['password'] = $this->_getParam('password'); $this->view->data = $data; $mail = new Zend_Mail(APP_CHARSET); $mail->setBodyHtml($this->view->render('user/welcome.phtml')); $mail->setSubject($this->view->translate('Welcome')); $mail->addTo($data['email'], $data['name']); $mail->send(); $result = $this->login($data['email'], $data['password']); if ($result->isValid()) { if ($session->url) { $this->_helper->_flashMessenger->addMessage('Success'); $url = $session->url; $session->url = null; $this->_redirect($url); } } } $this->_helper->_flashMessenger->addMessage('Success'); $identity = Zend_Auth::getInstance()->getIdentity(); if ($identity->id == $id) { $this->_redirect('user/edit'); } if ($identity->role == 'institution') { $this->_redirect('user'); } $this->_redirect('dashboard'); } $messages[] = 'Error'; $this->view->messages = $messages; $this->view->form = $form; $this->render('form'); }
/** * Add action * * Add a new user * * @return void */ public function createAction() { $form = new Admin_Form_User(); $elmUserName = $form->getElement('name'); $elmUserName->addValidators(array(array('UsernameExistsNot', true))); $form->onlyCreateActionElements(); $u = new Model_User(); $form->setModel($u); if ($form->validatePost()) { $password = $form->getValue('password'); $userName = $form->getValue('name'); $result = $form->create(array('password' => md5($password))); if ($result) { $this->_redirect('admin/user/open/username/' . $userName); } } $this->view->breadcrumbs['Create User'] = $this->baseUrl . '/admin/user/create'; $form->setAction($this->baseUrl . '/admin/user/create'); $this->view->form = $form; $this->view->toolbarLinks['Add to my bookmarks'] = $this->baseUrl . '/admin/index/bookmark/url/admin_user_create'; }
public function validateAction() { $this->_helper->viewRenderer->setNoRender(); $this->_helper->getHelper('layout')->disableLayout(); $form = new Admin_Form_User(); $form->isValid($this->_getAllParams()); $json = $form->getMessages(); header('Content-type: application/json'); echo Zend_Json::encode($json); }