From 46fda14e08e8936cb5f37bc53f79e3b375b84789 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Sun, 20 Feb 2011 21:23:27 +0100 Subject: [PATCH] Make sure no secondary email addresses are used for registration or when changing email address --- src/IDF/Form/Register.php | 4 +--- src/IDF/Form/UserAccount.php | 6 ++---- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/IDF/Form/Register.php b/src/IDF/Form/Register.php index 752deb4..449d776 100644 --- a/src/IDF/Form/Register.php +++ b/src/IDF/Form/Register.php @@ -93,9 +93,7 @@ class IDF_Form_Register extends Pluf_Form function clean_email() { $this->cleaned_data['email'] = mb_strtolower(trim($this->cleaned_data['email'])); - $guser = new Pluf_User(); - $sql = new Pluf_SQL('email=%s', $this->cleaned_data['email']); - if ($guser->getCount(array('filter' => $sql->gen())) > 0) { + if (Pluf::factory('IDF_EmailAddress')->get_user_for_email_address($this->cleaned_data['email']) != null) { throw new Pluf_Form_Invalid(sprintf(__('The email "%s" is already used. If you need, click on the help link to recover your password.'), $this->cleaned_data['email'])); } return $this->cleaned_data['email']; diff --git a/src/IDF/Form/UserAccount.php b/src/IDF/Form/UserAccount.php index d09417d..2474aeb 100644 --- a/src/IDF/Form/UserAccount.php +++ b/src/IDF/Form/UserAccount.php @@ -393,10 +393,8 @@ class IDF_Form_UserAccount extends Pluf_Form function clean_email() { $this->cleaned_data['email'] = mb_strtolower(trim($this->cleaned_data['email'])); - $guser = new Pluf_User(); - $sql = new Pluf_SQL('email=%s AND id!=%s', - array($this->cleaned_data['email'], $this->user->id)); - if ($guser->getCount(array('filter' => $sql->gen())) > 0) { + $user = Pluf::factory('IDF_EmailAddress')->get_user_for_email_address($this->cleaned_data['email']); + if ($user != null and $user->id != $this->user->id) { throw new Pluf_Form_Invalid(sprintf(__('The email "%s" is already used.'), $this->cleaned_data['email'])); } return $this->cleaned_data['email'];