0

我正在尝试修改 FOSUSerBundle 在用户注册时验证用户名/电子邮件的方式,因为我需要通过实体中的状态标志检查用户是否以前注册过,但他已取消订阅。我认为最好的方法是检查电子邮件是否以前在数据库中,不包括那些标志unsubscribed设置为 true 的人,但是我该怎么做呢?

所以,我看到如何通过UniqueValidator类进行验证,但我不明白它是如何工作的。如果有人也能解释一下,那就太好了。

谢谢。

4

1 回答 1

2

UniqueValidator调用类的validateUnique方法UserManager。您可以扩展类并修改功能以检查用户

$this->findUserByEmail($user->getEmail());

编辑

对于第二个问题,您必须覆盖类UpdateUser的方法UserManager

/**
 * Updates a user.
 *
 * @param UserInterface $user
 * @param Boolean $andFlush Whether to flush the changes (default true)
 */
public function updateUser(UserInterface $user, $andFlush = true)
{
    $existsUser = $this->findUserByEmail($user->getEmail()); 
    $this->updateCanonicalFields($user);
    $this->updatePassword($user);

    if($existsUser && null === $user->getId()){
        $user->setId($existsUser->getId());
        $this->em->merge($user);
    } else{
        $this->em->persist($user);
    }

    if ($andFlush) {
        $this->em->flush();
    }
}
于 2012-03-30T15:01:13.190 回答