0

I'm making web app that will be fully based on Ajax requests. As I understand the only way to achieve that goal is to send identity and password with every Ajax request or am I wrong? I'd like to use ZfcUser to perform actions connected with register, login and logout but if I'm calling that on server side: $this->getServiceLocator()->get('controllerPluginManager')->get('zfcUserAuthentication')->getAuthService()->getIdentity(); I always receive last logged user.

Is it possible to handle multiple users at once using ZfcUser plugin (or maybe simply Zend 2)? Can Zfcuser remember in any data structure all users that are actually logged in?

Stephane Rolland
  • 38,876
  • 35
  • 121
  • 169

1 Answers1

0

If you are in a controller you can use $this->ZfcUserAuthentication()->getIdentity() to get the identity. If you are anywhere else, use the servicemanager/locator to get 'zfcuser_auth_service' which you then can use to call getIdentity(). The Auth Service will give you the user based on session, so you should never users from another session. Doesn't matter if you use ajax or not.

Danielss89
  • 863
  • 1
  • 11
  • 17
  • Unfortunately it doesn't work in my case. Let me explain my exact scenario: I've got MAMP server on Mac OS with my web app. I'm opening it via url from CodeKit app. 1. Log in on laptop (ajax request) 2. Check on laptop that $this->ZfcUserAuthentication()->getIdentity() returns my correct user data (ajax request) 3. Check it on mobile phone using url from CodeKit. $this->ZfcUserAuthentication()->getIdentity() here also return the same user data but I've never logged any user on mobile phone. What can be a problem here? I guess that when I go to my app on mobile phone it shouldn't be any user? – SebastianCrow Oct 04 '14 at 09:34
  • The only thing I am thinking right now about your "bug" is the following: The problem is you have a generic entry point with Authentication for one user whatever the way to handle your requests to your application. That's why you are logged in when you change your client. Danielss89 has said the right method to configure your Authentication as you must do in this use-case. – BendaThierry.com Feb 29 '16 at 12:19