Commit a9706a49 authored by Mat's avatar Mat

Installation de FOSUserBundle lié à une entité User

* procédure en 7 étapes: https://symfony.com/doc/current/bundles/FOSUserBundle/index.html#content_wrapper
parent 769982c5
......@@ -17,6 +17,7 @@ class AppKernel extends Kernel
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new PotageBundle\PotageBundle(),
new FOS\UserBundle\FOSUserBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
......
......@@ -7,11 +7,11 @@ imports:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
locale: fr
framework:
#esi: ~
#translator: { fallbacks: ['%locale%'] }
translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.project_dir%/app/config/routing.yml'
......@@ -31,6 +31,8 @@ framework:
assets: ~
php_errors:
log: true
templating:
engines: [ twig ]
# Twig Configuration
twig:
......@@ -66,3 +68,12 @@ swiftmailer:
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
# FOSUserBundle Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: PotageBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
potage:
resource: "@PotageBundle/Resources/config/routing.yml"
prefix: /
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
prefix: /user
\ No newline at end of file
# To get started with security, check out the documentation:
# https://symfony.com/doc/current/security.html
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
anonymous: ~
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
#http_basic: ~
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
default_target_path: potage_homepage
use_referer : true
logout:
path: fos_user_security_logout
target: fos_user_security_login
anonymous: true
# https://symfony.com/doc/current/security/form_login_setup.html
#form_login: ~
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
\ No newline at end of file
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "4ab692c7e39abd3f37b227cce7b2acbc",
"content-hash": "61ec79609e6e01d169f10addc4e17290",
"packages": [
{
"name": "composer/ca-bundle",
......@@ -889,6 +889,82 @@
],
"time": "2016-10-17T18:31:11+00:00"
},
{
"name": "friendsofsymfony/user-bundle",
"version": "v2.1.2",
"source": {
"type": "git",
"url": "https://github.com/FriendsOfSymfony/FOSUserBundle.git",
"reference": "1049935edd24ec305cc6cfde1875372fa9600446"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/FriendsOfSymfony/FOSUserBundle/zipball/1049935edd24ec305cc6cfde1875372fa9600446",
"reference": "1049935edd24ec305cc6cfde1875372fa9600446",
"shasum": ""
},
"require": {
"paragonie/random_compat": "^1 || ^2",
"php": "^5.5.9 || ^7.0",
"symfony/form": "^2.8 || ^3.0 || ^4.0",
"symfony/framework-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/security-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/templating": "^2.8 || ^3.0 || ^4.0",
"symfony/twig-bundle": "^2.8 || ^3.0 || ^4.0",
"symfony/validator": "^2.8 || ^3.0 || ^4.0",
"twig/twig": "^1.28 || ^2.0"
},
"conflict": {
"doctrine/doctrine-bundle": "<1.3",
"symfony/doctrine-bridge": "<2.7"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.3",
"friendsofphp/php-cs-fixer": "^2.2",
"phpunit/phpunit": "^4.8.35|^5.7.11|^6.5",
"swiftmailer/swiftmailer": "^4.3 || ^5.0 || ^6.0",
"symfony/console": "^2.8 || ^3.0 || ^4.0",
"symfony/phpunit-bridge": "^2.8 || ^3.0 || ^4.0",
"symfony/yaml": "^2.8 || ^3.0 || ^4.0"
},
"type": "symfony-bundle",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"autoload": {
"psr-4": {
"FOS\\UserBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Christophe Coevoet",
"email": "stof@notk.org"
},
{
"name": "FriendsOfSymfony Community",
"homepage": "https://github.com/friendsofsymfony/FOSUserBundle/contributors"
},
{
"name": "Thibault Duplessis"
}
],
"description": "Symfony FOSUserBundle",
"homepage": "http://friendsofsymfony.github.com",
"keywords": [
"User management"
],
"time": "2018-03-08T08:59:27+00:00"
},
{
"name": "incenteev/composer-parameter-handler",
"version": "v2.1.3",
......
<?php
namespace PotageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* User
*
* @ORM\Table(name="fos_user")
* @ORM\Entity(repositoryClass="PotageBundle\Repository\UserRepository")
*/
class User extends BaseUser
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* User constructor.
*/
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
}
<?php
namespace PotageBundle\Repository;
/**
* UserRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class UserRepository extends \Doctrine\ORM\EntityRepository
{
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment