Repository URL to install this package:
|
Version:
6.2.10 ▾
|
| routes |
| reset |
| security |
| Form |
| DependencyInjection |
| Controller |
| Service |
| Event |
| Entity |
| Security |
| services.xml |
| DigitalAsceticBaseUserBundle.php |
| CHANGELOG.md |
| README.md |
| composer.json |
This library provide basic abstract class to work with User entity.
Also has implemented routes and services to handle login, logout and reset password.
This is the abstract class that you must extend from.
The security/user system is pluggable and can be configured this way:
First of all create your own User class extending from AbstractBaseUser:
namespace App\Entity;
use DigitalAscetic\BaseUserBundle\Entity\AbstractBaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* Class User
* @package App\Entity
*
* @ORM\Table(name="test_user")
* @ORM\Entity()
*/
class User extends AbstractBaseUser
{
}
| Property | Description | Default |
|---|---|---|
| user_class | User entity class | required |
| firewall_name | Firewall name to apply security checker | main |
| user_enabled | Default user enabled behaviour; if enabled is false user can't login until is enabled | false |
Example:
digital_ascetic_base_user: user_class: 'App\Entity\User' firewall_name: 'main' user_enabled: true // User is enabled by default
You must import all BaseUser routes:
asc_base_user: resource: "@DigitalAsceticBaseUserBundle/Resources/config/routes/all.xml"
or for example if you don't want reset functionality you can only import:
asc_base_user: resource: "@DigitalAsceticBaseUserBundle/Resources/config/routes/security.xml"
Review Symfony Security Documentation: Firewall and authentication sections
security: password_hashers: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' providers: base_user_provider: id: DigitalAscetic\BaseUserBundle\Security\UserProvider
To persist user we can simply use DigitalAscetic\BaseUserBundle\Service\UserManagerInterface updateUser method, that automatically handle encoding password and enabled behaviour.
The next code create a testUser entity, and calling updateUser method, automatically encode plainPassword and store to password property. Also depending on user_enabled configuration value, set its behaviour.
$testUser = new BaseUser(); $testUser->setUsername('test'); $testUser->setEmail('test@test.com'); $testUser->setPlainPassword('12345678'); $this->userManager->updateUser($testUser);
You can use our MVC implementation calling to :
Or use our RepeatPasswordService with a the methods to accomplish this task.
There are two events dispatched:
This bundle is compatible with JMSSerializerBundle, detecting if it's enabled and add AbstractBaseUser serialize mappings to its configuration.
id:
groups: [ id ]
type: integer
username:
groups: [ user.default ]
type: string
email:
groups: [ user.default ]
type: string
plainPassword:
groups: [ user.default ]
type: string
roles:
groups: [ user.roles ]
type: array
Run test executing:
./vendor/bin/simple-phpunit