Skip to content

Commit

Permalink
Merge pull request #1 from BartoszSiejka/registration-and-login
Browse files Browse the repository at this point in the history
login and register
  • Loading branch information
Paweł Jędrzejewski committed Nov 7, 2014
2 parents e1928bf + 68d5b8d commit 331d20d
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@
/vendor/
/bin/
/composer.phar

2 changes: 2 additions & 0 deletions app/AppKernel.php
Expand Up @@ -16,6 +16,8 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new FOS\UserBundle\FOSUserBundle(),
new App\Bundle\CoreBundle\AppCoreBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
6 changes: 6 additions & 0 deletions app/config/config.yml
Expand Up @@ -70,3 +70,9 @@ swiftmailer:
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }

# FOSUserBundle conf
fos_user:
db_driver: orm
firewall_name: main
user_class: App\Bundle\CoreBundle\Entity\User
22 changes: 22 additions & 0 deletions app/config/routing.yml
@@ -0,0 +1,22 @@
app_core:
resource: "@AppCoreBundle/Resources/config/routing.yml"
prefix: /

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
28 changes: 26 additions & 2 deletions app/config/security.yml
@@ -1,12 +1,36 @@
security:


providers:
in_memory:
memory: ~
fos_userbundle:
id: fos_user.user_provider.username

encoders:
FOS\UserBundle\Model\UserInterface: sha512

firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
login_path: /login
check_path: /login_check
csrf_provider: form.csrf_provider
logout: true
anonymous: true
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false

default:
anonymous: ~

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 }

role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -17,7 +17,8 @@
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0",
"sensio/framework-extra-bundle": "~3.0",
"incenteev/composer-parameter-handler": "~2.0"
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "*"
},
"require-dev": {
"sensio/generator-bundle": "~2.3"
Expand Down
69 changes: 68 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/App/Bundle/CoreBundle/AppCoreBundle.php
@@ -0,0 +1,9 @@
<?php

namespace App\Bundle\CoreBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AppCoreBundle extends Bundle
{
}
13 changes: 13 additions & 0 deletions src/App/Bundle/CoreBundle/Controller/DefaultController.php
@@ -0,0 +1,13 @@
<?php

namespace App\Bundle\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
public function indexAction($name)
{
return $this->render('AppCoreBundle:Default:index.html.twig', array('name' => $name));
}
}
28 changes: 28 additions & 0 deletions src/App/Bundle/CoreBundle/DependencyInjection/AppCoreExtension.php
@@ -0,0 +1,28 @@
<?php

namespace App\Bundle\CoreBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class AppCoreExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
29 changes: 29 additions & 0 deletions src/App/Bundle/CoreBundle/DependencyInjection/Configuration.php
@@ -0,0 +1,29 @@
<?php

namespace App\Bundle\CoreBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('app_core');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
26 changes: 26 additions & 0 deletions src/App/Bundle/CoreBundle/Entity/User.php
@@ -0,0 +1,26 @@
<?php

namespace App\Bundle\CoreBundle\Entity;

use FOS\UserBundle\Entity\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();
// your own logic
}
}
3 changes: 3 additions & 0 deletions src/App/Bundle/CoreBundle/Resources/config/routing.yml
@@ -0,0 +1,3 @@
app_core_homepage:
path: /hello/{name}
defaults: { _controller: AppCoreBundle:Default:index }
4 changes: 4 additions & 0 deletions src/App/Bundle/CoreBundle/Resources/config/services.yml
@@ -0,0 +1,4 @@
services:
# app_core.example:
# class: App\Bundle\CoreBundle\Example
# arguments: [@service_id, "plain_value", %parameter%]
Empty file.
11 changes: 11 additions & 0 deletions src/App/Bundle/CoreBundle/Resources/translations/messages.fr.xlf
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Symfony2 is great</source>
<target>J'aime Symfony2</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -0,0 +1 @@
Hello {{ name }}!
@@ -0,0 +1,17 @@
<?php

namespace App\Bundle\CoreBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();

$crawler = $client->request('GET', '/hello/Fabien');

$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
}
}

0 comments on commit 331d20d

Please sign in to comment.