Find a user by one of the fields given as $identity.
If one of the fields in the $identity array matches the user
will be retrieved.
todo interface for identity

@param array $identity An array of attributes and values to search for

@return UserInterface
345208
public function findByIdentity($identity)
    {
        $account = $this->model();

        $account = $account->where(function ($query) use ($identity){

            $firstWhere = true;

            foreach($identity as $attribute => $value){

                if($firstWhere) $query->where($attribute, '=', $value);

                else $query->orWhere($attribute, '=', $value);

                $firstWhere = false;
            }
        });

        $account = $account->get()->first();

        return $account;
    }
1121538
public function find($id)
    {
        return new self($this->_user, self::get($this->_user, $id));
    }
1262702
private function findUser($id)
    {
        if (is_array($id)) {
            /** @var User $user */
            $model = User::findIdentities($id);
        } else {
            /** @var User $user */
            $model = User::findIdentity($id);
        }
        if ($model !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('User not found');
        }
    }
242150
public function findUser ($userId) {
    $query = $this->database->pdo->prepare('SELECT username, points FROM users WHERE userId = :userId');
    $query->bindParam(':userId', $userId);

    $query->execute();
    return (object) $query->fetch(PDO::FETCH_ASSOC);
  }
967282
public function retrieveById($identifier) {
        if (!$this->isValidIdentifierValue($identifier)) {
            return null;
        }
        /** @var RecordInterface $user */
        $user = $this->createEmptyUserRecord()->fromPrimaryKey($identifier, [], $this->getRelationsToFetch());

        return $this->validateUser($user, null);
    }
1356712
public function authenticate(array $credentials): Identity
	{
		list($username, $password) = $credentials;

		$user = $this->orm->users->getByUsername($username);

		if (!$user) {
			throw new AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
		} elseif (!Passwords::verify($password, $user->password)) {
			throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
		} elseif (!$user->active) {
			throw new AuthenticationException('Account is deactivated.', self::NOT_APPROVED);
		} elseif (Passwords::needsRehash($user->password)) {
			$user->setPassword($password);
			$this->orm->persistAndFlush($user);
		}

		return new Identity($user->id);
	}
359099
private function matchRelationship(
        Identity $identity,
        object $entity,
        Relationship $meta,
        MapInterface $changeset,
        Query $query
    ): Query {
        $name = $this->name->sprintf(\md5($identity->value()));
        $this->variables = $this->variables->put(
            $name,
            $this->buildProperties(
                $changeset,
                $meta->properties()
            )
        );

        return $query
            ->match()
            ->linkedTo()
            ->through(
                (string) $meta->type(),
                (string) $name
            )
            ->withProperty(
                $meta->identity()->property(),
                (string) $name
                    ->prepend('{')
                    ->append('_identity}')
            )
            ->withParameter(
                (string) $name->append('_identity'),
                $identity->value()
            );
    }
539711
public function findByIdentifier($identifier): ?User
    {
        return DB::table('user')
            ->where('user_name', '=', $identifier)
            ->orWhere('email', '=', $identifier)
            ->get()
            ->map(User::rowMapper())
            ->first();
    }
464429
public function findById($id)
    {
        try
        {
            return $this->sentry->findUserById($id);
        }
        catch (SentryUserNotFoundException $e)
        {
            throw new UserNotFoundException($e->getMessage());
        }
    }
166404
public function login(array $identity = array())
    {
        if ($this->instance instanceof \Phavour\Session\Storage) {
            if ($this->instance->isLocked()) {
                $this->instance->unlock();
            }
            $this->instance->set('identity', $identity);
            $this->instance->set('roles', array());
            $this->instance->lock();
            return true;
        }

        return false;
    }
117222
public function get(Identity $identity): object
    {
        return $this
            ->states
            ->get($this->stateFor($identity))
            ->get($identity);
    }
88102
private function findObjectIdentityId(ObjectIdentityInterface $objectIdentity)
    {
        if ($this->objectIds->contains($objectIdentity)) {
            return $this->objectIds->offsetGet($objectIdentity);
        }

        $conn = $this->getConnection();

        $qb = $conn->createQueryBuilder();
        $qb
            ->select('id')
            ->from('acl_object_identity')
            ->where($qb->expr()->eq('type', $qb->expr()->literal($objectIdentity->getType())))
            ->andWhere($qb->expr()->eq('identifier', $qb->expr()->literal($objectIdentity->getIdentifier())));

        $id = $qb->execute()->fetchColumn();

        if ($id) {
            $this->objectIds->attach($objectIdentity, $id);
        }

        return $id;
    }
1175787
public function orderBy(IdentityInterface $identity = null)
    {
        if (is_null($this->identity) || !$this->identity->hasOrderBy()) {
            return [];
        }
        $sort = [];
        foreach ($this->identity->getOrderBy() as $key => $value) {
            if (strpos($key, 'random') !== false) {
                $sort["_script"] = [
                    "type"   => "number",
                    "script" => "Math.random()",
                    "order"  => "asc"
                ];
            } elseif ($key === Consts::GEO_DISTANCE_SORT) {
                $sort[$key] = $value;
            } elseif ($key !== null) {
                $sort[$key] = (strtolower($value) == Consts::DESCENDING)
                    ? \G4\DataMapper\Selection\Solr\Consts\Query::DESCENDING
                    : \G4\DataMapper\Selection\Solr\Consts\Query::ASCENDING;
            }
        }
        return $sort;
    }
64933
public static function hostnameAnalyzer($identity)
    {
        $address = $identity->getAddress();
        if (!$address->getHostname()) {
            $hostname = strtolower(gethostbyaddr($address->getValue()));
            if ($hostname && $hostname != $address->getValue()) {
                $address->setHostname($hostname);
                $reverseAddress = gethostbyname($hostname);
                if ($reverseAddress && $reverseAddress == $address->getValue()) {
                    $address->setAttribute('reverse', true);
                } else {
                    $address->setAttribute('reverse', false);
                }
            }
        }
        return $identity;
    }
830223
private function getUserById($id)
    {
        $user = $this->userService->findUserById($id);

        if (empty($user)) {
            throw $this->createNotFoundException('user not found');
        }

        return $user;
    }
738076
public function byIdentity($identity = null)
    {
        if (!$identity) {
            $identity = Yii::$app->user->identity;
        }
        if (method_exists($identity, 'canGetProperty') && !$identity->canGetProperty('guid')) {
            return $this;
        }
        return $this->createdBy($identity->getGUID());
    }
936164
public function setIdentity($identity = null)
    {
        if (null === $identity) {
            // Setting the identity to null resets the code and messages.
            $this->setCode();
            $this->setMessages();
        }
        $this->setParam('identity', $identity);
        return $this;
    }