chaplean / user-bundle
Creates a user account and log in (from FOSUserBundle)
Installs: 1 565
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.0.8
- chaplean/doctrine-extensions-bundle: ^5.0
- chaplean/form-handler-bundle: ^4.0 || ^5.0
- chaplean/mailer-bundle: ^5.0
- doctrine/doctrine-bundle: ^1.6
- doctrine/orm: ^2.5
- friendsofsymfony/rest-bundle: ^2.1
- friendsofsymfony/user-bundle: ^2.0
- sensio/distribution-bundle: ^5.0
- sensio/framework-extra-bundle: ^3.0 || ^4.0 || ^5.0
- symfony/framework-bundle: ^3.0 || ^4.0
- symfony/monolog-bundle: ^3.0 || ^4.
- symfony/security-bundle: ^3.0 || ^4.0
- symfony/templating: ^3.0 || ^4.0
- symfony/twig-bundle: ^3.0 || ^4.0
- symfony/validator: ^3.0 || ^4.0
- twig/extensions: ^1.0
Requires (Dev)
- chaplean/coding-standard: ^1.1
- chaplean/unit-bundle: ^8.0
- mockery/mockery: dev-master
- symfony/http-kernel: ^3.0 || ^4.0
- symfony/phpunit-bridge: ^4.0
- symfony/var-dumper: ^3.0 || ^4.0
- dev-master
- v8.0.3
- v8.0.2
- v8.0.1
- v8.0.0
- v7.0.1
- 7.0.0.x-dev
- v7.0.0
- v6.0.2
- v6.0.1
- v6.0.0
- v5.1.1
- v5.1.0
- v5.0.1
- v5.0.0
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.1
- v3.0.0
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dev
This package is auto-updated.
Last update: 2024-11-11 00:39:38 UTC
README
Prerequisites
This version of the bundle requires Symfony 3.4+.
Installation
1. Composer
composer require chaplean/user-bundle
2. AppKernel.php
Add
new Chaplean\Bundle\UserBundle\ChapleanUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
NOTE: After SecurityBundle
3. Define User entity
Create a User class with doctrine information.
<?php //... use Chaplean\Bundle\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="<YourTableName>") */ class User extends BaseUser { //... }
4. Minimal Configuration
Define namespace your user entity in app/config/config.yml
:
chaplean_user: entity: user: class: '<NamespaceUserEntity>'
Import default config in app/config/config.yml
:
imports: - { resource: '@ChapleanUserBundle/Resources/config/config.yml' }
Define a route name for index path
In app/config/config.yml
:
chaplean_user: entity: user: class: '<NamespaceUserEntity>' controller: index_route: <YourRouteNameForIndex> login_route: <YourRouteNameForLogin> register_password_route: <Route to set password on register> # default: 'chaplean_user_password_set_password' resetting_password_route: <Route to set password on resetting> # default: null and use register_password_route
Custom templating email:
In app/config/config.yml
chaplean_user: # ... emailing: register: subject: '<Translation key>' body: '<template twig>' resetting: subject: '<Translation key>' body: '<template twig>'
5. Configure security
In app/config/security.yml
:
imports: - { resource: '@ChapleanUserBundle/Resources/config/security.yml' }
If you want you can also overide the defaults :
security: encoders: FOS\UserBundle\Model\UserInterface: bcrypt firewalls: main: pattern: ^/ form_login: login_path: /login check_path: /api/login use_forward: false remember_me: true use_referer: true success_handler: chaplean_user.authentication.handler_json failure_handler: chaplean_user.authentication.handler_json csrf_token_generator: security.csrf.token_manager logout: path: /logout target: / anonymous: true
6. Import routing.yml
You should then create a Controller action for your login page. Make this controller inherit LoginController to get the checkAction and logoutAction actions. Finally in your routing create a route for these.
In your controller:
<?php namespace App\Bundle\FrontBundle\Controller; use Chaplean\Bundle\UserBundle\Controller\LoginController as BaseController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\SecurityUtilityTest\Csrf\CsrfTokenManagerInterface; /** * Class LoginController. */ class LoginController extends BaseController { /** * @var CsrfTokenManagerInterface */ protected $tokenManager; /** * LoginController constructor. * * @param CsrfTokenManagerInterface $tokenManager */ public function __construct(CsrfTokenManagerInterface $tokenManager) { $this->tokenManager = $tokenManager; } /** * Renders the login page. * * @Route("/connexion-of") * * @return Response */ public function loginAction() { return $this->render( 'Login/login.html.twig', [ 'csrf_token' => $this->tokenManager->getToken('authenticate')->getValue() ] ); } }
In app/config/routing.yml
:
chaplean_user_login_check: path: /api/login defaults: { _controller: AppFrontBundle:Login:check } methods: 'POST' chaplean_user_logout: path: /logout defaults: { _controller: AppFrontBundle:Login:logout } chaplean_user: resource: '@ChapleanUserBundle/Resources/config/routing.yml' chaplean_user_api: type: rest resource: '@ChapleanUserBundle/Resources/config/routing_rest.yml' prefix: /api/ app_front: type: annotation resource: '@AppFrontBundle/Controller/' prefix: /
Validator
MinimalPasswordRequirements
Chaplean\Bundle\UserBundle\Validator\Constraints\MinimalPasswordRequirements
has 2 options:
minLength
, default: 6atLeastOneSpecialCharacter
, default: true
Events
The UserBundle defines some events to allow you to hook in your own logic:
- ChapleanUserCreatedEvent : Dispatched after a user is created. Use getUser() to retreive the entity.
- ChapleanUserDeletedEvent : Dispatched before a user is deleted. Use getUser() to retreive the entity.