From cc1006b77c6dfdc53266e0bfc73fc9daf304f8e7 Mon Sep 17 00:00:00 2001 From: Andrew Bogott Date: Sat, 9 Nov 2013 20:21:02 +0000 Subject: [PATCH] Add a hook to validate account creation fields. This is a step on the way to fixing bug 56847. Change-Id: Id330a8ac041ddea086f192a90ddc962077453333 --- docs/hooks.txt | 4 ++++ includes/specials/SpecialUserlogin.php | 10 ++++++++++ languages/messages/MessagesEn.php | 1 + 3 files changed, 15 insertions(+) diff --git a/docs/hooks.txt b/docs/hooks.txt index 7bd725a8a4..700f765062 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -295,6 +295,10 @@ $article: Article object $user: the User object that was created. (Parameter added in 1.7) $byEmail: true when account was created "by email" (added in 1.12) +'ValidateNewUser': Before user account is created, check account settings +$user: the User object to be created. +$&error: Error message, if any, returned by failed validation + 'AfterFinalPageOutput': At the end of OutputPage::output() but before final ob_end_flush() which will send the buffered output to the client. This allows for last-minute modification of the output within the buffer by using diff --git a/includes/specials/SpecialUserlogin.php b/includes/specials/SpecialUserlogin.php index f40966c2cc..c8944d262c 100644 --- a/includes/specials/SpecialUserlogin.php +++ b/includes/specials/SpecialUserlogin.php @@ -409,6 +409,16 @@ class LoginForm extends SpecialPage { return Status::newFatal( 'userexists' ); } + $validateError = ''; + // Make sure that our extensions like the input for this user + if ( !wfRunHooks( 'ValidateNewUser', array( $u, &$validateError ) ) ) { + wfDebug( "New user failed hook validation.\n" ); + if ( !$validateError ) { + return Status::newFatal( 'newuserfailedvalidation' ); + } + return Status::newFatal( $validateError ); + } + if ( $this->mCreateaccountMail ) { # do not force a password for account creation by email # set invalid password, it will be replaced later by a random generated password diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 39f0b8a265..5614015175 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1169,6 +1169,7 @@ Use the form below to log in as another user.', 'badretype' => 'The passwords you entered do not match.', 'userexists' => 'Username entered already in use. Please choose a different name.', +'newuserfailedvalidation' => 'Your new account settings are invalid.', 'loginerror' => 'Login error', 'createacct-error' => 'Account creation error', 'createaccounterror' => 'Could not create account: $1', -- 2.20.1