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    public fun

How to setup django | django installation ubuntu

Introduction to Django 1.     High level web framework 1.     Basic modules, classes, and tools to quickly develop and deploy web apps 2.     Contains an ORM (Object-Relational Mapper) that allows for the use of standard Python language syntax when interfacing with a back-end database. 1.     Developer need not learn SQL, DDL, etc! 3.     Provides a template framework that allows HTML, XML, and other “documents” to be converted into “templates”, which can then be converted to “output” via a wide range of substitution techniques. 4.     Elegant URL support (fancy, beautiful URL's, no “?blah=blah”, etc.) 5.     Multi-lingual 2.     Fast and easy to use, robust, flexible, and lots of contributed components available! 1.     Built in administrative interface to manage data models. 2.     Built-in authentication/access control components 3.     Contributed Installing & Configuring Django Components 1.     Django can be downloaded from http://w

How to start working with Django web framework

 Django is a powerful web framework for Python that makes it easy to build web applications quickly. Here are some steps you can follow to start learning Django programming: Install Python: Django requires Python to be installed on your machine. If you don ' t already have Python installed, you can download it from the official Python website (https://www.python.org/downloads/). Install Django: Once you have Python installed, you can use the pip package manager to install Django. Open a terminal or command prompt and type the following command: pip install django Create a new Django project: To create a new Django project, open a terminal or command prompt and navigate to the directory where you want to store your project. Then run the following command: django - admin startproject myproject Replace myproject with the name you want to give to your project. This will create a new Django project with the specified name in the current directory. Run the development