{"id":14983709,"url":"https://github.com/damienharper/userbundle","last_synced_at":"2025-04-10T19:04:29.304Z","repository":{"id":54128226,"uuid":"149285325","full_name":"DamienHarper/UserBundle","owner":"DamienHarper","description":"Simple yet convenient bundle which lets you easily add features like user authentication, password resetting, user account locking, user account expiration to your application.","archived":false,"fork":false,"pushed_at":"2021-03-08T22:21:34.000Z","size":46,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T16:45:07.478Z","etag":null,"topics":["authentication","doctrine","symfony","symfony-bundle","symfony-flex","symfony3","symfony4","user-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DamienHarper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-18T12:33:54.000Z","updated_at":"2025-02-24T14:05:33.000Z","dependencies_parsed_at":"2022-08-13T07:01:24.345Z","dependency_job_id":null,"html_url":"https://github.com/DamienHarper/UserBundle","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamienHarper%2FUserBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamienHarper%2FUserBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamienHarper%2FUserBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DamienHarper%2FUserBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DamienHarper","download_url":"https://codeload.github.com/DamienHarper/UserBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248279196,"owners_count":21077406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","doctrine","symfony","symfony-bundle","symfony-flex","symfony3","symfony4","user-bundle"],"created_at":"2024-09-24T14:07:48.689Z","updated_at":"2025-04-10T19:04:29.274Z","avatar_url":"https://github.com/DamienHarper.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UserBundle \n\n[![Latest Stable Version](https://poser.pugx.org/damienharper/user-bundle/v/stable)](https://packagist.org/packages/damienharper/user-bundle)\n[![Latest Unstable Version](https://poser.pugx.org/damienharper/user-bundle/v/unstable)](https://packagist.org/packages/damienharper/user-bundle)\n[![Total Downloads](https://poser.pugx.org/damienharper/user-bundle/downloads)](https://packagist.org/packages/damienharper/user-bundle)\n[![License](https://poser.pugx.org/damienharper/user-bundle/license)](https://packagist.org/packages/damienharper/user-bundle)\n[![Monthly Downloads](https://poser.pugx.org/damienharper/user-bundle/d/monthly)](https://packagist.org/packages/damienharper/user-bundle)\n[![Daily Downloads](https://poser.pugx.org/damienharper/user-bundle/d/daily)](https://packagist.org/packages/damienharper/user-bundle)\n\n\nThis bundle, simple yet convenient, lets you easily add to your application features such as:\n- user authentication\n- password resetting\n- user account locking\n- user account expiration\n- force a user to reset his password at first connection\n\n**Notes**: \n- this bundle assumes you're using Doctrine to persist and retrieve your users. It provides a Doctrine UserProvider.\n- if you need two factor authentication (2FA), this bundle plays nicely with [TwoFactorBundle](https://github.com/scheb/two-factor-bundle)\n- this bundle is inspired by [FOSUserBundle](https://github.com/FriendsOfSymfony/FOSUserBundle.git)\n\n\nInstallation\n============\n\nApplications that use Symfony Flex\n----------------------------------\n\nOpen a command console, enter your project directory and execute:\n\n```console\n$ composer require damienharper/user-bundle\n```\n\nApplications that don't use Symfony Flex\n----------------------------------------\n\n### Step 1: Download the Bundle\n\nOpen a command console, enter your project directory and execute the\nfollowing command to download the latest stable version of this bundle:\n\n```console\n$ composer require damienharper/user-bundle\n```\n\nThis command requires you to have Composer installed globally, as explained\nin the [installation chapter](https://getcomposer.org/doc/00-intro.md)\nof the Composer documentation.\n\n### Step 2: Enable the Bundle\n\nThen, enable the bundle by adding it to the list of registered bundles\nin the `app/AppKernel.php` file of your project:\n\n```php\n\u003c?php\n// app/AppKernel.php\n\n// ...\nclass AppKernel extends Kernel\n{\n    public function registerBundles()\n    {\n        $bundles = array(\n            // ...\n            new DH\\UserBundle\\DHUserBundle(),\n        );\n\n        // ...\n    }\n\n    // ...\n}\n```\n\n\nConfiguration\n=============\n\n**Note**: following configuration instructions target a Symfony 4 application.\n\n## Step 1: Configure the bundle\n\nCreate a file named `dh_user.yaml` in the `config/packages` directory with the following content.\n\n```yaml\n# config/packages/dh_user.yaml\ndh_user:\n    user_class: App\\Entity\\User         # FQDN name of your user class\n    password_reset:\n        email_from: john.doe@gmail.com  # Sender of the password reset requests\n        token_ttl: 7200                 # TTL of a password reset request\n```\n\n**Notes**:\n- By default, the bundle assumes your User class name is `App\\Entity\\User`\n\n## Step 2: Setup routes\n\nEdit the `config/routes.yaml` file and add the following import rules.\n\n```yaml\n# config/routes.yaml\ndh_userbundle:\n    resource: \"@DHUserBundle/Controller/\"\n    type: annotation\n```\n\nThen, you'll have basic pages for logging in, requesting a password reset, resetting a password.\n\n## Step 3: Enable the bundle for your firewall\n\nEdit the `config/packages/security.yaml` file and add the appropriate blocks/rules as shown below, in this\nminimal configuration example.\n\n```yaml\n# config/packages/security.yaml\nsecurity:\n    encoders:\n        App\\Entity\\User:\n            algorithm: bcrypt\n\n    role_hierarchy:\n        ROLE_ADMIN:       ROLE_USER\n        ROLE_SUPER_ADMIN: ROLE_ADMIN\n\n    providers:\n        user_provider:\n            id: dh_userbundle.user_provider\n\n    firewalls:\n        dev:\n            pattern: ^/(_(profiler|wdt)|css|images|js)/\n            security: false\n\n        main:\n            pattern:  ^/\n            provider: user_provider\n            user_checker: dh_userbundle.user_checker\n            anonymous:    true\n\n            form_login:\n                login_path: dh_userbundle_login\n                check_path: dh_userbundle_login\n\n            logout: true\n\n\n    # Easy way to control access for large sections of your site\n    # Note: Only the *first* access control that matches will be used\n    access_control:\n        - { path: ^/login, role: IS_AUTHENTICATED_ANONYMOUSLY }\n        - { path: ^/password-reset, role: IS_AUTHENTICATED_ANONYMOUSLY }\n        - { path: ^/lost-password, role: IS_AUTHENTICATED_ANONYMOUSLY }\n        - { path: ^/admin/, role: ROLE_ADMIN }\n```\n\n## Step 4: Create (or update) your User class\n\nThe User class has to be an entity (the Doctrine way) which means a simple class containing properties mapped to columns\nof a table in the database. \n\nYour User class has to implement a few interfaces to make it work with the bundle:\n- `DH\\UserBundle\\Security\\UserInterface` which lists the methods expected to be callable by the bundle\n- `\\Serializable` regarding serialization/deserialization of User instances\n\nIn addition, a few properties are required by the bundle and as a convenience, the bundle provides you two traits you \ncan `use` in your User class to minimize your work:\n- `DH\\UserBundle\\Model\\ExtendedUserTrait` contains all the properties and methods required by the bundle.\n- `DH\\UserBundle\\Model\\UserTrait` only contains the minimal, it's up to you to implement the remaining required properties \nand methods (you can then use the `ExtendedUserTrait` as an example)  \n\nExample of a User class using `ExtendedUserTrait`\n```php\n\u003c?php\n\nnamespace App\\Entity;\n\nuse DH\\UserBundle\\Model\\ExtendedUserTrait;\nuse DH\\UserBundle\\Security\\UserInterface;\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntity;\nuse Symfony\\Component\\Validator\\Constraints as Assert;\n\n\n/**\n * @ORM\\Entity(repositoryClass=\"App\\Repository\\UserRepository\")\n * @ORM\\Table(name=\"user\")\n * @UniqueEntity(fields=\"email\", message=\"Email already registered.\")\n * @UniqueEntity(fields=\"username\", message=\"Username already registered.\")\n */\nclass User implements UserInterface, \\Serializable\n{\n    use ExtendedUserTrait;\n\n    /**\n     * @ORM\\Id\n     * @ORM\\GeneratedValue\n     * @ORM\\Column(type=\"integer\")\n     */\n    private $id;\n\n    /**\n     * @ORM\\Column(type=\"string\")\n     * @Assert\\NotBlank()\n     */\n    private $fullName;\n\n    public function getId(): int\n    {\n        return $this-\u003eid;\n    }\n\n    public function setFullName(string $fullName): void\n    {\n        $this-\u003efullName = $fullName;\n    }\n\n    public function getFullName(): ?string\n    {\n        return $this-\u003efullName;\n    }\n}\n```\n\n\n\n\nLicense\n=======\n\nUserBundle is free to use and is licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamienharper%2Fuserbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdamienharper%2Fuserbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdamienharper%2Fuserbundle/lists"}