Checks if administration code is unique.

@param User       $user
@param Constraint $constraint
172916
public function validate($user, Constraint $constraint)
    {
        $code = $user->getAdministrativeCode();
        if (!empty($code) && $this->platformConfigHandler->getParameter('is_user_admin_code_unique')) {
            $tmpUser = $this->om->getRepository('ClarolineCoreBundle:User')->findOneByAdministrativeCode($code);
            if ($tmpUser && $tmpUser->getUsername() !== $user->getUsername()) {
                $this->context->addViolationAt(
                    'administrativeCode',
                    $this->translator->trans($constraint->error, ['%code%' => $code], 'platform')
                );
            }
        }
    }
1183860
protected function isUsernameInUse($username, User $user)
    {
        return ($this->userManager->hasUserForUsername($username) && $this->userManager->getUserForUsername($username)->getUuid() != $user->getUuid());
    }
847373
public void addUniqueConstraint(UniqueConstraint uc) {
		if (uc.isPrimaryKey()) {
			if (pk != null)
				throw new IllegalArgumentException("Duplicate PK " + pk + " " + uc);
			pk = uc;
		}
		else {
			if (pk != null)
				if (uc.getAttributes().equals(pk.getAttributes()))
					// ignore the unique index created for the primary key
					return;
		}
		ucs.add(uc);
	}
924979
public function validate($value, Constraint $constraint)
    {
        $value = trim($value);

        parent::validate($value, $constraint);
    }
1283439
public function hasPrivileges(User $user, array $required) {
        foreach ($required as $resourceId=>$right) {
            if ($right === 'WRITE' && !$this->hasWritePrivilege($user, $resourceId)) {
                common_Logger::d('User \''.$user->getIdentifier().'\' does not have lock for resource \''.$resourceId.'\'');
                return false;
            }
            if (!in_array($right, $this->getPermissionProvider()->getSupportedRights())) {
                $required[$resourceId] = PermissionInterface::RIGHT_UNSUPPORTED;
            }
        }
        
        $permissions = $this->getPermissionProvider()->getPermissions($user, array_keys($required));
        foreach ($required as $id => $right) {
            if (!isset($permissions[$id]) || !in_array($right, $permissions[$id])) {
                common_Logger::d('User \''.$user->getIdentifier().'\' does not have \''.$right.'\' permission for resource \''.$id.'\'');
                return false;
            }
        }
        return true;
    }
1135462
public function update(User $user, User $entity)
    {
        if ($entity->id === $user->id) {
            return true;
        }
        return $user->hasPermission('user-update');
    }
79959
public function validate($value, Constraint $constraint)
    {
        /**@var $constraint CodeUnit */
        if (!in_array($value, $this->codes)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $value)
                ->addViolation();
        }
    }
645319
public function isUniqueKey(Fluent $constraint)
    {
        foreach ($this->unique as $index) {

            // We only need to consider cases, when UNIQUE KEY is presented by only ONE column
            if (count($index->columns) === 1 && isset($index->columns[0])) {
                if (in_array($index->columns[0], $constraint->columns)) {
                    return true;
                }
            }
        }

        return false;
    }
541110
private function isSecureExpired(User $user)
    {
        // never expired
        if (!$this->expirationPeriod) {
            return false;
        }

        if (!$lastLogin = $user->getLineLastLogin()) {
            return true;
        }

        return (new \DateTime('-'.$this->expirationPeriod)) > $lastLogin;
    }
111986
private function validatePermissions(
        Sharing $constraint,
        SharingIdentityConfigInterface $config,
        Collection $permissions
    ): void {
        if ($permissions->count() > 0 && !$config->isPermissible()) {
            $this->context->buildViolation($constraint->identityNotPermissibleMessage)
                ->atPath($constraint->permissions)
                ->setParameter('%class_property%', $constraint->identityClass)
                ->setParameter('%class%', $config->getType())
                ->addViolation()
            ;
        }
    }
1181406
public function updateAction(User $user)
    {
        $this->userService->updateUser($user);
        $this->addFlashMessage('Your user has been updated.', 'User updated', Message::SEVERITY_OK);
        $this->redirect('edit');
    }
383952
public function validate ($entity, Constraint $constraint)
    {
        if (!$entity instanceof ClientBillingAddressInterface) {
            throw new \InvalidArgumentException('Expected instance of ClientBillingAddressInterface');
        }
        
        if (false === $entity->isCompanyAddress()) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            
            if (false === $this->isValidCompanyName($entity)) {
                $this->context->buildViolation('client.company_name_not_valid')->atPath('companyName')->addViolation();
            }
            
            if (false === $this->isValidVatId($entity)) {
                $this->context->buildViolation('client.vatid_not_valid')->atPath('vatId')->addViolation();
            }
        }
    }
334002
protected function CanEdit(User $user)
    {
        return self::Guard()->Allow(BackendAction::Edit(), $user)&&
            self::Guard()->Allow(BackendAction::UseIt(), new UserForm());
    }
974505
public function verify(User $user, $byAdmin = false)
    {
        return $this->save($user->verify($byAdmin));
    }
574919
public function visitUniqueItemsConstraint(ArrayValue\UniqueItemsConstraint $constraint)
    {
        $value = $this->currentValue();
        if (
            !$value instanceof Value\ArrayValue ||
            !$constraint->value() ||
            $this->comparator->equals(
                $value->value(),
                $this->unique($value->value())
            )
        ) {
            return $this->createResult();
        }

        return $this->createSingleIssueResult($constraint);
    }
590359
private function userAttemptBruteForceLock(User $user)
    {
        if ($this->userAttemptBruteForceLockHasExceeded($user)) {
            return true;
        }
        
        $this->attempts = $user->login_attempt + 1;
        
        if ($this->attempts >= $this->allowedAttempts) {
            $user->updateAttributes(['login_attempt_lock_expiration' => time() + $this->lockoutTime]);
        }
        
        $user->updateAttributes(['login_attempt' => $this->attempts]);
    }
716331
public function validate($entity, Constraint $constraint)
    {
        if (!$entity instanceof ClientDetails) {
            throw new \InvalidArgumentException('Expected instance of ClientDetails');
        }
        
        $username = $entity->getUsername();
        $result   = $this->clientRepository->findOneBy(['clientDetails.username' => $username]);
        
        if (null === $result) {
            return;
        }
        
        if ($this->context instanceof ExecutionContextInterface) {
            $this->context
                ->buildViolation($constraint->message)
                ->setParameter('{{ url }}', $this->routerHelper->generateUrl('front.client.login'))
                ->atPath('username')
                ->setInvalidValue($username)
                ->addViolation();
        }
    }