aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Roles/Abuser.pm
blob: 7510e6bc2a9f564345eb9ed2dd230f8b73855b46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package FixMyStreet::Roles::Abuser;

use Moo::Role;

=head2 is_from_abuser

    $bool = $alert->is_from_abuser(  );

Returns true if the user's email or its domain is listed in the 'abuse' table.

=cut

sub is_from_abuser {
    my $self = shift;

    my $email = $self->user->email;
    my $domain;
    ($domain) = $email =~ m{ @ (.*) \z }x if $email;
    my $phone = $self->user->phone;

    # search for an entry in the abuse table
    my $abuse_rs = $self->result_source->schema->resultset('Abuse');

    return
         $abuse_rs->find( { email => $email } )
      || $abuse_rs->find( { email => $domain } )
      || $abuse_rs->find( { email => $phone } )
      || undef;
}

1;