public function editAction()
 {
     if ($this->_hasParam("id")) {
         $id = $this->_getParam("id");
         //$update = $this->_isUserAllowed(User_Module_Acl::ACL_RESOURCE_USER, User_Module_Acl::ACL_RESOURCE_USER_PRIVILEGE_UPDATE);
         $update = Agana_Acl_Service::isAllowed(Zend_Auth::getInstance()->getIdentity()->acl_role_id, User_Module_Acl::ACL_RESOURCE_USER, User_Module_Acl::ACL_RESOURCE_USER_PRIVILEGE_UPDATE);
         $isMe = $id == Zend_Auth::getInstance()->getIdentity()->id;
         if ($update || $isMe) {
             $request = $this->getRequest();
             $userDomain = new User_Domain_User(null);
             $user = $userDomain->getById($id);
             $form = new User_Form_User(User_Form_User::ACTION_EDIT, $user);
             if ($request->isPost()) {
                 $data = $request->getPost();
                 if (isset($data['save'])) {
                     if ($form->isValid($data)) {
                         try {
                             /**
                              * Before save test if the user has permission to change
                              * GROUP and STATUS
                              * It only can update this fields if has update privilege
                              * not only being the profile owner
                              * We do not want that the users change it's own group
                              * to another one like Administrator
                              */
                             if (!$update) {
                                 $data['acl_role_id'] = $user->getAcl_role_id();
                                 $data['status'] = $user->getStatus();
                             }
                             $this->_update($data);
                             $msg = 'User updated';
                             $this->_helper->flashMessenger->addMessage(array('success' => $msg));
                             $this->_helper->redirector('index', 'profile', 'user', array('id' => $id));
                         } catch (Exception $e) {
                             $this->_addSavingExceptionMessage($e);
                         }
                     } else {
                         $this->_addValidationMessage();
                     }
                 } else {
                     if (isset($data['cancel'])) {
                         $lru = new Agana_Controller_Action_Helper_LastRequestUri();
                         $lru->setNamespace('edituserprofile');
                         $lru->redirect('user/admin/list');
                         //$this->_helper->redirector(array('action' => 'list', 'controller' => 'admin', 'module' => 'user'));
                     }
                 }
             }
             $this->view->form = $form;
         }
     } else {
         $this->_helper->flashMessenger->addMessage(array('error' => 'Param id missing'));
         $this->_forward('list');
         return;
     }
 }
Example #2
0
 public function redirectAfterLogin($defaultUri = '')
 {
     $lru = new Agana_Controller_Action_Helper_LastRequestUri();
     $lru->setNamespace($this->_namespace);
     $lru->redirect('user/profile');
 }
 public function updateAction()
 {
     if ($this->_isUserAllowed()) {
         if ($this->_hasParam("id")) {
             $id = $this->_getParam("id");
             $request = $this->getRequest();
             $role = new User_Domain_Role(null);
             $role = $role->getById($id);
             $form = new User_Form_Role(User_Form_Role::ACTION_EDIT, $role);
             if ($request->isPost()) {
                 $data = $request->getPost();
                 if (isset($data['save'])) {
                     if ($form->isValid($request->getPost())) {
                         try {
                             $this->_update($form->getValues());
                             $msg = 'Role updated';
                             $this->_helper->flashMessenger->addMessage(array('success' => $msg));
                             $this->_helper->redirector(array('action' => 'list', 'controller' => 'role', 'module' => 'user'));
                         } catch (Exception $e) {
                             $this->_addSavingExceptionMessage($e);
                         }
                     } else {
                         $this->_addValidationMessage();
                     }
                 } else {
                     if (isset($data['cancel'])) {
                         $lru = new Agana_Controller_Action_Helper_LastRequestUri();
                         $lru->setNamespace('acl_role');
                         $lru->redirect('user/role/list');
                         //$this->_helper->redirector(array('action' => 'list', 'controller' => 'admin', 'module' => 'user'));
                     }
                 }
             }
             $this->view->form = $form;
         } else {
             $this->_helper->flashMessenger->addMessage(array('error' => 'Param id missing'));
             $this->_forward('list');
             return;
         }
     }
 }