Clean the user data.

@param stdClass|array $user the user data to be validated against properties definition.
@return stdClass $user the cleaned user data.
2115
public static function clean_data($user) {
        if (empty($user)) {
            return $user;
        }

        foreach ($user as $field => $value) {
            // Get the property parameter type and do the cleaning.
            try {
                $user->$field = core_user::clean_field($value, $field);
            } catch (coding_exception $e) {
                debugging("The property '$field' could not be cleaned.", DEBUG_DEVELOPER);
            }
        }

        return $user;
    }
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);
    }
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));
    }
851861
public function setUserData(User $user)
    {
        $userVarArray = get_object_vars($user);

        foreach ($userVarArray as $key => $value) {
            if ($value !== null) {
                $this->{$key} = $value;
            }
        }
    }
965086
public function deserializeFromString($user)
    {
        $base64EncodedUserValues = json_decode(base64_decode($user), true);
        if (!is_array($base64EncodedUserValues)) {
            return null;
        }

        if (empty($base64EncodedUserValues)) {
            return null;
        }

        $expectedKeys = [
            self::SERIALIZED_USER_USERNAME_KEY,
            self::SERIALIZED_USER_PASSWORD_KEY,
            self::SERIALIZED_USER_KEY_KEY,
        ];

        foreach ($expectedKeys as $expectedKey) {
            if (!isset($base64EncodedUserValues[$expectedKey])) {
                return null;
            }
        }

        $userValues = [];

        foreach ($base64EncodedUserValues as $key => $value) {
            $base64DecodedValue = base64_decode($value);
            if ($base64DecodedValue == '') {
                return null;
            }

            $userValues[$key] = $base64DecodedValue;
        }

        return $this->deserialize($userValues);
    }
249054
private function cleanUserSessions(User $user)
    {
        $sessions = $this->objectManager->getRepository('Phraseanet:Session')
            ->findByUser(['user' => $user]);

        foreach ($sessions as $session) {
            $this->objectManager->remove($session);
        }
    }
843976
public function prune($user = null)
    {
        if ($user) {
            $this->addUsingAlias(UserPeer::ID, $user->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }
73800
public function setUser(array $user)
    {
        if (in_array('user', $this->persistantMap)) {
            $this->store->set('user', $user);
        }

        $this->user = $user;
        return $this;
    }
382642
private function cleanSettings(User $user)
    {
        foreach ($user->getNotificationSettings() as $userNotificationSetting) {
            $this->objectManager->remove($userNotificationSetting);
        }

        $user->getNotificationSettings()->clear();

        foreach ($user->getSettings() as $userSetting) {
            $this->objectManager->remove($userSetting);
        }

        $user->getSettings()->clear();
    }
701028
public function removeUser(User $user)
    {
        if ($this->users->contains($user)) {
            $this->users->removeElement($user);
        }

        return $this;
    }
894260
public function actionDeregister($user)
    {
        $user = $this->getUser($user);
        if ($user->deregister()) {
            echo "User (" . $user->getID() . ") Deregistered.\n";
            return static::EXIT_CODE_NORMAL;
        }
        return static::EXIT_CODE_ERROR;
    }
810506
public function deleteUser($user) {
        global $DB;

        $DB->delete_records($this->userresulttable, ['id' => $user->getRecordId()]);
        $user->initialize();

        return true;
    }
1186197
public function forUser($user)
    {
        $callback = function () use ($user)
        {
            return $user;
        };

        return new static(
            $this->container, $callback, $this->abilities,
            $this->policies, $this->beforeCallbacks, $this->afterCallbacks
        );
    }
487675
protected function mapUserToObject(array $user)
    {
        if ($this->detailed) {
            return new User([
                'id' => $this->arrayItem($user, 'userid'),
                'name' => $this->arrayItem($user, 'name'),
                'avatar' => $this->arrayItem($user, 'avatar'),
                'email' => $this->arrayItem($user, 'email'),
            ]);
        }

        return new User(array_filter([
            'id' => $this->arrayItem($user, 'UserId') ?: $this->arrayItem($user, 'OpenId'),
            'userId' => $this->arrayItem($user, 'UserId'),
            'openid' => $this->arrayItem($user, 'OpenId'),
            'deviceId' => $this->arrayItem($user, 'DeviceId'),
        ]));
    }
4506
private function convertUser(array $user) : UserInterface
    {
        $baseUser   = new BaseUser();
        $baseUser->setLoginName($user['login_name']);
        $baseUser->setLoginPassword($user['login_password']);
        $baseUser->setRoles($user['roles']);
        return $baseUser;
    }
1283082
private function cleanRights(User $user)
    {
        foreach ([
            'DELETE FROM `basusr` WHERE usr_id = :usr_id',
            'DELETE FROM `sbasusr` WHERE usr_id = :usr_id',
        ] as $sql) {
            $stmt = $this->appboxConnection->prepare($sql);
            $stmt->execute([':usr_id' => $user->getId()]);
            $stmt->closeCursor();
        }
    }
181577
public function removeUser(ChildUser $user)
    {
        if ($this->getUsers()->contains($user)) { $userRole = new ChildUserRole();

            $userRole->setUser($user);
            if ($user->isRolesLoaded()) {
                //remove the back reference if available
                $user->getRoles()->removeObject($this);
            }

            $userRole->setRole($this);
            $this->removeUserRole(clone $userRole);
            $userRole->clear();

            $this->collUsers->remove($this->collUsers->search($user));

            if (null === $this->usersScheduledForDeletion) {
                $this->usersScheduledForDeletion = clone $this->collUsers;
                $this->usersScheduledForDeletion->clear();
            }

            $this->usersScheduledForDeletion->push($user);
        }


        return $this;
    }