Well, when registering the user has their ACTIVE set to 0, how to send an email with a link so that when clicking on this link the user will update the asset to 1.
Well, when registering the user has their ACTIVE set to 0, how to send an email with a link so that when clicking on this link the user will update the asset to 1.
I generate a token and save it to my user, then I search the user database containing that token in the database, so you retrieve the user without much work. To generate the token I use the following methods
public function onRegistrationSuccess($user)
{
$user->setEnabled(false);
if (null === $user->getConfirmationToken()) {
$user->setConfirmationToken($this->generateToken());
}
$this->sendConfirmationEmailMessage($user);
}
public function generateToken()
{
return rtrim(strtr(base64_encode($this->getRandomNumber()), '+/', '-_'), '=');
}
private function getRandomNumber()
{
return hash('sha256', uniqid(mt_rand(), true), true);
}
You can use openssl to change the randomNumber method to this one
private function getRandomNumber()
{
$nbBytes = 32;
$bytes = openssl_random_pseudo_bytes($nbBytes, $strong);
if (false !== $bytes && true === $strong) {
return $bytes;
}
throw new \Exception('OpenSSL não produziu um número aleatório seguro.');
}