Skip to main content

How to Setup Zfcuser , ZfcUserDoctrineORM , BjyAuthorize in ZF2


STEP 1 : Install All module by composer .

file name composer.json 
{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "~2.3",
        "doctrine/doctrine-orm-module": "0.7.*",
        "zf-commons/zfc-user": "~0.1",
        "bjyoungblood/bjy-authorize": "~1.1",
        "zf-commons/zfc-user-doctrine-orm": "~0.1"
    }
}
run in terminal : "composer update" or "composer.phar update"


STEP-2:  Database details 

file : config/autoload/doctrine.local.php 
return array(
  'doctrine' => array(
    'connection' => array(
      'orm_default' => array(
        'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
        'params' => array(
          'host'     => 'localhost',
          'port'     => '3306',
          'user'     => '************',
          'password' => '**********',
          'dbname'   => 'zf2demo',
)))));




STEP-3: update database  run doctrine command  or run sql in Database Table Schema are. 

URL : ZFCuser
URL : bjyoungblood


STEP-4 : ADD Module to your config file :

file name : config/application.config.php
you module should section looks like this
 'modules' => array(
         'application',
         'DoctrineModule',
         'DoctrineORMModule',
         'ZfcBase',
         'ZfcUser',
         'ZfcUserDoctrineORM',
         'BjyAuthorize'
    ),

STEP -5 : NOW CHECK TEST ZFCUSER WORKING OR NOT.


in browser : /user/login
if everything is right then you will see login screen .

STEP-6 setup for BjyAuthorize.

create config file for BjyAuthorize in config/autoload location
file name: config/autoload/bjyauthorize.global.php

and put

<?php
return array(
'bjyauthorize' => array(
// set the 'guest' role as default (must be defined in a role provider)
'default_role' => 'guest',
/* this module uses a meta-role that inherits from any roles that should
* be applied to the active user. the identity provider tells us which
* roles the "identity role" should inherit from.
*
* for ZfcUser, this will be your default identity provider
*/
'identity_provider' => 'BjyAuthorize\Provider\Identity\ZfcUserZendDb',
/* role providers simply provide a list of roles that should be inserted
* into the Zend\Acl instance. the module comes with two providers, one
* to specify roles in a config file and one to load roles using a
* Zend\Db adapter.
*/
'role_providers' => array(
/* here, 'guest' and 'user are defined as top-level roles, with
* 'admin' inheriting from user
*/
'BjyAuthorize\Provider\Role\Config' => array(
'guest' => array(),
'user' => array('children' => array(
'admin' => array(),
)),
),
// this will load roles from the user_role table in a database
// format: user_role(role_id(varchar), parent(varchar))
'BjyAuthorize\Provider\Role\ZendDb' => array(
'table' => 'user_role',
'role_id_field' => 'role_id',
'parent_role_field' => 'parent',
),
),
// resource providers provide a list of resources that will be tracked
// in the ACL. like roles, they can be hierarchical
'resource_providers' => array(
'BjyAuthorize\Provider\Resource\Config' => array(
'admin' => array(),
//'pants' => array(),
),
),
/* rules can be specified here with the format:
* array(roles (array), resource, [privilege (array|string), assertion])
* assertions will be loaded using the service manager and must implement
* Zend\Acl\Assertion\AssertionInterface.
* *if you use assertions, define them using the service manager!*
*/
'rule_providers' => array(
'BjyAuthorize\Provider\Rule\Config' => array(
'allow' => array(
// allow guests and users (and admins, through inheritance)
// the "wear" privilege on the resource "pants"
//array(array('guest', 'user'), 'pants', 'wear'),
array(array('admin'), 'admin'),
),
// Don't mix allow/deny rules if you are using role inheritance.
// There are some weird bugs.
'deny' => array(
// ...
),
),
),
/* Currently, only controller and route guards exist
*/
'guards' => array(
/* If this guard is specified here (i.e. it is enabled), it will block
* access to all controllers and actions unless they are specified here.
* You may omit the 'action' index to allow access to the entire controller
*/
'BjyAuthorize\Guard\Controller' => array(
//array('controller' => 'index', 'action' => 'index', 'roles' => array('guest','user')),
//array('controller' => 'index', 'action' => 'stuff', 'roles' => array('user')),
array('controller' => 'zfcuser', 'roles' => array()),
array('controller' => 'Application\Controller\Index', 'roles' => array('guest', 'user')),
array('controller' => 'Admin\Controller\Index', 'roles' => array('admin')),
array('controller' => 'Album\Controller\Album', 'roles' => array('admin')),
array('controller' => 'Form\Controller\Index', 'roles' => array('admin')),
),
/* If this guard is specified here (i.e. it is enabled), it will block
* access to all routes unless they are specified here.
*/
'BjyAuthorize\Guard\Route' => array(
array('route' => 'zfcuser', 'roles' => array('user')),
array('route' => 'zfcuser/logout', 'roles' => array('user')),
array('route' => 'zfcuser/login', 'roles' => array('guest')),
array('route' => 'zfcuser/register', 'roles' => array('guest')),
array('route' => 'zfcuser/changepassword', 'roles' => array('user')),
array('route' => 'zfcuser/changeemail', 'roles' => array('user')),
// Below is the default index action used by the [ZendSkeletonApplication](https://github.com/zendframework/ZendSkeletonApplication)
array('route' => 'home', 'roles' => array('guest', 'user')),
array('route' => 'about', 'roles' => array('guest', 'user')),
array('route' => 'admin', 'roles' => array('admin')),
array('route' => 'admin/users', 'roles' => array('admin')),
array('route' => 'album', 'roles' => array('admin')),
array('route' => 'form', 'roles' => array('admin')),
array('route' => 'form/create','roles' => array('admin')),
array('route' => 'form/input','roles' => array('admin')),
array('route' => 'form/paragraph','roles' => array('admin')),
),
),
),
);


