70508

Zend Framework2 using Zfcuser & Bjyauthorize routing

Question:

I'm a beginer zend framework programmer. I did use ZfcUser for authentification and Bjyauthorize for authorization. I have to type of users : normal users and administrator . So what i want to do is to route the user to page A and admin to page B after authentification . In the Zfcuser configuation file there not this possibility we have just this line

'logout_redirect_route' => 'zfcuser/login',

how can do specify a diffrent route for my differents users?

Answer1:

To me your problem has nothing to do with ZfcUser or BjyAuthorize: Just let the user and the admin go inside your controller and there you can dispatch them depending on the user role.

return $this->forward()->dispatch('MyModule\Controller\Index', array('action'=>'PageB'));

Answer2:

Suppose you have an 'admin' role in bjyauthorize that you want to redirect to another route.

In your loginAction replace the code:

if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) { return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute()); }

with this code:

if ($this->zfcUserAuthentication()->getAuthService()->hasIdentity()) { $roles = $this->serviceLocator->get('BjyAuthorize\Provider\Identity\ProviderInterface')->getIdentityRoles(); if (in_array('admin',$roles)) { return $this->redirect()->toRoute('admin_route'); } else { return $this->redirect()->toRoute('user_route'); } }

Recommend

  • Extending ZfcUsers UserController
  • Rewriting url to hide index.php and to make query nice
  • Setting existing SSL certificate on an IIS website which uses hostheader
  • Set LayoutParams on parentless LinearLayout
  • How to attach custom styles into zf2 forms
  • Spring integration Configuration to wait for outcome of async batch job
  • How do CL commands build their exact parameter lists?
  • Gnuplot multiplot: Convenient method for creating more complex layouts
  • Using bitbake is it possible to have a different do_install for a package based on the target image?
  • Symfony2 plaintext users don't work
  • Counting Treaps
  • Why is django manage.py syncdb failing to create new columns on my development server?
  • How do I check if System::Collections:ArrayList is empty / nullptr / null?
  • Changing Jupyter Notebook start up folder by modifying “start in” not working any more
  • Configure nginx to return different files to different authenticated users with the same URI
  • How to override value that appears in a dropdown in the rails_admin gem
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Using $this when not in object context
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Perl system calls when running as another user using sudo
  • Why winpcap requires both .lib and .dll to run?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Free memory of cv::Mat loaded using FileStorage API
  • Trying to get generic when generic is not available
  • coudnt use logback because of log4j
  • Getting Messege Twice Using IMvxMessenger
  • Change div Background jquery
  • How to get Windows thread pool to call class member function?
  • Bitwise OR returns boolean when one of operands is nil
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?