Code Monkey home page Code Monkey logo

userbundle's Introduction

UserBundle

Symfony User Bundle. The bundle allow in easy way to manage user and security in Symfony 4.2.

Configure

Require the bundle with composer:

$ composer require mkurc1/user-bundle

Add vendor into config/bundles.php:

<?php
// app/bundles.php

return [
    // ...
    UserBundle\UserBundle::class => ['all' => true],
    // ...
];

Create your User class:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use UserBundle\Entity\User as BaseUser;

/**
 * @ORM\Entity()
 */
class User extends BaseUser
{

Create file config/packages/user.yaml:

user:
    user_class: App\Entity\User
    sender_email: "%env(USER_SENDER_EMAIL)%"
    login:
        default_target_path: dashboard # default router after login
    resetting:
        ttl: 86400 # 24 hours

Add into config/routes.yaml:

logout:
    path: /logout

Add into config/routes/annotations.yaml:

user:
    resource: ../../vendor/mkurc1/user-bundle/Controller/
    type: annotation

Update config/packages/security.yaml:

security:
    encoders:
        # use your user class name here
        App\Entity\User:
            # bcrypt or argon2i are recommended
            # argon2i is more secure, but requires PHP 7.2 or the Sodium extension
            algorithm: bcrypt
            cost: 12

    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        user_provider:
            id: UserBundle\Security\UserProvider
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: ~
            form_login:
                login_path: login
                check_path: login
                csrf_token_generator: security.csrf.token_manager
            remember_me:
                secret:   '%kernel.secret%'
                lifetime: 2592000 # 4 weeks in seconds
                path:     /
            logout:
                path:   /logout
                target: /
            guard:
                authenticators:
                    - UserBundle\Security\LoginFormAuthenticator

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/confirm, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/reset, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: IS_AUTHENTICATED_REMEMBERED }

Update your database schema:

$ php bin/console doctrine:schema:update --force

Commands

You have access to several commands:

$ php bin/console user:create # Create a user
$ php bin/console user:activate # Activate a user
$ php bin/console user:change-password # Change the password of a user
$ php bin/console user:deactivate # Deactivate a user
$ php bin/console user:demote # Demote a user by removing a role
$ php bin/console user:promote # Promote a user by adding a role

License

The bundle is released under the MIT License.

userbundle's People

Contributors

mkurc1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.