Hi all,
I found that this wonderfull snippet does check on duplicate email on submitting a new account, but it doesn’t when a user edits his profile. Therefor I edited the source code a little and thought, lets share it:)
The code can be inserted on line 867 in the webloginpe.class file. This is for the version thats distributed with evo. I thought it is 2.0. On the last version that is obtained from google code its line 907. For any other versions, insert it in the function SaveUserProfile after EVENT: OnBeforeWebSaveUser block.
The code is basicly a copy of the part that is used in the register function, with the addition that I changed the query to ignore the email database entry from the current user. This to prevent getting an error when a user saves his profile without editing the email.
Here is the code:
//check for duplicate email
if(!empty($_POST['email'])) {
// Validate the email address.
$this->ValidateEmail($_POST['email']);
if (!empty($this->Report))
{
return $this->report;
}
//check if email exists in db except the email for current user, in the case he didnt changed his email
$query = "SELECT * FROM ". $web_user_attributes ." WHERE `email`='".$_POST['email']."' AND `id`!='" . $internalKey . "'";
$checkEmail = $modx->db->query($query);
$limit = $modx->recordCount($checkEmail);
if ($limit > 0)
{
return $this->FormatMessage($this->LanguageArray[8]);
}
}
I hope this helps:)
Jurrian