dyatlovk / usersbundle
Symfony users bundle
v0.3.2
2021-03-22 08:14 UTC
Requires
- php: >=7.2
- doctrine/orm: ^2.7
- sensio/framework-extra-bundle: ^5.2
- symfony/form: 4.4.*
- symfony/framework-bundle: 4.4.*
- symfony/mailer: 4.4.*
- symfony/security-bundle: 4.4.*
- symfony/security-csrf: *
- symfony/templating: 4.4.*
- symfony/twig-bundle: 4.4.*
- symfony/yaml: *
- twig/twig: 3.0.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.15
- symfony/console: 4.4.*
- symfony/framework-bundle: 4.4.*
- symfony/orm-pack: ^1.0
- symfony/phpunit-bridge: 4.4.*
- symfony/symfony: 4.4.*
- symfony/yaml: *
README
User managment system in Symfony 4+
Features:
- Registration
- Auth via email
- Remember me
- Password resetting
- Console commands (activate, create, promote etc)
- Standalone unit tested (no requiring symfony framework)
Quick start
Require the bundle with composer:
composer requre dyatlovk/usersbundle
Enable the bundle:
<?php
// config/bundles.php
return [
// ...
new Dyatlov\UsersBundle\DyatlovUserBundle(),
// ...
];
Create User entity class:
<?php
// App/Entity/User.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Dyatlov\UsersBundle\Model\User as BaseUser;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* Class User
*
* @UniqueEntity(fields="email", message="Email already taken")
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="`user`")
*/
class User extends BaseUser
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
Configure your application's config:
# config/security.yml
security:
encoders:
Dyatlov\UsersBundle\Model\UserInterface:
algorithm: bcrypt
providers:
in_memory: { memory: ~ }
user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: true
provider: user_provider
user_checker: dyatlov_users.checker
logout:
path: dyatlov.users.logout
target: app.index
form_login:
login_path: dyatlov.users.login
check_path: dyatlov.users.login
username_parameter: login_form[email]
password_parameter: login_form[password]
remember_me:
secret: '%kernel.secret%'
lifetime: 604800 # 1 week in seconds
path: /
secure: true
always_remember_me: false
remember_me_parameter: login_form[rememberme]
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
Configure the bundle:
# config/framework.yml
dyatlov_users:
user_class: 'App\Entity\User'
Importing routes:
#config/routes/users.yml
users:
resource: '@DyatlovUsersBundle/Resources/config/routing/'
type: directory
Update your database schema:
bin/console doctrine:schema:update --force