PHP code example of ruwork / manual-auth-bundle

1. Go to this page and download the library: Download ruwork/manual-auth-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/ */

    

ruwork / manual-auth-bundle example snippets




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
    }
}