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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package Bugzilla::Extension::NewAcctAntiSpam;
use strict;
use warnings;
use base qw(Bugzilla::Extension);
use DateTime;
use Bugzilla::Error;
use Bugzilla::Util qw(remote_ip datetime_from);
BEGIN {
*Bugzilla::User::acct_created_ts = \&_user_acct_created_ts;
*Bugzilla::User::set_acct_created_ts = \&_user_set_acct_created_ts;
}
sub _user_acct_created_ts { $_[0]->{acct_created_ts} }
sub _user_set_acct_created_ts {
my ($self, $value) = @_;
$self->set('acct_created_ts', $_[1]);
Bugzilla->dbh->do("UPDATE profiles SET acct_created_ts = ? WHERE userid = ?",
undef, $value, $self->id);
Bugzilla->memcached->clear({table => 'profiles', id => $self->id});
}
sub object_end_of_create {
my ($self, $args) = @_;
my $object = $args->{object} or return;
return if exists $args->{changes} && !scalar(keys %{$args->{changes}});
if ($object->isa('Bugzilla::User')) {
my $now = DateTime->now->datetime(' ');
$object->set_acct_created_ts($now);
}
}
sub object_end_of_create_validators {
my ($self, $args) = @_;
if ($args->{class} eq 'Bugzilla::Comment') {
if ($args->{params}->{thetext} =~ /https?:\/\//i) {
my $user = Bugzilla->user;
my $created = $user->acct_created_ts;
if ($created) {
my $dayafter = (datetime_from($created)
+ DateTime::Duration->new(days => 1));
if (DateTime->now < $dayafter) {
ThrowUserError('antispam_comment_blocked');
}
}
}
}
}
sub object_columns {
my ($self, $args) = @_;
my ($class, $columns) = @$args{qw(class columns)};
if ($class->isa('Bugzilla::User')) {
push(@$columns, qw(acct_created_ts));
}
}
sub object_update_columns {
my ($self, $args) = @_;
my ($object, $columns) = @$args{qw(object columns)};
if ($object->isa('Bugzilla::User')) {
push(@$columns, qw(acct_created_ts));
}
}
sub install_update_db {
my $dbh = Bugzilla->dbh;
$dbh->bz_add_column('profiles', 'acct_created_ts', {TYPE => 'DATETIME'});
}
__PACKAGE__->NAME;
|