Skip to content
Snippets Groups Projects
ServiceProvider.pm 1.02 KiB
Newer Older
package IdPAccountManager::ServiceProvider;
Guillaume ROUSSE's avatar
Guillaume ROUSSE committed

use strict;
Guillaume ROUSSE's avatar
Guillaume ROUSSE committed

use base 'IdPAccountManager::DB::Object';

use List::MoreUtils qw(any);

Guillaume ROUSSE's avatar
Guillaume ROUSSE committed
__PACKAGE__->meta->setup(
    table   => 'serviceproviders',

    columns => [
        id          => { type => 'bigserial', not_null => 1 },
        entityid    => { type => 'varchar', length => 200, not_null => 1 },
        displayname => { type => 'varchar', length => 500 },
        contacts    => { type => 'array' },
Guillaume ROUSSE's avatar
Guillaume ROUSSE committed
    ],

    primary_key_columns => [ 'id' ],

    unique_key => [ 'entityid' ],
);

## Print the content of a test account
sub print {
    my ($self, $fd) = @_;
    $fd = \*STDOUT unless $fd;

    printf $fd
      "ServiceProvider ID=%s; entityid=%s; displayname=%s; contacts=%s\n",
Guillaume ROUSSE's avatar
Guillaume ROUSSE committed
      $self->id(),
      $self->entityid(),
      $self->displayname(),
      join(',', $self->contacts());
## Check if email address is a known contact
sub is_contact {
    my ($self, $email) = @_;

    $email = lc($email);

    return any { $email eq lc($_) } $self->contacts();