aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2018-04-20 15:42:06 +0200
committerneodarz <neodarz@neodarz.net>2018-04-20 15:42:06 +0200
commite9f888b55624413ae1f946fd8aca9182dba354cb (patch)
treec17841e8b6d6e04239443aac9545adb92072bc7e
parent9f2cb612b2f4a2914d0f09fa9d6ba16d11e0bd2d (diff)
downloadfilmManager-e9f888b55624413ae1f946fd8aca9182dba354cb.zip
filmManager-e9f888b55624413ae1f946fd8aca9182dba354cb.tar.xz
Implement FOSUserBundle
-rw-r--r--app/AppKernel.php1
-rw-r--r--app/Resources/views/base.html.twig6
-rw-r--r--app/config/config.yml11
-rw-r--r--app/config/routing.yml19
-rw-r--r--app/config/security.yml21
-rw-r--r--composer.json2
-rw-r--r--composer.lock80
-rw-r--r--src/AppBundle/Entity/User.php26
8 files changed, 163 insertions, 3 deletions
diff --git a/app/AppKernel.php b/app/AppKernel.php
index d3e300f..45eb04f 100644
--- a/app/AppKernel.php
+++ b/app/AppKernel.php
@@ -17,6 +17,7 @@ class AppKernel extends Kernel
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
+ new FOS\UserBundle\FOSUserBundle(),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
diff --git a/app/Resources/views/base.html.twig b/app/Resources/views/base.html.twig
index f961b43..8be9516 100644
--- a/app/Resources/views/base.html.twig
+++ b/app/Resources/views/base.html.twig
@@ -12,6 +12,12 @@
<li><a href="/">home</a></li>
<li><a href="/film">films</a></li>
<li><a href="/acteur">acteurs</a></li>
+ {% if app.user %}
+ <li><a href="/logout">logout</a></li>
+ {% else %}
+ <li><a href="/login">login</a></li>
+ <li><a href="/register">register</a></li>
+ {% endif %}
</ul>
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
diff --git a/app/config/config.yml b/app/config/config.yml
index ed744a3..c6e61d9 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -30,6 +30,8 @@ framework:
assets: ~
php_errors:
log: true
+ templating:
+ engines: ['twig', 'php']
# Twig Configuration
twig:
@@ -65,3 +67,12 @@ swiftmailer:
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
+
+fos_user:
+ db_driver: orm
+ firewall_name: main
+ user_class: AppBundle\Entity\User
+
+ from_email:
+ address: "contact@filmmanager.org"
+ sender_name: "contact"
diff --git a/app/config/routing.yml b/app/config/routing.yml
index 2ec067f..c8716e4 100644
--- a/app/config/routing.yml
+++ b/app/config/routing.yml
@@ -1,3 +1,22 @@
app:
resource: '@AppBundle/Controller/'
type: annotation
+
+fos_user_security:
+ resource: "@FOSUserBundle/Resources/config/routing/security.xml"
+
+fos_user_profile:
+ resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
+ prefix: /profile
+
+fos_user_register:
+ resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
+ prefix: /register
+
+fos_user_resetting:
+ resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
+ prefix: /resetting
+
+fos_user_change_password:
+ resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
+ prefix: /profile
diff --git a/app/config/security.yml b/app/config/security.yml
index 0e0b7cb..a642464 100644
--- a/app/config/security.yml
+++ b/app/config/security.yml
@@ -1,9 +1,17 @@
# 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_ADMI: ROLE_ADMIN
# https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
providers:
+ fos_userbundle:
+ id: fos_user.user_provider.username
in_memory:
memory: ~
@@ -14,7 +22,12 @@ security:
security: false
main:
- anonymous: ~
+ pattern: ^/
+ form_login:
+ provider: fos_userbundle
+ csrf_token_generator: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
+ logout: true
+ anonymous: true
# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
@@ -22,3 +35,9 @@ security:
# 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 }
diff --git a/composer.json b/composer.json
index 322ce39..6586582 100644
--- a/composer.json
+++ b/composer.json
@@ -23,6 +23,7 @@
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
+ "friendsofsymfony/user-bundle": "^2.1",
"incenteev/composer-parameter-handler": "^2.0",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
@@ -31,6 +32,7 @@
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
+ "symfony/templating": "^3.4",
"twig/twig": "^1.0||^2.0"
},
"require-dev": {
diff --git a/composer.lock b/composer.lock
index b9a3bb4..c040e41 100644
--- a/composer.lock
+++ b/composer.lock
@@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
- "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "d78137dd4297a414f03c58b3532a2a72",
+ "content-hash": "f90a517398fc3133b6c7762376b85d2b",
"packages": [
{
"name": "cocur/slugify",
@@ -955,6 +955,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": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
diff --git a/src/AppBundle/Entity/User.php b/src/AppBundle/Entity/User.php
new file mode 100644
index 0000000..4484015
--- /dev/null
+++ b/src/AppBundle/Entity/User.php
@@ -0,0 +1,26 @@
+<?php
+// src/AppBundle/Entity/User.php
+
+namespace AppBundle\Entity;
+
+use FOS\UserBundle\Model\User as BaseUser;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ * @ORM\Table(name="fos_user")
+ */
+class User extends BaseUser
+{
+ /**
+ * @ORM\Id
+ * @ORM\Column(type="integer")
+ * @ORM\GeneratedValue(strategy="AUTO")
+ */
+ protected $id;
+
+ public function __construct()
+ {
+ parent::__construct();
+ }
+}