## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require atoolo/web-account-bundle
Add to config/bundles.php:
return [
// ...
Atoolo\WebAccountBundle\AtooloWebAccountBundle::class => ['all' => true],
];
Configuration: Publish the default config:
php bin/console config:dump-reference AtooloWebAccountBundle
Override in config/packages/atoolo_web_account.yaml:
atoolo_web_account:
ies_url: '%env(IES_URL)%' # Required for GraphQL integration
unauthorized_entry_point: '/login' # Customize unauthorized redirect
First Use Case:
Enable registration and login routes by configuring security.yaml:
security:
firewalls:
main:
form_login:
login_path: atoolo_web_account_login
check_path: atoolo_web_account_check
logout:
path: atoolo_web_account_logout
User Model: Extend the default user entity (if needed):
// src/Entity/CustomUser.php
use Atoolo\WebAccountBundle\Entity\User;
class CustomUser extends User
{
// Add custom fields/methods
}
Update security.yaml to point to your user provider:
providers:
app_user_provider:
entity:
class: App\Entity\CustomUser
property: email
Registration Flow:
Atoolo\WebAccountBundle\Controller\RegistrationController).Atoolo\WebAccountBundle\Form\RegistrationType:
// src/Form/ExtendedRegistrationType.php
use Atoolo\WebAccountBundle\Form\RegistrationType as BaseType;
class ExtendedRegistrationType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('customField', TextType::class);
}
}
services.yaml to replace the default form:
services:
Atoolo\WebAccountBundle\Form\RegistrationType:
alias: App\Form\ExtendedRegistrationType
Authentication:
atoolo_web_account_login (GET/POST)atoolo_web_account_check (login check)atoolo_web_account_logout (logout)templates/atoolo_web_account/login.html.twig.GraphQL Integration:
// src/Resolver/CustomUserResolver.php
use Overblog\GraphQLBundle\Resolver\ResolverInterface;
class CustomUserResolver implements ResolverInterface
{
public function resolve($root, array $args, GraphQLContextInterface $context)
{
// Custom logic (e.g., fetch user from external API)
}
}
config/graphql.yaml:
resolvers:
CustomUserResolver: ~
User-Specific Features:
Atoolo\WebAccountBundle\Security\User\WebAccountUser trait to access user data in controllers:
use Atoolo\WebAccountBundle\Security\User\WebAccountUser;
class MyController
{
public function showProfile(WebAccountUser $user)
{
$user->getEmail(); // Access user data
}
}
ROLE_USER):
# config/routes.yaml
app_profile:
path: /profile
controller: App\Controller\ProfileController::show
roles: [ROLE_USER]
Password Recovery:
templates/atoolo_web_account/email/reset_password.html.twig.// src/Controller/CustomRecoveryController.php
use Atoolo\WebAccountBundle\Controller\RecoveryController as BaseController;
class CustomRecoveryController extends BaseController
{
protected function generateRecoveryToken(UserInterface $user)
{
// Custom token generation logic
}
}
Event Listeners:
// src/EventListener/CustomUserListener.php
use Atoolo\WebAccountBundle\Event\UserEvents;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
class CustomUserListener
{
#[AsEventListener(event: UserEvents::REGISTERED, method: 'onUserRegistered')]
public function onUserRegistered(UserRegisteredEvent $event)
{
// Send welcome email, log activity, etc.
}
}
Extranet Support:
config/packages/atoolo_web_account.yaml:
atoolo_web_account:
extranet: true
Custom User Provider:
// src/Security/CustomUserProvider.php
use Symfony\Component\Security\Core\User\UserProviderInterface;
class CustomUserProvider implements UserProviderInterface
{
public function loadUserByIdentifier($identifier)
{
// Custom user loading logic
}
}
security.yaml:
providers:
custom_user_provider:
id: App\Security\CustomUserProvider
API Authentication:
# config/packages/security.yaml
firewalls:
api:
pattern: ^/api
stateless: true
provider: custom_user_provider
json_login:
check_path: /api/login_check
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
Testing:
use Atoolo\WebAccountBundle\Test\WebAccountTestTrait;
class MyTest extends WebTestCase
{
use WebAccountTestTrait;
public function testAuthenticatedRoute()
{
$client = static::createClient();
$this->loginUser($client, ['email' => 'user@example.com', 'password' => 'password']);
$client->request('GET', '/profile');
// Assertions...
}
}
IES URL Configuration:
ies_url in configuration for GraphQL operations. If missing, registration/password recovery will fail silently.IES_URL is set in .env and referenced in atoolo_web_account.yaml:
atoolo_web_account:
ies_url: '%env(IES_URL)%'
Role Prefix:
ROLE_ (e.g., ROLE_USER). Forgetting this prefix in security checks will cause authentication failures.ROLE_USER (not just USER) in YAML or annotations:
# Correct:
roles: [ROLE_USER]
# Incorrect:
roles: [USER]
Cookie Naming:
WEB_ACCOUNT_TOKEN for authentication cookies. Conflicts may arise with other bundles using similar names (e.g., WEB_TOKEN).config/packages/atoolo_web_account.yaml:
atoolo_web_account:
cookie_name: CUSTOM_ACCOUNT_TOKEN
GraphQL Schema Mismatches:
overblog_graphql_bundle.User Entity Inheritance:
User entity requires proper mapping of custom fields. Forgetting to update the entity manager’s metadata can lead to "undefined property" errors.php bin/console doctrine:schema:update --force after adding custom fields.How can I help you explore Laravel packages today?