Disabling email verification in sylius platform

1.1k views Asked by At

one question...If I want to disable email verification upon user registration ( I would like for users to be logged in automatically after registration) how should I do that? Should I change it in the configuration somewhere or should I override controllers and manually enable users and add verification for them? I saw that in previous sylius versions there were a configuration for verification in sylius_user (SyliusUserBundle) but in new version, there is no configuration for that. Thank you.

//edit// I have overridden controller for registration(code below) and just got User and enabled it plus logged him in with service provided with sylius.

<?php

namespace AppBundle\Controller;

use Blameable\Fixture\Document\User;
use FOS\RestBundle\View\View;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sylius\Bundle\ResourceBundle\Controller\ResourceController as BaseCustomerController;
use Sylius\Component\Resource\ResourceActions;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Sylius\Bundle\UserBundle\Security\UserLogin as UserLogin;

class CustomerController extends BaseCustomerController
{
    /**
     * @param Request $request
     *
     * @return Response
     */
    public function createAction(Request $request)
    {
        $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

    $this->isGrantedOr403($configuration, ResourceActions::CREATE);
    $newResource = $this->newResourceFactory->create($configuration, $this->factory);

    $form = $this->resourceFormFactory->create($configuration, $newResource);

    if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
        $newResource = $form->getData();

        $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource);

        if ($event->isStopped() && !$configuration->isHtmlRequest()) {
            throw new HttpException($event->getErrorCode(), $event->getMessage());
        }
        if ($event->isStopped()) {
            $this->flashHelper->addFlashFromEvent($configuration, $event);

            return $this->redirectHandler->redirectToIndex($configuration, $newResource);
        }

        if ($configuration->hasStateMachine()) {
            $this->stateMachine->apply($configuration, $newResource);
        }
        $newResource->getUser()->enable();
        $this->repository->add($newResource);
        $this->get('sylius.security.user_login')->login($newResource->getUser());
        $this->eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource);


        if (!$configuration->isHtmlRequest()) {
            return $this->viewHandler->handle($configuration, View::create($newResource, Response::HTTP_CREATED));
        }

        $this->flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource);

        return $this->redirectHandler->redirectToResource($configuration, $newResource);
    }

    if (!$configuration->isHtmlRequest()) {
        return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST));
    }

    $view = View::create()
        ->setData([
            'configuration' => $configuration,
            'metadata' => $this->metadata,
            'resource' => $newResource,
            $this->metadata->getName() => $newResource,
            'form' => $form->createView(),
        ])
        ->setTemplate($configuration->getTemplate(ResourceActions::CREATE . '.html'))
    ;

    return $this->viewHandler->handle($configuration, $view);
}


}
1

There are 1 answers

0
michalmarcinkowski On BEST ANSWER

You can simply do that by bringing back two classes from this PR:

  1. UserAutoLoginListener
  2. UserRegistrationFormSubscriber