@param User $user

@throws ORMInvalidArgumentException
@throws OptimisticLockException
@throws \InvalidArgumentException
@throws ORMException
196368
public function requestNewPassword(User $user)
    {
        $user->setPasswordRequestedAt(new \DateTime());
        $user->resetAuthenticationToken();
        $user->setEmailSent(false);
        $this->save($user);
    }
324198
public function verifyResumeAuthorization(DeliveryExecutionInterface $deliveryExecution, User $user)
    {
        foreach ($this->getProviders() as $provider) {
            $provider->verifyResumeAuthorization($deliveryExecution, $user);
        }
        $this->getServiceManager()->get(EventManager::SERVICE_ID)->trigger(new DeliveryExecutionVerified($deliveryExecution));
    }
970543
protected function readValue(User $user, string $attribute) : void
    {
        $user->$attribute = $this->prompt(mb_convert_case($attribute, MB_CASE_TITLE, 'utf-8') . ':', [
            'validator' => function ($input, &$error) use ($user, $attribute) {
                $user->$attribute = $input;
                if ($user->validate([$attribute])) {
                    return true;
                } else {
                    $error = implode(',', $user->getErrors($attribute));
                    return false;
                }
            },
        ]);
    }
534118
public function write($user)
    {
        $this->_user = $user;

        $this->_session->renew();
        $this->_session->write($this->_config['key'], $user);
    }
328842
private function setUser($user)
    {
        if ($user instanceof UserPerson) {
            $this->userPerson = $user;
        } elseif ($user instanceof UserCompany) {
            $this->userCompany = $user;
        } elseif ($user instanceof UserApiKey) {
            $this->userApiKey = $user;
        } else {
            throw new BunqException(vsprintf(self::ERROR_UNEXPECTED_USER_INSTANCE, [get_class($user)]));
        }
    }
1332400
public function login(User $user)
    {
        // if not impersonated, save current logged in user
        // otherwise do not update (leave first original user in session)
        if (!$this->isActive()) {
            session()->put($this->originalUserKey, auth()->user()->id);
        }

        auth()->loginUsingId($user->id);

        session()->put($this->isActiveKey, true);
    }
1077062
public function grantTo($user): void
    {
        $userModel = config('auth.providers.users.model');

        if (is_int($user) && !$userModel::find($user)) {
            return;
        }

        $this->users()->attach($user);
    }
1165106
public function save(User $user) : bool
    {
        if (!$user->save()) {
            throw new \RuntimeException($this->i18n->t('setrun/user', 'Saving error'));
        }
        return true;
    }
249054
private function cleanUserSessions(User $user)
    {
        $sessions = $this->objectManager->getRepository('Phraseanet:Session')
            ->findByUser(['user' => $user]);

        foreach ($sessions as $session) {
            $this->objectManager->remove($session);
        }
    }
467138
public function persist($user): void
    {
        $this->om->persist($user);
        $this->om->flush();
    }
1260098
public function changePassword(User $user)
    {
        if ($user->isGuest()) {
            Throw new UserException('Cannot change password of a guest.');
        }

        if (empty($user->getPassword())) {
            Throw new UserException('Cannot change an empty password');
        }

        $hashgen = new HashGenerator($user->getPassword());
        $hashgen->setSalt($this->salt);
        $password = $hashgen->generate();

        // Check the old password
        $this->db->qb([
            'table' => $this->table,
            'method' => 'UPDATE',
            'fields' => 'password',
            'filter' => 'id_user=:id_user',
            'params' => [
                ':id_user' => $user->getId(),
                ':password' => $password
            ]
        ], true);

        $user->setPassword($password);
    }
1290913
public function updateUser(User $user)
    {
        $query = $this->handler->createUpdateQuery();
        $query
            ->update($this->handler->quoteTable('ezuser'))
            ->set(
                $this->handler->quoteColumn('login'),
                $query->bindValue($user->login)
            )->set(
                $this->handler->quoteColumn('email'),
                $query->bindValue($user->email)
            )->set(
                $this->handler->quoteColumn('password_hash'),
                $query->bindValue($user->passwordHash)
            )->set(
                $this->handler->quoteColumn('password_hash_type'),
                $query->bindValue($user->hashAlgorithm)
            )->where(
                $query->expr->eq(
                    $this->handler->quoteColumn('contentobject_id'),
                    $query->bindValue($user->id, null, \PDO::PARAM_INT)
                )
            );
        $query->prepare()->execute();

        $query = $this->handler->createUpdateQuery();
        $query
            ->update($this->handler->quoteTable('ezuser_setting'))
            ->set(
                $this->handler->quoteColumn('is_enabled'),
                $query->bindValue($user->isEnabled, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('max_login'),
                $query->bindValue($user->maxLogin, null, \PDO::PARAM_INT)
            )->where(
                $query->expr->eq(
                    $this->handler->quoteColumn('user_id'),
                    $query->bindValue($user->id, null, \PDO::PARAM_INT)
                )
            );
        $query->prepare()->execute();
    }
286279
public function updateRememberToken(UserInterface $user, $token)
    {
        $user->setRememberToken($token);
        $this->entityManager->persist($user);
        $this->entityManager->flush();
    }
937325
public function blockUser(UserInterface $user, $expire, $reason, $creator = null)
    {
        $class = $this->entityOptions->getUserBlock();
        /** @var UserBlockEntity $userBlock */
        $userBlock = new $class;
        $userBlock->setUser($user);
        $userBlock->setCreator($creator);
        $userBlock->setReason($reason);
        $userBlock->setExpire($expire);

        $this->blockUserWithEntity($userBlock);
    }
325806
public function setPlatformRoles(User $user, $roles)
    {
        $this->roleManager->resetRoles($user);
        $this->roleManager->associateRoles($user, $roles);
    }
54873
public function isMember(User $user)
	{
		if(!$this->isPersisted)
		{
			throw new LogicException('You can only check if a user is a member of a group that exist in the database.');
		}

		if(!$user->isPersisted())
		{
			throw new LogicException('You can only check if a user that exist in the database is a member of a group.');
		}

		return $this->users()->where($user->getPrimaryKey(), '=', $user->getPrimaryKeyValue())->count() > 0;
	}
1135462
public function update(User $user, User $entity)
    {
        if ($entity->id === $user->id) {
            return true;
        }
        return $user->hasPermission('user-update');
    }