@param UserInterface $user

@return RoleInterface
761077
public function removeUser(UserInterface $user)
    {
        $this->users->removeElement($user);

        if ($user->hasRole($this) === true)
            $user->removeRole($this);
        
        return $this;
    }
438232
public function getFavouriteAccountsForUser(UserInterface $user)
    {
        $criteria = new Criteria();
        $criteria
            ->where($criteria->expr()->in(
                'id',
                $user->getMyFavouriteAccountIds()
            ))
        ;

        return $this->oh->getOrganization()
            ->getAccounts()
            ->matching($criteria)
        ;
    }
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
        );
    }
495105
public function createUser(UserInterface $user)
    {
        if (isset($this->users[strtolower($user->getUsername())])) {
            throw new \LogicException('Another user with the same username already exists.');
        }

        $this->users[strtolower($user->getUsername())] = $user;
    }
1049924
public function updateUser(User $user)
    {
        try {
            return $this->innerGateway->updateUser($user);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
460604
protected function refreshLanguagesByAliases(UserInterface $user)
    {
        $sites = array();
        $siteIds = array();
        $allSite = $this->get('security.authorization_checker')->isGranted(ContributionRoleInterface::PLATFORM_ADMIN);

        if ($allSite) {
            $sites = $this->container->get('open_orchestra_model.repository.site')->findByDeleted(false);
        } else {
            foreach ($user->getGroups() as $group) {
                /** @var SiteInterface $site */
                $site = $group->getSite();
                if (!$group->isDeleted() && !$site->isDeleted() && !in_array($site->getSiteId(), $siteIds)) {
                    $siteIds[] = $site->getSiteId();
                    $sites[] = $site;
                }
            }
        }

        foreach ($sites as $site) {
            if(!$user->hasLanguageBySite($site->getSiteId())) {
                $user->setLanguageBySite($site->getSiteId(), $site->getDefaultLanguage());
            }
        }

        return $user;
    }
577524
public function persist(UserInterface $user)
    {
        $session = new PersistentSession();
        $session->email = $this->email;
        $session->series = $this->hash($this->series);
        $session->token = $this->hash($this->token);
        $session->user_id = $user->id();
        $session->two_factor_verified = $user->isTwoFactorVerified();

        try {
            $session->save();
        } catch (\Exception $e) {
            throw new \Exception("Unable to save persistent session for user # {$user->id()}: ".$e->getMessage());
        }

        return $session;
    }
936640
public function setRole(UserInterface $user, array $selectedRole)
    {
        $choices = $this->rolesManager->getChoices();

        if (!isset($choices[$selectedRole['roles']])) {
            throw new InvalidArgumentException(
                sprintf('Impossible to set role %s', $selectedRole['roles'])
            );
        }

        $user->setRoles([$choices[$selectedRole['roles']]]);

        $this->entityManager->flush();
    }
1307784
public function setUser(User $user = null): FamilyPermission
    {
        $this->user = $user;
        if ($user && !$user->getFamilyPermissions()->contains($this)) {
            $user->getFamilyPermissions()->add($this);
        }

        return $this;
    }
770916
public function authorize(UserInterface $user, $ip = null)
    {
        return $this->authRoles($user) && $this->authIps($ip);
    }
729722
public function isAdmitted(UserInterface $user = null)
    {
        if (is_null($user)) {
            return !$this->currentUser() instanceof GuestUser;
        }

        return $user->getIdentifier() === $this->currentUser()->getIdentifier();
    }
1069333
public static function create(UserInterface $user): UserMetaInterface
    {
        /** @var AbstractUser $user */
        $user_meta = static::findOne(['user_id' => $user->id]);
        if ($user_meta instanceof UserMetaInterface) {
            return $user_meta;
        }
        $user_meta = new static([
            'user_id' => $user->id,
            'notification_email' => $user->email,
            'display_name' => $user->username,
        ]);
        (new UserMetaHandler($user_meta))->create();
        $user_meta->refresh();
        return $user_meta;
    }
174829
public function getIdentityRoles(UserInterface $user = null)
    {
        if ($user === null) {
            $user = $this->getDefaultIdentity();
            if (!$user) {
                return (array) $this->getModuleOptions()->getDefaultGuestRole();
            }
        }

        $resultSet = $this->getUserRoleLinkerMapper()->findByUser($user);

        if (count($resultSet) > 0) { // if exists in database
            $roles = array();
            foreach ($resultSet  as $userRoleLinker) {
                $roles[] = $userRoleLinker->getRoleId();
            }

            return $roles;
        } else {
            return (array) $this->getModuleOptions()->getDefaultUserRole();
        }

    }
1296413
public function addUser(UserInterface $user)
    {
        $this->users->add($user);

        if ($user->hasRole($this) === false)
            $user->addRole($this);

        return $this;
    }
972986
public function removeRole(RoleInterface $role)
    {
        $this->roles->removeElement($role);

        if ($role->hasUser($this) === true)
            $role->removeUser($this);
        
        return $this;
    }
522222
public function findPlatformRoles(User $user)
    {
        $dql = "
            SELECT r FROM Claroline\CoreBundle\Entity\Role r
            JOIN r.users u
            WHERE u.id = {$user->getId()} AND r.type = ".Role::PLATFORM_ROLE;
        $query = $this->_em->createQuery($dql);

        return $query->getResult();
    }
1270680
private function objectifyRoles(UserInterface $user)
    {
        $roles = [];

        foreach ($user->getRoles() as $role) {
            if (is_string($role)) {
                $role = new Role($role);
            } elseif (!$role instanceof RoleInterface) {
                throw new \InvalidArgumentException(sprintf('User roles must be an array of strings, or RoleInterface instances, but got %s.', gettype($role)));
            }

            $roles[] = $role;
        }

        return $roles;
    }