Rename a user.

@param User $user
@param $username
512680
public function rename(User $user, $username)
    {
        $userRole = $this->roleManager->getUserRoleByUser($user);
        if ($userRole) $this->roleManager->renameUserRole($userRole, $user->getUsername());
        $user->setUsername($username);
        $personalWorkspaceName = $this->translator->trans('personal_workspace', array(), 'platform') . $user->getUsername();
        $pws = $user->getPersonalWorkspace();
        if ($pws) $this->workspaceManager->rename($pws, $personalWorkspaceName);
        $this->objectManager->persist($user);
        $this->objectManager->flush();
    }
461019
def rename(name, new_name):
    '''
    
    '''
    current_info = info(name)
    if not current_info:
        raise CommandExecutionError('User \'{0}\' does not exist'.format(name))
    new_info = info(new_name)
    if new_info:
        raise CommandExecutionError(
            'User \'{0}\' already exists'.format(new_name)
        )
    _dscl(
        ['/Users/{0}'.format(name), 'RecordName', name, new_name],
        ctype='change'
    )
    # dscl buffers changes, sleep 1 second before checking if new value
    # matches desired value
    time.sleep(1)
    return info(new_name).get('RecordName') == new_name
991258
protected function removeOwnerFromUsersWorkspaces(User $user)
    {
        /** @var Workspace $workspace */
        foreach ($this->workspaceRepository->findByOwner($user) as $workspace) {
            $workspace->setOwner(null);
            $this->workspaceRepository->update($workspace);
        }
    }
465219
public function deleteUser(User $user)
    {
        $url = self::makeUserUrl($user->tenantId, $user->username);
        $this->service->prepAndSend($url, array(204), 'DELETE', null, false, 'application/json', 'application/json');
	}
1277039
public function setUsername($username)
    {
        if (preg_match(self::PATTERN_MATCH_USERNAME, $username) !== 1) {
            throw new \InvalidArgumentException('"' . $username . '" is not a valid username.', 1184071238);
        }

        $this->username = $username;
    }
1016791
public static function deleteUser($username)
	{
		if ( ! self::userExists( $username ) ) return false;

		$deleted_user = self::$auth['users'][ $username ];
		unset( self::$auth['users'][ $username ] );

		return $deleted_user;
	}
440774
public function update(Request $request, User $user)
    {
        $this->authorize('update', $user);
        $this->validate($request, [
            'name'     => 'required|max:255',
        ]);

        $user->update([
            'name' => $request->name,
        ]);

        return redirect()->route('laralum::users.index');
    }
542173
public function deleteUser($username) {
    $users = \Drupal::entityQuery('user')
      ->condition("name", $username)
      ->execute();

    /** @var \Drupal\user\Entity\User $users */
    $users = User::loadMultiple($users);
    foreach ($users as $user) {
      $user->delete();
    }
  }
460664
public function deleteUser(User $user)
    {
        foreach ($user->getAccounts() as $account) {
            $this->securityContext->withoutAuthorizationChecks(function () use ($account) {
                $this->deletePersonalWorkspace($account->getAccountIdentifier());
            });

            $this->accountRepository->remove($account);
        }

        $this->removeOwnerFromUsersWorkspaces($user);

        $this->partyRepository->remove($user);
        $this->emitUserDeleted($user);
    }
1061449
public function setNewActiveContributionToSection(User $user = null)
    {
        $oldActiveContribution = $this->getActiveContribution();
        $newActiveContribution = new Contribution();
        $newActiveContribution->setSection($this);
        if (null === $oldActiveContribution) {
            if (null === $user) {
                $user = $this->getAuthor();
            }
        } else {
            if (null === $user) {
                $user = $oldActiveContribution->getContributor();
            }
            if (null === $user) {
                $user = $this->getAuthor();
            }
            $newActiveContribution->setTitle($oldActiveContribution->getTitle());
            $newActiveContribution->setText($oldActiveContribution->getText());
        }
        $newActiveContribution->setContributor($user);
        $this->setActiveContribution($newActiveContribution);
    }
1123982
public function setUsername($username)
    {
        if (mb_strlen($username) == 0) {
            $this->throwError('Username not set');
        }

        $this->username = $username;

        return $this;
    }
1363956
public function edit_load_user_data($user) {
        if ($this->data !== null) {
            $this->data = clean_text($this->data, $this->dataformat);
            $user->{$this->inputname} = array('text' => $this->data, 'format' => $this->dataformat);
        }
    }
834976
public function update($user, User $userToManage)
    {
        if ($userToManage->id == $user->id || $userToManage->superAdmin()) {
            return false;
        }

        $user = User::findOrFail($user->id);

        return $user->hasPermission('laralum::users.update') || $user->superAdmin();
    }
637496
public function deactivateUser(User $user)
    {
        /** @var Account $account */
        foreach ($user->getAccounts() as $account) {
            $account->setExpirationDate($this->now);
            $this->accountRepository->update($account);
        }
        $this->emitUserDeactivated($user);
    }
1245226
public function deleteUser(User $user)
    {

        /* When the api will identify a user, please uncomment this
        if ($this->container->get('security.token_storage')->getToken()->getUser()->getId() === $user->getId()) {
            throw new \Exception('A user cannot delete himself');
        }*/
        $userRole = $this->roleManager->getUserRoleByUser($user);

        //soft delete~
        $user->setMail('mail#' . $user->getId());
        $user->setFirstName('firstname#' . $user->getId());
        $user->setLastName('lastname#' . $user->getId());
        $user->setPlainPassword(uniqid());
        $user->setUsername('username#' . $user->getId());
        $user->setPublicUrl('removed#' . $user->getId());
        $user->setAdministrativeCode('code#' . $user->getId());
        $user->setIsEnabled(false);

        // keeping the user's workspace with its original code
        // would prevent creating a user with the same username
        // todo: workspace deletion should be an option
        $ws = $user->getPersonalWorkspace();

        if ($ws) {
            $ws->setCode($ws->getCode() . '#deleted_user#' . $user->getId());
            $ws->setDisplayable(false);
            $this->objectManager->persist($ws);
        }

        if ($userRole) {
            $this->objectManager->remove($userRole);
        }
        $this->objectManager->persist($user);
        $this->objectManager->flush();

        $this->strictEventDispatcher->dispatch('claroline_users_delete', 'GenericDatas', array(array($user)));
        $this->strictEventDispatcher->dispatch('log', 'Log\LogUserDelete', array($user));
        $this->strictEventDispatcher->dispatch('delete_user', 'DeleteUser', array($user));
    }
801512
public function edit(string $username, string $email) : void
    {
        $this->username = $username;
        $this->email    = $email;
    }
1153624
public function update(UserRequest $request, User $user)
    {
        $user->update($request->all());
        $this->_syncUserGroups($user, $request->get('user_group_id'));
        return redirect()->route('admin.user.index');
    }