Annelidous-snapshot

 view release on metacpan or  search on metacpan

Annelidous/Search/Ubersmith.pm  view on Meta::CPAN

sub find_byusername {
    my $self=shift;
    my $username=shift;
    return $self->find("and username regexp ?", $username);
}
sub find_active_byusername {
    my $self=shift;
    my $username=shift;
    return $self->find_active("and username regexp ?", $username);
}

sub by_id {
    my $self=shift;
    my $id=shift;
	#print "Hunting for id: ";
	#print Dumper $id."\n";
	# Do not discriminate on active or not.
    return $self->find("and PACKAGES.packid=?", $id);
}

sub by_clientid {
    my $self=shift;
    my $id=shift;
	my $active=shift;
	my $where="and CLIENT.clientid=?";
	if ($active) {
		$where.=" and PACKAGES.active=1";
	}
	# Do not discriminate on active or not.
    return $self->find($where, $id);
}

#
# Fetches clients based on email address
#
sub find_bymail {
    my $self=shift;
    my $email=shift;
    return $self->find ("and email=?", $email);
}

#
# Fetches clients based on their host
#
sub find_byhost {
    my $self=shift;
    my $hostname=shift;
    return $self->find ("and servername=?", $hostname);
}

sub get_default_cluster {
	my $self=shift;
	return Annelidous::Cluster::GrokThis->new($self);
}

# Authentication per-service
# I.E. sub-accounts
sub auth_service {
    my $self=shift;
    my $username=shift;
    my $password=shift;
    my $c=$self->find("and username=? and password=?", $username,$password);

	# Return the single authorized package/service.
	return [$c->{id}];
}

# Authentication per-account
# I.E. master accounts
sub auth_account {
    my $self=shift;
    my $username=shift;
    my $password=shift;
    my @cl=$self->db_fetch("select clientid from CLIENT where clientid=? and password=? limit 1",$username,$password);
	if ($#cl > -1) {
		return $self->authorized_services($cl[0]->{clientid});
	}
	return 0;
}

sub authorized_services {
	my $self=shift;
	my $clientid=shift;
	my @services=();
    # Iterate over the options.
    foreach my $pack ($self->by_clientid($clientid)) {
        # Ignore broken guests
        next if ($pack->{username} =~ /^c?$/ || ! $pack->{ip});

        # Just get the first IP:
        @_=split (/ /, $pack->{ip});
        my $ip=$_[0];

        # Skip any entries that don't have IPs.
        next unless ($ip);
		push @services, $pack->{id};
	}
	# Authorized services by packid.
	return @services;
}


1;



( run in 3.420 seconds using v1.01-cache-2.11-cpan-364913b4093 )