Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chaplean/user-bundle
https://github.com/chaplean/user-bundle
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/chaplean/user-bundle
- Owner: chaplean
- Created: 2019-07-10T11:53:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-10T12:12:25.000Z (over 5 years ago)
- Last Synced: 2024-04-24T09:25:21.432Z (9 months ago)
- Language: PHP
- Size: 4.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Security: Security/Handler/ExceptionHandler.php
Awesome Lists containing this project
README
Getting Started With Chaplean User Bundle
=========================================# Prerequisites
This version of the bundle requires Symfony 3.4+.
# Installation
## 1. Composer
```
composer require chaplean/user-bundle
```## 2. AppKernel.php
Add
```
new Chaplean\Bundle\UserBundle\ChapleanUserBundle(),
new FOS\UserBundle\FOSUserBundle(),
```
**NOTE**: After SecurityBundle## 3. Define User entity
Create a User class with doctrine information.
```php
")
*/
class User extends BaseUser {
//...
}
```## 4. Minimal Configuration
Define namespace your user entity in `app/config/config.yml`:
```yaml
chaplean_user:
entity:
user:
class: ''
```Import default config in `app/config/config.yml`:
```yaml
imports:
- { resource: '@ChapleanUserBundle/Resources/config/config.yml' }
```Define a route name for index path
In `app/config/config.yml`:
```yaml
chaplean_user:
entity:
user:
class: ''
controller:
index_route:
login_route:
register_password_route: # default: 'chaplean_user_password_set_password'
resetting_password_route: # default: null and use register_password_route
```Custom templating email:
In `app/config/config.yml`
```yaml
chaplean_user:
# ...
emailing:
register:
subject: ''
body: ''
resetting:
subject: ''
body: ''
```## 5. Configure security
In `app/config/security.yml`:
```yaml
imports:
- { resource: '@ChapleanUserBundle/Resources/config/security.yml' }
```If you want you can also overide the defaults :
```yaml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcryptfirewalls:
main:
pattern: ^/
form_login:
login_path: /login
check_path: /api/login
use_forward: false
remember_me: true
use_referer: true
success_handler: chaplean_user.authentication.handler_json
failure_handler: chaplean_user.authentication.handler_json
csrf_token_generator: security.csrf.token_manager
logout:
path: /logout
target: /
anonymous: true
```## 6. Import routing.yml
You should then create a Controller action for your login page. Make this controller inherit LoginController
to get the checkAction and logoutAction actions. Finally in your routing create a route for these.In your controller:
```php
tokenManager = $tokenManager;
}/**
* Renders the login page.
*
* @Route("/connexion-of")
*
* @return Response
*/
public function loginAction()
{
return $this->render(
'Login/login.html.twig',
[
'csrf_token' => $this->tokenManager->getToken('authenticate')->getValue()
]
);
}
}
```In `app/config/routing.yml`:
```yaml
chaplean_user_login_check:
path: /api/login
defaults: { _controller: AppFrontBundle:Login:check }
methods: 'POST'chaplean_user_logout:
path: /logout
defaults: { _controller: AppFrontBundle:Login:logout }chaplean_user:
resource: '@ChapleanUserBundle/Resources/config/routing.yml'chaplean_user_api:
type: rest
resource: '@ChapleanUserBundle/Resources/config/routing_rest.yml'
prefix: /api/app_front:
type: annotation
resource: '@AppFrontBundle/Controller/'
prefix: /
```# Validator
### MinimalPasswordRequirements
`Chaplean\Bundle\UserBundle\Validator\Constraints\MinimalPasswordRequirements` has 2 options:
* `minLength`, default: 6
* `atLeastOneSpecialCharacter`, default: true# Events
The UserBundle defines some events to allow you to hook in your own logic:
- ChapleanUserCreatedEvent : Dispatched after a user is created. Use getUser() to retreive the entity.
- ChapleanUserDeletedEvent : Dispatched before a user is deleted. Use getUser() to retreive the entity.