Edit user

@return \Zend\Http\Response|ViewModel|array
8034
public function editAction()
    {
        /* @var $user \Auth\Entity\User */
        $user = $this->userRepository->find($this->params('id'), \Doctrine\ODM\MongoDB\LockMode::NONE, null, ['allowDeactivated' => true]);
        
        // check if user is not found
        if (!$user) {
            return $this->notFoundAction();
        }
        
        $params = $this->params();
        $forms = $this->formManager;
        /* @var $infoContainer \Auth\Form\UserProfileContainer */
        $infoContainer = $forms->get('Auth/UserProfileContainer');
        $infoContainer->setEntity($user);
        $statusContainer = $forms->get('Auth/UserStatusContainer');
        $statusContainer->setEntity($user);
        
        // set selected user to image strategy
        $imageStrategy = $infoContainer->getForm('info.image')
            ->getHydrator()
            ->getStrategy('image');
		$fileEntity = $imageStrategy->getFileEntity();
		$fileEntity->setUser($user);
		$imageStrategy->setFileEntity($fileEntity);
        
        if ($this->request->isPost()) {
            $formName = $params->fromQuery('form');
            $container = $formName === 'status' ? $statusContainer : $infoContainer;
            $form = $container->getForm($formName);
        
            if ($form) {
                $postData  = $form->getOption('use_post_array') ? $params->fromPost() : [];
                $filesData = $form->getOption('use_files_array') ? $params->fromFiles() : [];
                $form->setData(array_merge($postData, $filesData));
        
                if (!$form->isValid()) {
                    return new JsonModel(
                        array(
                            'valid' => false,
                            'errors' => $form->getMessages(),
                        )
                    );
                }
                
                $this->userRepository->store($user);
        
                if ('file-uri' === $params->fromPost('return')) {
                    $content = $form->getHydrator()->getLastUploadedFile()->getUri();
                } else {
                    if ($form instanceof SummaryFormInterface) {
                        $form->setRenderMode(SummaryFormInterface::RENDER_SUMMARY);
                        $viewHelper = 'summaryForm';
                    } else {
                        $viewHelper = 'form';
                    }
                    $content = $this->viewHelper->get($viewHelper)->__invoke($form);
                }
        
                return new JsonModel(
                    array(
                        'valid' => $form->isValid(),
                        'content' => $content,
                    )
                );
            }
        }
        
        return [
            'infoContainer' => $infoContainer,
            'statusContainer' => $statusContainer
        ];
    }
511636
public function edit($id)
    {
        if (\Auth::user()->id == 1 || \Auth::user()->id == 2) {
            $user = Admin::find($id);
            return view('adminems::users.edit', compact('user'));
        }

        return redirect()->route('panel');
    }
