Checks for duplicate user_to_app_to_role relation.

@param $uar

@return bool
550534
protected function isDuplicateUserAppRole($uar)
    {
        $userId = $uar['user_id'];
        $appId = $uar['app_id'];
        $roleId = $uar['role_id'];

        return UserAppRole::whereRaw(
            "user_id = '$userId' AND 
            role_id = '$roleId' AND 
            app_id = '$appId'"
        )->exists();
    }
293534
public function isExistsAmongTwoUsers($user1, $user2)
    {
        $conversation = Conversation::where(
            function ($query) use ($user1, $user2) {
                $query->where(
                    function ($q) use ($user1, $user2) {
                        $q->where('user_one', $user1)
                            ->where('user_two', $user2);
                    }
                )
                    ->orWhere(
                        function ($q) use ($user1, $user2) {
                            $q->where('user_one', $user2)
                                ->where('user_two', $user1);
                        }
                    );
            }
        );

        if ($conversation->exists()) {
            return $conversation->first()->id;
        }

        return false;
    }
220250
final public function hasRequiredRole(UserInterface $user = null, array $roles = [])
    {
        if ($user != null) {
            // Check if user's roles matches required roles
            $userRoles = $user->getRoles();

            foreach ($userRoles as $role) {
                if (\in_array($role, $roles)) {
                    return true;
                }
            }
        }

        return false;
    }
628136
public function isExistsAmongTwoUsers($user1, $user2)
    {
        $conversation = Conversation::where('user_one', $user1)
            ->where('user_two', $user2);

        if ($conversation->exists()) {
            return $conversation->first()->id;
        }

        return false;
    }
729087
public static function isAppRegistered(?string $app = null): bool
    {
        self::initialize();
        if ($app === null) {
            $app = '*';
        }
        return isset(self::$repositories[$app]);
    }
1309949
public function is($roles)
	{
		if (!$this->user())
		{
			return false;
		}

		$userRoles = $this->getUser()->roles;

		foreach ((array)$roles as $role)
		{
			if (in_array(mb_strtolower($role), $userRoles)
				|| in_array($role, $userRoles)
			)
			{
				return true;
			}
		}

		return false;
	}
188528
public static function userHasRole($role , $username = null)
	{
		if ( is_null( $username ) ) $username = self::getCurrentUsername();
		if ( is_null( $username ) ) return false;
		if ( ! self::userExists( $username ) ) return false;
		if ( in_array( 'admin' , self::$auth['users'][ $username ]['roles'] ) ) return true;
		return ( in_array( $role , self::$auth['users'][ $username ]['roles'] ) );
	}
1258569
private static function userHasResource($resources)
    {
        if (!is_array($resources)) {
            $resources = [$resources];
        }

        $container = Container::getInstance();

        /** @var Rbac $rbac */
        $rbac = $container->get('rbac');

        /** @var Auth $auth */
        $auth = $container->get('auth');

        foreach($resources as $resource){
            foreach ($auth->getStorage()->read()['roles'] as $roleName) {
                if (true === $rbac->isGranted($roleName, $resource)) {
                    return true;
                }
            }
        }

        return false;
    }
925350
public function checkAccess($role){
		if(!\Yii::$app->user->isGuest)
		{
			if(Yii::$app->user->identity->role == self::$roles[$role])
			{
				return true;
			}
		}
		return false;
	}
373202
public function isAuthenticated()
    {
        if (!$this->session->has('usr_id')) {
            return false;
        }

        if ($this->session->has('session_id')) {
            if (null !== $this->app['repo.sessions']->find($this->session->get('session_id'))) {
                return true;
            }
        }

        $this->session->invalidate();
        $this->reinitUser();

        return false;
    }
956769
public function hasUserRoles($roles)
	{
		if ($this->session_machine === null) {
			throw new RuntimeException('Session machine not ready ‒ '.__METHOD__.' called too soon.');
		}

		if (is_array($roles)) {
			return count(array_intersect($this->getUserRoles(), $roles)) > 0;
		} else {
			return in_array($roles, $this->getUserRoles());
		}
	}
918631
protected function authRoles(UserInterface $user)
    {
        if (empty($this->roles)) {
            return true;
        }

        foreach ($this->roles as $role) {
            if ($user->hasRole($role)) {
                return true;
            }
        }

        return false;
    }
1118984
public function addRole($role)
    {
        if ($this->instance instanceof \Phavour\Session\Storage) {
            if ($this->hasRole($role)) {
                return true;
            }
            if ($this->instance->isLocked()) {
                $this->instance->unlock();
            }
            $roles = $this->instance->get('roles');
            if (is_array($roles)) {
                $this->instance->set(
                    'roles', array_merge($roles, array($role)));
            } else {
                $this->instance->set('roles', array($role));
            }
            $this->instance->lock();
            return true;
        }

        return false;
    }
1339795
public function hasRole($role)
    {
        if (is_array($role)) {
            return in_array($this->attributes['role'], $role);
        }

        return $this->attributes['role'] == $role;
    }
641367
public function hasRole($role)
    {
        if (is_string($role)) {
            return $this->roles->contains('name', $role);
        }

        if (is_array($role)) {
            foreach ($role as $r) {
                if ($this->hasRole($r)) {
                    return true;
                }
            }

            return false;
        }

        return !!$role->intersect($this->roles)->count();
    }
39061
public function addRole($role)
    {
        if ($role instanceof Role) {
            $role = $role->id;
        }

        // We don't want a double up on roles
        if (false !== array_search($role, (array) $this->attributes['roles'])) {
            return false;
        }

        $this->attributes['roles'][] = $role;

        return true;
    }
1011569
public function primaryUnique(&$data) {
		if (empty($entity['foreign_id']) || $entity['address_type_id'] != Address::TYPE_MAIN) {
			return true;
		}
		$conditions = ['foreign_id' => $entity['foreign_id'], 'address_type_id' => Address::TYPE_MAIN];
		if (!empty($entity['id'])) {
			$conditions['user_id !='] = $entity['id'];
		}
		if ($this->find('first', ['conditions' => $conditions])) {
			return false;
		}
		return true;
	}