Edit user's profile.
@param boolean $isNewRecord
@return integer|false the number of rows affected, or false if validation fails
508082
public function save($isNewRecord)
    {
        if ($this->validate()) {
            $user = $this->user;
            $data = [];
            $fn = $user->formName();
            if ($isNewRecord) {
                $data[$fn]['username']    = $this->username;
            }
            $data[$fn]['email']           = $this->email;
            $data[$fn]['password']        = $this->password_new;
            $data[$fn]['change_auth_key'] = $this->change_auth_key;

            $loaded = $user->load($data);
            if ($isNewRecord) {
                $user->scenario = $user::SCENARIO_CREATE;
                $user->status = $user::STATUS_REGISTERED;
                $saved = $user->insert();
            } else {
                $saved = $user->update();
            }
            if ($loaded && $saved) {
                $this->auth_key = $user->auth_key;
                return $saved;
            } else {
                $this->addErrors($user->errors);
            }
        }
        return false;
    }
357325
public function refreshProfile(array $userProfile = [])
    {
        if (count($userProfile) == 0) {
            $userProfile = $this->getProfileFromApi();
        }

        $success = false;

        if (is_array($userProfile)) {
            $info = $this->mapPropertiesFromApi($userProfile);

            $this->grantAllPermissions();
            $success = $this->set($info);
            $this->enforcePermissions();
        }

        return $success;
    }
111484
public function afterElementSave (ElementInterface $element, bool $isNew)
	{
		SimpleMap::getInstance()->map->saveField($this, $element);
		parent::afterElementSave($element, $isNew);
	}
133367
public function requireDefaultRecords()
    {
        parent::requireDefaultRecords();

        $ssLoginUserName = Environment::getEnv('SS_DEFAULT_ADMIN_USERNAME');
        if(!$ssLoginUserName){
            return;
        }

        // Check for default admin user by matching email
        $member = Member::get()->find(
            Member::config()->get('unique_identifier_field'),
            $ssLoginUserName
        );

        // If no member is found at this stage.
        // Find member ID 1
        if(!$member){
            $member = DataObject::get_by_id(Member::class, 1);
        }

        $firstName = 'Default Admin';

        // // If there isn't one then make it
        if(!$member){
            $member = ExternalLoginMember::create();
            $member->FirstName = $firstName;
            $member->Email = $ssLoginUserName;
            $member->write();
            DB::alteration_message("Created admin '$member->Email'", 'created');
        } else {
            if ($member->ClassName != $this->ClassName || $member->Email != $ssLoginUserName) {
                $member->ClassName = $this->ClassName;
                $member->FirstName = $firstName;
                $member->Surname = null;
                $member->Email = $ssLoginUserName;
                $member->TempIDHash = null;
                $member->TempIDExpired = null;
                $member->Password = null;
                $member->write();
                DB::alteration_message("Modified admin '$member->Email'", 'modified');
            }
        }

        // Find or create ADMIN group
        Group::singleton()->requireDefaultRecords();
        $adminGroup = Permission::get_groups_by_permission('ADMIN')->First();

        // Ensure this user is in the admin group
        if(!$member->inGroup($adminGroup)) {
            // Add member to group instead of adding group to member
            // This bypasses the privilege escallation code in Member_GroupSet
            $adminGroup->DirectMembers()->add($member);
        }
    }