293283
public function editUserAction()
    {
        if(!$this->identity()) {
          return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
      
        try {
            $id = (int) $this->params()->fromRoute('id', 0);
    
            if ($id == 0) {
                $this->flashMessenger()->addErrorMessage($this->getTranslatorHelper()->translate('User ID invalid'));
                return $this->redirect()->toRoute('user-admin');
            }
            
            $entityManager = $this->getEntityManager();
            $user = $entityManager->getRepository('CsnUser\Entity\User')->find($id);
            
            $form = $this->getUserFormHelper()->createUserForm($user, 'EditUser');
            
            $form->setAttributes(array(
                'action' => $this->url()->fromRoute('user-admin', array('action' => 'edit-user', 'id' => $id)),
            ));
              	
            $request = $this->getRequest();
            if ($request->isPost()) {
                $form->setValidationGroup('username', 'email', 'firstName', 'lastName', 'language', 'state', 'role', 'question', 'answer', 'csrf');
                $form->setData($request->getPost());
                if ($form->isValid()) {
                    $entityManager->persist($user);
                    $entityManager->flush();
                    $this->flashMessenger()->addSuccessMessage($this->getTranslatorHelper()->translate('User Updated Successfully'));
                    return $this->redirect()->toRoute('user-admin');
                }
            }  
        }      
        catch (\Exception $e) {
            return $this->getServiceLocator()->get('csnuser_error_view')->createErrorView(
                $this->getTranslatorHelper()->translate('Something went wrong during update user process! Please, try again later.'),
                $e,
                $this->getOptions()->getDisplayExceptions(),
                false
            );
        }
        
        $viewModel = new ViewModel(array(
            'form' => $form,
            'headerLabel' => $this->getTranslatorHelper()->translate('Edit User').' - '.$user->getDisplayName(),
        ));
        $viewModel->setTemplate('csn-user/admin/edit-user-form');
        return $viewModel;
    }
1045194
public function edit($id)
    {
      $user  = $this->users->findOrFail($id);
      $roles = Role::pluck('name', 'id');
      return \View::make('admin.users.edit', [
        'user'              =>  $user,
        'roles'              =>  $roles,
        'title'              => 'edit',
      ]);
    }
409644
public function edit($id = null)
    {
        $user = $this->Users->get($id);

        //Only the admin founder can edit others admin users
        if ($user->group_id === 1 && !$this->Auth->isFounder()) {
            $this->Flash->alert(I18N_ONLY_ADMIN_FOUNDER);

            return $this->redirect(['action' => 'index']);
        }

        $user = $this->Users->patchEntity($user, $this->request->getData(), ['validate' => 'EmptyPassword']);

        if ($this->request->is(['patch', 'post', 'put'])) {
            if ($this->Users->save($user)) {
                $this->Flash->success(I18N_OPERATION_OK);

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error(I18N_OPERATION_NOT_OK);
        }

        $this->set(compact('user'));
    }
826033
private function edit()
    {
        $columns = [];
        $values = [];
        //
        if ($this->_tracked) {
            $this->edited_at = Time::current();
        }
        //
        foreach ($this->_columns as $value) {
            if ($value != $this->_keyName) {
                $columns[] = $value;
                $values[] = empty($this->$value) ? null : $this->$value;
            }
        }
        //
        return $this->update($columns, $values);
    }
695985
protected function editor(User $user)
    {
        // store props
        $oldProps = new UserUpdater($user);
        $newProps = $this->getNewValues($user);

        // confirm
        $ln = <<<EOL
Summary
-------
Username: "{$newProps->getUsername()}"
Email:    "{$newProps->getEmail()}"
Password: "{$newProps->getPassword()}"
EOL;
        $this->logger->block($ln);

        // check changes
        $changedValues = $oldProps->getChanged($newProps);
        if (empty($changedValues)) {
            $this->logger->note('Nothing changed, exiting.');

            return;
        }
        // persist
        if ($persist = $this->ask(new ConfirmationQuestion('Confirm user update?'))) {
            $this->userEditor->updateUser($user, $newProps);
            $this->logger->success('User updated!');
        }
        // send mail
        if ($persist) {
            $dontSend = 'Don\'t send';
            $emailChoices = [$dontSend, $oldProps->getEmail()];
            if (isset($changedValues['email'])) {
                $emailChoices[] = $changedValues['email'];
            }
            $to = $this->ask(new ChoiceQuestion('Send notification to', $emailChoices));
            if ($to !== $dontSend) {
                $this->sendNotification($to, $changedValues);
            }
        }
    }
578836
public function editAction()
    {
        if(method_exists($this, 'getEditForm'))
        {
            $form = $this->getEditForm();
        }
        else
        {
            $form = $this->getForm();
        }

        $id = $this->getEvent()
                ->getRouteMatch()
                ->getParam('id', 0);

        $form->add([
            'type'       => 'Zend\Form\Element\Hidden',
            'name'       => 'id',
            'attributes' => [
                'id'    => 'id',
                'value' => $id,
            ],
            'filters'    => [
                [
                    'name' => 'Int',
                ],
            ],
            'validators' => [
                [
                    'name' => 'Digits',
                ],
            ],
        ]);

        $em            = $this->getEntityManager();
        $objRepository = $em->getRepository($this->getEntityClass());
        $entity        = $objRepository->find($id);
        $form->bind($entity);

        $redirectUrl = $this->url()->fromRoute($this->getActionRoute(), [], true);
        $prg         = $this->fileprg($form, $redirectUrl, true);

        if($prg instanceof Response)
        {
            return $prg;
        }
        elseif($prg === false)
        {
            $this->getEventManager()->trigger('getForm', $this, [
                'form'        => $form,
                'entityClass' => $this->getEntityClass(),
                'id'          => $id,
                'entity'      => $entity,
            ]);

            return [
                'entityForm' => $form,
                'entity'     => $entity,
            ];
        }

        $this->getEventManager()->trigger('getForm', $this, [
            'form'        => $form,
            'entityClass' => $this->getEntityClass(),
            'id'          => $id,
            'entity'      => $entity,
        ]);

        $savedEntity = $this->getEntityService()->save($form, $entity);

        if(!$savedEntity)
        {
            return [
                'entityForm' => $form,
                'entity'     => $entity,
            ];
        }

        $this->flashMessenger()->addSuccessMessage($this->getServiceLocator()
                        ->get('translator')
                        ->translate($this->successEditMessage));

        return $this->redirect()->toRoute($this->getActionRoute('list'), [], true);
    }
646525
public function edit($id)
    {
        $record = $this->model->findOrFail($id);

        $this->viewData['record'] = $record;

        $this->viewData['formMethod'] = 'PUT';
        $this->viewData['formAction'] = 'user.update';

        return view($this->defaultFormView, $this->viewData);
    }
14604
def edit_user(self, user_id, user_object):
        
        return self.user_service.editObject(user_object, id=user_id)
60131
public function editaddress()
    {
        $member = Security::getCurrentUser();
        $id = $this->getOwner()->request->param("ID");
        $address = ContactLocation::get()->byID($id);

        if ($address && $address->canEdit($member)) {
            $form = $this->AddressForm();
            $form->loadDataFrom($address);
            $form
                ->Actions()
                ->dataFieldByName("action_doSaveAddress")
                ->setTitle(_t("SilverCommerce\ContactAdmin.Save", "Save"));

            $this
                ->getOwner()
                ->customise([
                    "Title" => _t(
                        "SilverCommerce\ContactAdmin.EditAddress",
                        "Edit Address"
                    ),
                    "MenuTitle" => _t(
                        "SilverCommerce\ContactAdmin.EditAddress",
                        "Edit Address"
                    ),
                    "Form" => $form
                ]);

            $this->getOwner()->extend("updateEditAddress");
            
            return $this
                ->getOwner()
                ->renderWith([
                    'AccountController_editaddress',
                    AccountController::class . '_editaddress',
                    'AccountController',
                    AccountController::class,
                    'Page'
                ]);
        } else {
            return $this->getOwner()->httpError(404);
        }
    }
386278
public function edit(Request $request, $user)
    {
        // Set roles that have access
        $request->user()->authorizeRoles(['admin']);

        // Return view with user object
        $user = User::findOrFail($user);
        return view('user::edit', ['user' => $user]);
    }
383300
public function editUserForgot()
    {
        $this->controlAccessUserForgot();

        $this->setUserForgot();
        $this->setTitleEditUserForgot();
        $this->setBreadcrumbEditUserForgot();

        $this->setData('forgetful_user', $this->data_user);
        $this->setData('password_limit', $this->user->getPasswordLength());

        $this->submitUserForgot();
        $this->outputEditUserForgot();
    }
454584
public function Edit($UserID) {
      $this->Permission('Garden.Users.Edit');
      
      // Page setup
      $this->AddJsFile('user.js');
      $this->Title(T('Edit User'));
      $this->AddSideMenu('dashboard/user');

      // By default, people with access here can freely assign all roles
      $RoleModel = new RoleModel();
      $RoleData = $AllRoles = $RoleModel->GetArray();

      // Hide personal info roles
      if (!CheckPermission('Garden.PersonalInfo.View')) {
         $RoleData = array_filter($RoleData, 'RoleModel::FilterPersonalInfo');
      }

      $UserModel = new UserModel();
      $User = $UserModel->GetID($UserID, DATASET_TYPE_ARRAY);
      
      // Determine if username can be edited
      $CanEditUsername = (bool)C("Garden.Profile.EditUsernames") || Gdn::Session()->CheckPermission('Garden.Users.Edit');
      $this->SetData('_CanEditUsername', $CanEditUsername);
      
      // Determine if emails can be edited
      $CanEditEmail = (
              Gdn::Session()->CheckPermission('Garden.Users.Edit') && 
              Gdn::Session()->CheckPermission('Garden.PersonalInfo.View')
           );
      $this->SetData('_CanEditEmail', $CanEditEmail);
      
      // Decide if they have ability to confirm users
      $Confirmed = (bool)GetValueR('Confirmed', $User);
      $CanConfirmEmail = (
              UserModel::RequireConfirmEmail() &&
              Gdn::Session()->CheckPermission('Garden.Users.Edit') && 
              Gdn::Session()->CheckPermission('Garden.PersonalInfo.View'));
      $this->SetData('_CanConfirmEmail', $CanConfirmEmail);
      $this->SetData('_EmailConfirmed', $Confirmed);
      $User['ConfirmEmail'] = (int)$Confirmed;

      // Set the model on the form.
      $this->Form->SetModel($UserModel);

      // Make sure the form knows which item we are editing.
      $this->Form->AddHidden('UserID', $UserID);

      try {
         
         $AllowEditing = TRUE;
         $this->EventArguments['AllowEditing'] = &$AllowEditing;
         $this->EventArguments['TargetUser'] = &$User;
         
         // These are all the 'effective' roles for this edit action. This list can
         // be trimmed down from the real list to allow subsets of roles to be
         // edited.
         $this->EventArguments['RoleData'] = &$RoleData;
         
         $UserRoleData = $UserModel->GetRoles($UserID)->ResultArray();
         $RoleIDs = ConsolidateArrayValuesByKey($UserRoleData, 'RoleID');
         $RoleNames = ConsolidateArrayValuesByKey($UserRoleData, 'Name');
         $UserRoleData = ArrayCombine($RoleIDs, $RoleNames);
         $this->EventArguments['UserRoleData'] = &$UserRoleData;
         
         $this->FireEvent("BeforeUserEdit");
         $this->SetData('AllowEditing', $AllowEditing);
         
         $this->Form->SetData($User);
         if ($this->Form->AuthenticatedPostBack()) {
            
            if (!$CanEditUsername)
               $this->Form->SetFormValue("Name", $User['Name']);
            
            // Allow mods to confirm/unconfirm emails
            $this->Form->RemoveFormValue('Confirmed');
            $Confirmation = $this->Form->GetFormValue('ConfirmEmail', null);
            $Confirmation = !is_null($Confirmation) ? (bool)$Confirmation : null;

            if ($CanConfirmEmail && is_bool($Confirmation))
               $this->Form->SetFormValue('Confirmed', (int)$Confirmation);
            
            // If a new password was specified, add it to the form's collection
            $ResetPassword = $this->Form->GetValue('ResetPassword', FALSE);
            $NewPassword = $this->Form->GetValue('NewPassword', '');
            if ($ResetPassword == 'Manual') 
               $this->Form->SetFormValue('Password', $NewPassword);
            
            // Role changes
            
            // These are the new roles the editing user wishes to apply to the target
            // user, adjusted for his ability to affect those roles
            $RequestedRoles = $this->Form->GetFormValue('RoleID');
            
            if (!is_array($RequestedRoles)) $RequestedRoles = array();
            $RequestedRoles = array_flip($RequestedRoles);
            $UserNewRoles = array_intersect_key($RoleData, $RequestedRoles);
            
            // These roles will stay turned on regardless of the form submission contents 
            // because the editing user does not have permission to modify them
            $ImmutableRoles = array_diff_key($AllRoles, $RoleData);
            $UserImmutableRoles = array_intersect_key($ImmutableRoles, $UserRoleData);
            
            // Apply immutable roles
            foreach ($UserImmutableRoles as $IMRoleID => $IMRoleName)
               $UserNewRoles[$IMRoleID] = $IMRoleName;
            
            // Put the data back into the forum object as if the user had submitted 
            // this themselves
            $this->Form->SetFormValue('RoleID', array_keys($UserNewRoles));
            
            if ($this->Form->Save(array('SaveRoles' => TRUE)) !== FALSE) {
               if ($this->Form->GetValue('ResetPassword', '') == 'Auto') {
                  $UserModel->PasswordRequest($User['Email']);
                  $UserModel->SetField($UserID, 'HashMethod', 'Reset'); 
               }

               $this->InformMessage(T('Your changes have been saved.'));
            }
            
            $UserRoleData = $UserNewRoles;
         }
      } catch (Exception $Ex) {
         $this->Form->AddError($Ex);
      }
      
      $this->SetData('User', $User);
      $this->SetData('Roles', $RoleData);
      $this->SetData('UserRoles', $UserRoleData);
      
      $this->Render();
   }
1365961
public function edit($userId)
    {
        $this->requireAdmin();

        $method = $this->request->getMethod();
        $user = $this->userStore->getById($userId);

        if (empty($user)) {
            throw new NotFoundException(Lang::get('user_n_not_found', $userId));
        }

        $this->layout->title = $user->getName();
        $this->layout->subtitle = Lang::get('edit_user');

        $values = array_merge($user->getDataArray(), $this->getParams());
        $form = $this->userForm($values, 'edit/' . $userId);

        if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
            $view = new b8\View('UserForm');
            $view->type = 'edit';
            $view->user = $user;
            $view->form = $form;

            return $view->render();
        }

        $name = $this->getParam('name', null);
        $email = $this->getParam('email', null);
        $password = $this->getParam('password', null);
        $isAdmin = (int)$this->getParam('is_admin', 0);

        $this->userService->updateUser($user, $name, $email, $password, $isAdmin);

        $response = new b8\Http\Response\RedirectResponse();
        $response->setHeader('Location', PHPCI_URL . 'user');
        return $response;
    }
155814
public function getEditor()
    {
        $user = null;

        if($this->hasProperty('modified_by') && !empty($this->modified_by)) {
            $user = $this->getObject('user.provider')->getUser($this->modified_by);
        }

        return $user;
    }
115590
function canEdit( )
    {
        if ( !isset( $this->Permissions["can_edit"] ) )
        {
            $this->Permissions["can_edit"] = $this->checkAccess( 'edit' );
            if ( $this->Permissions["can_edit"] != 1 )
            {
                 $user = eZUser::currentUser();
                 if ( $user->id() == $this->ContentObject->attribute( 'id' ) )
                 {
                     $access = $user->hasAccessTo( 'user', 'selfedit' );
                     if ( $access['accessWord'] == 'yes' )
                     {
                         $this->Permissions["can_edit"] = 1;
                     }
                 }
            }
        }
        return ( $this->Permissions["can_edit"] == 1 );
    }