edit BjyAuthorize\Guard\Controller and BjyAuthorize\Guard\Route with your controller and route
please check this url : https://github.com/patrioticcow/Zend-Project


STEP-7 test your application

 




Comments

Popular posts from this blog

HTML Emailing in ZF2

<?php namespace Application\Model; use Zend\Mail\Message; use Zend\Mime\Message as MimeMessage; use Zend\Mime\Part as MimePart; use Zend\Mail\Transport\Sendmail as SendmailTransport; use Zend\Mail\Transport\Smtp as SmtpTransport; use Zend\Mail\Transport\SmtpOptions; use Zend\View\Renderer\PhpRenderer; use Zend\View\Resolver\TemplatePathStack; use Zend\View\Model\ViewModel; use Zend\View\Model\ModelInterface; class ApiEmail extends ApiInterface {    protected $From = "XXXXX@gmail.com";    protected $FromName = "XXXX";    protected $To = "" ;    protected $Subject = "" ;    protected $Body = "" ;    protected $Cc = "XXXXXX@gmail.com";    protected $Bcc = "XXXXX@gmail.com" ;    protected $ReplyTo = "XXXX@gmail.com" ;    protected $Sender = "" ;    protected $Encoding = "UTF-8" ;    protected $MESSAGE ; // getter setter ...

What are the advantages and disadvantages of using zsh instead of bash (or other shells)?

Everything y ou kno w from bash  still  applies, but zsh does a bunch of other useful things.  I  know that I use only a small subset of them, but t hese are especially useful for me: Extended globbing: For example,  *(.)  matches only regular files, not directories, whereas  a*z(/)  matches directories whose names start with  a  and end with  z . There are a bunch of other things, such as  **  as described by  Ole Tange . Inline glob expansion: For example, type  rm *.pdf  and then hit tab. The glob  *.pdf  will expand inline into the list of .pdf files, which means you can change the result of the expansion, perhaps by removing from the command the name of one particular file you don’t want to  rm . Interactive path expansion: Type  cd /u/l/b  and hit tab. If there is only one existing path each of whose components start...