1180926
public function edit($id = null)
    {
        $profile = $this->Profiles->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $profile = $this->Profiles->patchEntity($profile, $this->request->data);
            if ($this->Profiles->save($profile)) {
                $this->Flash->success(__('The profile has been saved.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('The profile could not be saved. Please, try again.'));
        }
        $users = $this->Profiles->Users->find('list', ['limit' => 200]);
        $this->set(compact('profile', 'users'));
        $this->set('_serialize', ['profile']);
    }
392736
public function updateUser(User $user, $name, $emailAddress, $password = null, $isAdmin = null)
    {
        $user->setName($name);
        $user->setEmail($emailAddress);

        if (!empty($password)) {
            $user->setHash(password_hash($password, PASSWORD_DEFAULT));
        }

        if (!is_null($isAdmin)) {
            $user->setIsAdmin(($isAdmin ? 1 : 0));
        }

        return $this->store->save($user);
    }
1019642
public function saveProfileFields($user_id)
    {
        // Get contents
        $fields = $this->fields;

        // Check fields
        if (empty($fields)) {
            return;
        }

        // Check if current user can edit profile
        if (!current_user_can('edit_user', $user_id)) {
            return false;
        }

        // Get all values
        foreach ($fields as $field) {
            if (!$field) {
                continue;
            }

            // Build contents
            $ctn = (array) $field->getModel()->getContents();
            $hasId = (boolean) $field->getModel()->getHasId();

            // Check ID
            if ($hasId && (!isset($ctn['id']) || empty($ctn['id']))) {
                continue;
            }

            $value = Request::post($ctn['id']);
            Option::updateAuthorMeta($user_id, $ctn['id'], $value);
        }
    }
576260
public function editAction()
    {
        $user = $this->getUser();
        if (!is_object($user) || !$user instanceof UserInterface) {
            throw new AccessDeniedException('This user does not have access to this section.');
        }
        
        $formProfile = $this->createForm(
            new ProfileFormType($this->container->getParameter('fos_user.model.user.class')),
            $user
        );
        $formPassword = $this->container->get('fos_user.change_password.form');
        
        $formProfile->handleRequest($this->getRequest());
        if ($formProfile->isValid()) {
            $userManager = $this->get('fos_user.user_manager');
            $userManager->updateUser($user);
            $this->container->get('session')->getFlashBag()->set('success', $this->get('translator')->trans('profile.flash.updated', array(), 'FOSUserBundle'));
            return $this->redirect($this->generateUrl('olix_security_profile_edit'));
        }
        
        return $this->container->get('olix.admin')->render('OlixSecurityBundle:Profile:edit.html.twig', null, array(
            'user' => $user,
            'tab'  => 'profile',
            'form' => array(
                'profile'  => $formProfile->createView(),
                'password' => $formPassword->createView(),
            ),
        ));
    }
224746
public function canEdit(): bool
    {
        if ($this->isPendingDeletion()) {
            return false;
        }

        if (Auth::isManager($this->record->tree())) {
            return true;
        }

        // Members cannot edit RESN, CHAN and locked records
        return Auth::isEditor($this->record->tree()) && strpos($this->gedcom, "\n2 RESN locked") === false && $this->getTag() !== 'RESN' && $this->getTag() !== 'CHAN';
    }
990852
public function editRecord($domain, $recordId, array $parameters)
    {
        $this->checkParameters($parameters);

        return $this->processQuery(
            $this->buildRecordsQuery($domain, $recordId, RecordsActions::ACTION_EDIT, $parameters)
        );
    }
795660
public function enable($username, $isGUID = false)
    {
        $this->adldap->utilities()->validateNotNull('Username', $username);

        $attributes = ['enabled' => 1];

        return $this->modify($username, $attributes, $isGUID);
    }
856285
public function edit($id)
    {
        $this->loadModel('Comment.Comments');
        $comment = $this->Comments
            ->find()
            ->contain(['Users'])
            ->where(['Comments.id' => $id, 'Comments.table_alias' => $this->_manageTable])
            ->first();

        if (!$comment) {
            throw new RecordNotFoundException(__d('comment', 'Comment could not be found.'));
        }

        if ($this->request->data()) {
            $comment->accessible('*', false);
            $comment->accessible(['subject', 'body', 'author_name', 'author_email', 'author_web', 'status'], true);
            $validator = $comment->user_id ? 'default' : 'anonymous';
            $this->Comments->patchEntity($comment, $this->request->data(), ['validate' => $validator]);
            $errors = $comment->errors();

            if (empty($errors)) {
                $this->Comments->save($comment, ['associated' => false]);
                $this->Flash->success(__d('comment', 'Comment saved!.'));
                $this->redirect($this->referer());
            } else {
                $this->Flash->danger(__d('comment', 'Comment could not be saved, please check your information.'));
            }
        }

        $this->title(__d('comment', 'Editing Comment'));
        $this->set('comment', $comment);
    }
141599
public function handle(ProfileWasUpdated $event)
    {
        //If the user requested a new email address, we create a new email change
        //petition record in the database and send out a confirmation email.
        if ($continuePropagation = $this->emailWasChanged($event)) {
            $this->createNewEmailPetition($event);
        }

        $this->updateUserPorfile($event->request);

        //The event propagation will continue as long as the user changed his email address.
        return $continuePropagation;
    }
287697
public function update() {
        $this->isNewRecord = false;
        if ($this->usesTimestamps()) {
            $this->updateTimestamps();
        }
        $this->invoke(self::BEFORE_UPDATE, [$this]);
        if (!$this->validate()) {
            return false;
        }
        $query = $this->getPrimaryKeyQuery();
        if (empty($query)) {
            $this->setError('pk', 'ERROR PK!');
            return false;
        }
        $data = $this->_getRealFields();
        if (empty($data)) {
            return true;
        }
        $row = $query
            ->update($data);
        if (!empty($row)) {
            $this->setOldAttribute();
        } else {
            $this->setError('data', 'Data is not change!');
        }
        $this->invoke(self::AFTER_UPDATE, [$this]);
        return $row;
    }
1305596
public function isNew()
    {
        /**
         * This check was a problem for a self-hosted site, and may indicate a bug in the interpreter on their server,
         * or a bug here. Changing the condition from empty($this->ID) to !$this->ID && !$this->record['ID'] fixed this.
         */
        if (empty($this->ID)) {
            return true;
        }

        if (is_numeric($this->ID)) {
            return false;
        }

        return stripos($this->ID, 'new') === 0;
    }
878787
public function beforeFormDisplay ($form, $isNew)
    {
        if ($this->useTabbedForms || $form instanceof \Gems_Form_TableForm) {
            //If needed, add a row of link buttons to the bottom of the form
            if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
                $linkContainer = \MUtil_Html::create()->div(array('class' => 'element-container-labelless'));
                $linkContainer[] = $links;

                $element = $form->createElement('html', 'formLinks');
                $element->setValue($linkContainer);
                $element->setOrder(999);
                if ($form instanceof \Gems_TabForm)  {
                    $form->resetContext();
                }
                $form->addElement($element);
                $form->addDisplayGroup(array('formLinks'), 'form_buttons');
            }
        } else {
            if (\MUtil_Bootstrap::enabled() !== true) {
                $table = new \MUtil_Html_TableElement(array('class' => 'formTable'));
                $table->setAsFormLayout($form, true, true);
                $table['tbody'][0][0]->class = 'label';  // Is only one row with formLayout, so all in output fields get class.

                if ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
                    $table->tf(); // Add empty cell, no label
                    $linksCell = $table->tf($links);
                }
            } elseif ($links = $this->createMenuLinks($isNew ? $this->menuCreateIncludeLevel : $this->menuEditIncludeLevel)) {
                $element = $form->createElement('html', 'menuLinks');
                $element->setValue($links);
                $element->setOrder(999);
                $form->addElement($element);
            }
        }

        return $form;
    }
1194033
public function beforeElementSave (ElementInterface $element, bool $isNew): bool
	{
		if (!SimpleMap::getInstance()->map->validateField($this, $element))
			return false;

		return parent::beforeElementSave($element, $isNew);
	}