TPUserBundle
FOSUserBundle extension with admin gui, (*1)
Installation
Add TPUserBundle in your composer.json, TPUserBundle require also FOSUserBundle:, (*2)
{
"require": {
"friendsofsymfony/user-bundle": "~2.0@dev",
"twinpeaks/user-bundle": "dev-master"
}
}
Enable the bundle in the kernel:, (*3)
``` php
// app/AppKernel.php, (*4)
public function registerBundles()
{
$bundles = array(
// ...
new FOS\UserBundle\FOSUserBundle(),
new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(),
new Twinpeaks\UserBundle\TPUserBundle(),
);
}, (*5)
Configure your application's security.yml
``` yaml
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_USER: ROLE_USER
ROLE_ADMIN: [ROLE_USER]
ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
fos_userbundle:
id: fos_user.user_provider.username
in_memory:
memory:
users:
user: { password: user, roles: [ 'ROLE_USER' ] }
admin: { password: admin, roles: [ 'ROLE_ADMIN' ] }
firewalls:
main:
pattern: ^/
form_login:
#login_path: /
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
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 }
Configure the FOSUserBundle, (*6)
``` yaml, (*7)
app/config/config.yml
FOSUser Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: Twinpeaks\UserBundle\Entity\User
group:
group_class: Twinpeaks\UserBundle\Entity\UserGroup, (*8)
Add TPUserBundle to assetic
``` yaml
# app/config/config.yml
bundles: [ "TPUserBundle" ]
Import routing files
``` yaml, (*9)
app/config/routing.yml
twinpeaks_user:
resource: "@TPUserBundle/Resources/config/routing.xml"
prefix: /admin, (*10)
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml", (*11)
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile, (*12)
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register, (*13)
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting, (*14)
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile, (*15)
Update the schema database
``` php
#console
php app/console doctrine:schema:update --force
Create user
``` php, (*16)
console
php app/console fos:user:create, (*17)
Promote user to SuperAdmin
Create user
``` php
#console
php app/console fos:user:promote username ROLE_SUPER_ADMIN