PHP code example of kikwik / double-opt-in-bundle

1. Go to this page and download the library: Download kikwik/double-opt-in-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kikwik / double-opt-in-bundle example snippets


namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Kikwik\DoubleOptInBundle\Model\DoubleOptInInterface;
use Kikwik\DoubleOptInBundle\Model\DoubleOptInTrait;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Entity(repositoryClass=UserRepository::class)
 * @ORM\Table(name="`user`")
 */
class User implements UserInterface, DoubleOptInInterface
{
    use DoubleOptInTrait;

    //...
}

$user = new User();
$user->setEmail('[email protected]');
$user->setPassword('secret');

$user->disableDoubleOptIn();

$em->persist($user);
$em->flush();

/**
 * @Route("/resend-email/{id}", name="app_resend_email")
 */
public function resendConfirmationEmail(User $user, DoubleOptInMailManager $doubleOptInMailManager)
{
    if($user->getDoubleOptInSecretCode())
    {
        $doubleOptInMailManager->sendEmail($user);
    }
    return $this->redirectToRoute('app_home');
}

// src/EventSubscriber/AfterDoubleOptInEventSubscriber.php
namespace App\EventSubscriber;

use Kikwik\DoubleOptInBundle\Event\DoubleOptInVerifiedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class AfterDoubleOptInEventSubscriber implements EventSubscriberInterface
{
    public function onDoubleOptInVerified(DoubleOptInVerifiedEvent $event)
    {
        $object = $event->getObject();

        // Do something with the $object, which is verified
    }

    public static function getSubscribedEvents()
    {
        return [
            'kikwik.double_opt_in.verified' => 'onDoubleOptInVerified',
        ];
    }
}
yaml
double_opt_in:
    title: Verifica email
    success: La tua email è stata verificata con successo
    danger: Il codice di verifica non è stato trovato, forse è già stato usato?
    email:
        subject: 'Conferma la tua email'
        content: |
            <p>
                <a href="{{ confirm_url }}">Clicca qui per confermare la tua email</a><br/>
                oppure incolla in seguente link nella barra degli indirizzi del browser: <br/>{{ confirm_url }}
            </p>