Ozzy47
Well-known member
I am working on an addon that will allow users to register using existing emails or change their emails to an existing email.
I extended
Both of those have to run in order to allow someone to register using an existing email or change their email to an existing one.
Now I have two options, Allow Registration and Allow change. The first one,
Problem I am facing is if I set the options in any of the if statements, the code won't fire properly because the functions are both needed in each option. Basically what I need is a way to turn off the one or the other without affecting the other one.
I am probably missing something really simple, but the logic I need to follow is escaping me.
I extended
XF\Entity\User
and the two functions that are changed is verifyEmail(&$email)
and _preSave()
. Here is my code that is working and allowing the use of an existing email in both instances.
PHP:
<?php
namespace OzzModz\RequireUnique\XF\Entity;
class User extends XFCP_User
{
protected function verifyEmail(&$email)
{
$options = \XF::options();
$existingUser = $this->finder('XF:User')->where('email', $email)->fetchOne();
if ($existingUser && $existingUser['user_id'] != $this->user_id)
{
return true;
}
return true;
return parent::verifyEmail();
}
protected function _preSave()
{
$options = \XF::options();
if (!$this->secret_key)
{
$this->secret_key = \XF::generateRandomString(32);
}
if ($this->isChanged('email') && $this->email && empty($this->_errors['email']))
{
// Redo the duplicate email check. This tries to reduce a race condition that can be extended
// due to third-party spam checks.
$matchUserId = $this->db()->fetchOne("
SELECT user_id
FROM xf_user
WHERE email = ?
", $this->email);
if ($matchUserId && (!$this->user_id || $matchUserId != $this->user_id))
{
return true;
}
}
return parent::_preSave();
}
}
Both of those have to run in order to allow someone to register using an existing email or change their email to an existing one.
Now I have two options, Allow Registration and Allow change. The first one,
ozzmodz_RequireUnique_registration
controls if a user can register using an existing email and the second one, ozzmodz_RequireUnique_change
controls if a user can change their email to an existing email.Problem I am facing is if I set the options in any of the if statements, the code won't fire properly because the functions are both needed in each option. Basically what I need is a way to turn off the one or the other without affecting the other one.
I am probably missing something really simple, but the logic I need to follow is escaping me.