]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1061271: Add a hook into Bugzilla::User::check_and_send_account_creation_confirma...
authorFrédéric Buclin <LpSolit@gmail.com>
Thu, 26 Feb 2015 14:27:30 +0000 (15:27 +0100)
committerFrédéric Buclin <LpSolit@gmail.com>
Thu, 26 Feb 2015 14:27:30 +0000 (15:27 +0100)
r=gerv a=glob

Bugzilla/Hook.pm
Bugzilla/User.pm
extensions/Example/Extension.pm

index 5abaabc7c2b27da41f717bbe07f3b1bd7b797332..f711907d13f69ff21e15289f43f516ee2c9a50eb 100644 (file)
@@ -1592,6 +1592,24 @@ name), you can get it from here.
 
 =back
 
+=head2 user_check_account_creation
+
+This hook permits you to do extra checks before the creation of a new user
+account. This hook is called after email address validation has been done.
+Note that this hook can also access the IP address of the requester thanks
+to the C<remote_ip()> subroutine exported by C<Bugzilla::Util>.
+
+Params:
+
+=over
+
+=item C<login>
+
+The login of the new account. This is usually an email address, unless the
+C<emailsuffix> parameter is not empty.
+
+=back
+
 =head2 user_preferences
 
 This hook allows you to add additional panels to the User Preferences page,
index fa26743661829c0d46c725dd855d28dccd7ddd1f..b28d0932365d0d9890fdfe9991547cddfb0c8fe2 100644 (file)
@@ -21,6 +21,7 @@ use Bugzilla::Classification;
 use Bugzilla::Field;
 use Bugzilla::Group;
 use Bugzilla::BugUserLastVisit;
+use Bugzilla::Hook;
 
 use DateTime::TimeZone;
 use List::Util qw(max);
@@ -2417,6 +2418,9 @@ sub check_and_send_account_creation_confirmation {
         ThrowUserError('account_creation_restricted');
     }
 
+    # Allow extensions to do extra checks.
+    Bugzilla::Hook::process('user_check_account_creation', { login => $login });
+
     # Create and send a token for this new account.
     require Bugzilla::Token;
     Bugzilla::Token::issue_new_user_account_token($login);
index 0ab5220a77e983dd316cd7b10788b91bb91f9bd8..a866e85e6a437a97b94c67fd72fc8c2a77cdb990 100644 (file)
@@ -18,7 +18,7 @@ use Bugzilla::Error;
 use Bugzilla::Group;
 use Bugzilla::User;
 use Bugzilla::User::Setting;
-use Bugzilla::Util qw(diff_arrays html_quote);
+use Bugzilla::Util qw(diff_arrays html_quote remote_ip);
 use Bugzilla::Status qw(is_open_state);
 use Bugzilla::Install::Filesystem;
 use Bugzilla::WebService::Constants;
@@ -953,6 +953,26 @@ sub template_before_process {
     }
 }
 
+sub user_check_account_creation {
+    my ($self, $args) = @_;
+
+    my $login = $args->{login};
+    my $ip = remote_ip();
+
+    # Log all requests.
+    warn "USER ACCOUNT CREATION REQUEST FOR $login ($ip)";
+
+    # Reject requests based on their email address.
+    if ($login =~ /\@evil\.com$/) {
+        ThrowUserError('account_creation_restricted');
+    }
+
+    # Reject requests based on their IP address.
+    if ($ip =~ /^192\.168\./) {
+        ThrowUserError('account_creation_restricted');
+    }
+}
+
 sub user_preferences {
     my ($self, $args) = @_;
     my $tab = $args->{current_tab};