From: Duck Date: Tue, 28 Jul 2009 23:05:29 +0000 (-0600) Subject: Ticket #8258: Catch exists() errors for auth signup X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=676070cae8a2331df6ddd763aa95da2966c1b640;p=horde.git Ticket #8258: Catch exists() errors for auth signup Signed-off-by: Michael M Slusarz --- diff --git a/framework/Auth/lib/Horde/Auth/Signup.php b/framework/Auth/lib/Horde/Auth/Signup.php index cdb873cc2..1031abe34 100644 --- a/framework/Auth/lib/Horde/Auth/Signup.php +++ b/framework/Auth/lib/Horde/Auth/Signup.php @@ -58,39 +58,33 @@ class Horde_Auth_Signup * Adds a new user to the system and handles any extra fields that may have * been compiled, relying on the hooks.php file. * - * @params mixed $info Reference to array of parameteres to be passed + * @params mixed $info Reference to array of parameters to be passed * to hook. * * @throws Horde_Exception */ - public function addSignup($info) + public function addSignup(&$info) { global $auth; // Perform any preprocessing if requested. - try { - $info = Horde::callHook('signup_preprocess', array($info)); - } catch (Horde_Exception_HookNotSet $e) {} - - // Check to see if the username already exists. - if ($auth->exists($info['user_name']) || - $this->exists($info['user_name'])) { - throw new Horde_Exception(sprintf(_("Username \"%s\" already exists."), $info['user_name'])); - } + $this->_preSignup($info); // Attempt to add the user to the system. $auth->addUser($info['user_name'], array('password' => $info['password'])); // Attempt to add/update any extra data handed in. if (!empty($info['extra'])) { - Horde::callHook('signup_addextra', array($info['user_name'], $info['extra'])); - } catch (Horde_Exception_HookNotSet $e) {} + try { + Horde::callHook('signup_addextra', array($info['user_name'], $info['extra'])); + } catch (Horde_Exception_HookNotSet $e) {} + } } /** * Queues the user's submitted registration info for later admin approval. * - * @params mixed $info Reference to array of parameteres to be passed + * @params mixed $info Reference to array of parameters to be passed * to hook * * @throws Horde_Exception @@ -98,18 +92,10 @@ class Horde_Auth_Signup */ public function queueSignup(&$info) { - global $auth, $conf; + global $conf; // Perform any preprocessing if requested. - try { - $info = Horde::callHook('signup_preprocess', array($info)); - } catch (Horde_Exception_HookNotSet $e) {} - - // Check to see if the username already exists. - if ($auth->exists($info['user_name']) || - $this->exists($info['user_name'])) { - throw new Horde_Exception(sprintf(_("Username \"%s\" already exists."), $info['user_name'])); - } + $this->_preSignup($info); // If it's a unique username, go ahead and queue the request. $signup = $this->newSignup($info['user_name']); @@ -153,9 +139,35 @@ class Horde_Auth_Signup } /** + * Perform common presignup actions. + * + * @param array $info Reference to array of parameters. + * + * @throws Horde_Exception + */ + protected function _preSignup(&$info) + { + global $auth; + + try { + $info = Horde::callHook('signup_preprocess', array($info)); + } catch (Horde_Exception_HookNotSet $e) {} + + // Check to see if the username already exists in auth backend. + if ($auth->exists($info['user_name'])) { + throw new Horde_Exception(sprintf(_("Username \"%s\" already exists."), $info['user_name'])); + } + + // Check to see if the username already exists in signup queue. + if ($this->exists($info['user_name'])) { + throw new Horde_Exception(sprintf(_("Username \"%s\" already exists."), $info['user_name'])); + } + } + + /** * Queues the user's submitted registration info for later admin approval. * - * @params mixed $info Reference to array of parameteres to be passed + * @params mixed $info Reference to array of parameters to be passed * to hook * * @throws Horde_Exception diff --git a/framework/Auth/lib/Horde/Auth/Signup/Sql.php b/framework/Auth/lib/Horde/Auth/Signup/Sql.php index 6e8cb03c9..6d038bd7e 100644 --- a/framework/Auth/lib/Horde/Auth/Signup/Sql.php +++ b/framework/Auth/lib/Horde/Auth/Signup/Sql.php @@ -80,6 +80,10 @@ class Horde_Auth_Signup_Sql extends Horde_Auth_Signup */ public function exists($user) { + if (empty($GLOBALS['conf']['signup']['queue'])) { + return false; + } + $stmt = $this->_db->prepare('SELECT 1 FROM ' . $this->_params['table'] . ' WHERE user_name = ?');