This is a Symfony bundle, that extends the symfony user, without adding too many unnecessary features.
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require plumtreesystems/user-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the /configu/bundles.php
file of your project:
<?php
// bundles.php
// ...
return [
//...
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
//...
PlumTreeSystems\UserBundle\PlumTreeSystemsUserBundle::class => ['all' => true],
//...
];
Create a configuration for the bundle
#config/packages/pts_user_bundle.yaml
plum_tree_systems_user:
user_class: <classname of the class that extends one of the abstract classes>
Import the routes
#config/routes.yaml
plum_tree_systems_user:
resource: "@PlumTreeSystemsUserBundle/Resources/config/routes/securityRoutes.yml"
prefix: /
Create a user entity, that extends one of the existing abstract (TokenUser|User...) entities.
// App/Entity/User.php
namespace App\Entity;
use PlumTreeSystems\UserBundle\Entity\User as PTSUser;
class User extends PTSUser {
/...
}
Add this user class to the config/packages/pts_user_bundle.yaml
configuration file.
#config/packages/pts_user_bundle.yaml
plum_tree_systems_user:
user_class: 'App\Entity\User'
Add the security provider and encoder
#config/packages/security.yaml
security:
#...
providers:
ptsuser:
id: pts_user.provider
#...
encoders:
App\Entity\User: bcrypt
# optionally add the user checker to the firewalls where you will be using the authentication to handle disabled users
firewalls:
#...
main:
#...
user_checker: pts_user.security.checker
#...
If the extended user does not bring any additional fields, the create user command can be used php bin/console pts:user:create
note: when implementing own user, and not overriding password creation flow, use the $user->setPlainPassword('1234')
method to automatically encode it prior to persisting it to the database
Access the imported login route ex: mywebsite.com/
[prefix]
login
To customize the login form add a template file /templates/bundles/PlumTreeSystemsUserBundle/security/login.html.twig
Preferably copying and modifying the original