From 5e6a8fcd0d46945fc537dfcec067219ce901abcf Mon Sep 17 00:00:00 2001 From: "bzrmirror%bugzilla.org" Date: Thu, 26 Feb 2015 14:46:37 +0000 Subject: [PATCH] Bug 1061271: Add a hook into Bugzilla::User::check_and_send_account_creation_confirmation() r=gerv a=glob git-svn-id: svn://10.0.0.236/trunk@265838 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/bugzilla/.bzrrev | 2 +- mozilla/webtools/bugzilla/.gitrev | 2 +- mozilla/webtools/bugzilla/Bugzilla/Hook.pm | 18 +++++++++++++++ mozilla/webtools/bugzilla/Bugzilla/User.pm | 4 ++++ .../bugzilla/extensions/Example/Extension.pm | 22 ++++++++++++++++++- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/mozilla/webtools/bugzilla/.bzrrev b/mozilla/webtools/bugzilla/.bzrrev index a828d11cf57..e514e78babf 100644 --- a/mozilla/webtools/bugzilla/.bzrrev +++ b/mozilla/webtools/bugzilla/.bzrrev @@ -1 +1 @@ -9314 \ No newline at end of file +9315 \ No newline at end of file diff --git a/mozilla/webtools/bugzilla/.gitrev b/mozilla/webtools/bugzilla/.gitrev index 40b82588605..da10edcdc5c 100644 --- a/mozilla/webtools/bugzilla/.gitrev +++ b/mozilla/webtools/bugzilla/.gitrev @@ -1 +1 @@ -0a0c32b2082a0f31757cc09af6d7f2ff9ba45168 \ No newline at end of file +0a8f7a59f894738d86564874fbabeb1c81f3178d \ No newline at end of file diff --git a/mozilla/webtools/bugzilla/Bugzilla/Hook.pm b/mozilla/webtools/bugzilla/Bugzilla/Hook.pm index 5abaabc7c2b..f711907d13f 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/Hook.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/Hook.pm @@ -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 subroutine exported by C. + +Params: + +=over + +=item C + +The login of the new account. This is usually an email address, unless the +C parameter is not empty. + +=back + =head2 user_preferences This hook allows you to add additional panels to the User Preferences page, diff --git a/mozilla/webtools/bugzilla/Bugzilla/User.pm b/mozilla/webtools/bugzilla/Bugzilla/User.pm index fa267436618..b28d0932365 100644 --- a/mozilla/webtools/bugzilla/Bugzilla/User.pm +++ b/mozilla/webtools/bugzilla/Bugzilla/User.pm @@ -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); diff --git a/mozilla/webtools/bugzilla/extensions/Example/Extension.pm b/mozilla/webtools/bugzilla/extensions/Example/Extension.pm index 0ab5220a77e..a866e85e6a4 100644 --- a/mozilla/webtools/bugzilla/extensions/Example/Extension.pm +++ b/mozilla/webtools/bugzilla/extensions/Example/Extension.pm @@ -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};