ruwork/manual-auth-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Ruwork Manual Auth Bundle

Installs: 10 597

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 5

Forks: 0

Type:symfony-bundle

0.13.5 2019-01-21 11:28 UTC

README

Configuration

# app/config/security.yml
security:
    main:
        # add manual auth to any firewall
        manual: ~
        anonymous: ~
        provider: your_user_provider
        form_login:
            # ...
        logout:
            # ...
        remember_me:
            # configure remember me if you need
            always_remember_me: true

Authenticating a User in the controller

<?php

declare(strict_types=1);

namespace App\Controller;

use Ruwork\ManualAuthBundle\ManualAuthTokens;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\User\UserInterface;

final class RegistrationController
{
    private $manualAuthTokens;
    
    public function __construct(ManualAuthTokens $manualAuthTokens) {
        $this->manualAuthTokens = $manualAuthTokens;
    }
    
    /**
     * @Route("/registration")
     */
    public function __invoke()
    {
        // registration form handling
        
        /** 
         * @var UserInterface $user
         * @var FormInterface $form
         */
        
        if ($form->isSubmitted() && $form->isValid()) {
            // save user
            
            // you have to create a relevant token
            // f.e. PostAuthGuardToken for a firewall with guard authentication
            $token = new UsernamePasswordToken($user, $user->getPassword(), 'main', $user->getRoles());
            $this->manualAuthTokens->set('main', $token);
            
            // redirect to next page
        }
        
        // not submitted and invalid form logic
    }
}