aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extensions/NewAcctAntiSpam/Config.pm11
-rw-r--r--extensions/NewAcctAntiSpam/Extension.pm78
-rw-r--r--extensions/NewAcctAntiSpam/template/en/default/hook/global/user-error-errors.html.tmpl5
-rw-r--r--template/en/default/account/create.html.tmpl4
4 files changed, 98 insertions, 0 deletions
diff --git a/extensions/NewAcctAntiSpam/Config.pm b/extensions/NewAcctAntiSpam/Config.pm
new file mode 100644
index 000000000..730dadfd8
--- /dev/null
+++ b/extensions/NewAcctAntiSpam/Config.pm
@@ -0,0 +1,11 @@
+package Bugzilla::Extension::NewAcctAntiSpam;
+
+use strict;
+use warnings;
+
+use constant NAME => 'NewAcctAntiSpam';
+use constant REQUIRED_MODULES => [];
+use constant OPTIONAL_MODULES => [];
+
+__PACKAGE__->NAME;
+
diff --git a/extensions/NewAcctAntiSpam/Extension.pm b/extensions/NewAcctAntiSpam/Extension.pm
new file mode 100644
index 000000000..b779269e1
--- /dev/null
+++ b/extensions/NewAcctAntiSpam/Extension.pm
@@ -0,0 +1,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;
diff --git a/extensions/NewAcctAntiSpam/template/en/default/hook/global/user-error-errors.html.tmpl b/extensions/NewAcctAntiSpam/template/en/default/hook/global/user-error-errors.html.tmpl
new file mode 100644
index 000000000..cddf69008
--- /dev/null
+++ b/extensions/NewAcctAntiSpam/template/en/default/hook/global/user-error-errors.html.tmpl
@@ -0,0 +1,5 @@
+[% IF error == "antispam_comment_blocked" %]
+ [% title = "Comment Blocked" %]
+ New accounts are forbidden from posting URLs in bug comments. Please wait
+ at least 24 hours before posting URLs. We are sorry for the inconvenience.
+[% END %]
diff --git a/template/en/default/account/create.html.tmpl b/template/en/default/account/create.html.tmpl
index fe266e7e0..d9a138369 100644
--- a/template/en/default/account/create.html.tmpl
+++ b/template/en/default/account/create.html.tmpl
@@ -65,6 +65,10 @@
<b>Please do not use temporary/throwaway email addresses to register, they cause
too many mail bounces later when developers follow up bugs.</b>
</p>
+<p class="warning">
+To prevent spam, new accounts are forbidden from posting URLs in comments
+for the first 24 hours. We are sorry for the inconvenience.
+</p>
[% END %]
<form id="account_creation_form" method="get" action="createaccount.cgi">