How to check is authenticated user (Zend FW) authorized in some JQuery function?

258 Views Asked by At

There is a user info in the user's area (web app use Zend Framework + Jquery). When I logged in as USER_1, I can edit USER_1 info of course, but when I in the new browser's window logged out as USER_1 and logged in as USER_2 and then back to window with opened USER_1 info, I can edit USER_1 info, but logged as USER_2.

The EDIT button code in view:

<div class="editbutton" id="switchbutton<?php echo $user['id']; ?>" onclick="showBody(<?php echo $user['id']; ?>)">EDIT USER</div>

showBody function in separate .js file:

showBody = function(id) {
  if(active_id == id){
    $("#user-body-" + active_id).slideUp(250);
    active_id = 0;
    $("#switchbutton" + id).text("EDIT USER");
    return;
  }
  if(active_id == 0) $("#user-body-" + id).slideDown(300);
  else {
    $("#user-body-" + active_id).slideUp(250, function() {
      $("#user-body-" + id).slideDown(300);
    });
  }
  $("#switchbutton" + active_id).text("EDIT USER");
  $("#switchbutton" + id).text("CANCEL");
  active_id = id;
};

user-body is form with text fields to edit

How can get from within showBody function current authenticated user to compare with active_id and if are equal pass the action if not redirect to some index/action?

1

There are 1 best solutions below

0
On

You can always use Zend_Auth

    // Get Zend_Auth instance
    $auth = Zend_Auth::getInstance();

    // Has user been authenticated
    if($auth->hasIdentity())
    {
      // If so, set user identity
      $this->view->identity = $auth->getIdentity();

      switch($this->view->identity->id)
      {
       case 1:
       $this->view->headScript()->appendFile(somefile.js');                 
      }