Beispiel #1
0
 public static function isCustomer($identity)
 {
     $auth = Zend_Auth::getInstance();
     if ($identity) {
         // get username
         $identity = $auth->getIdentity();
         $username = $identity->username;
         // get user ID
         $userModel = new TBB_Model_Users();
         $userID = $userModel->getUserIDByUsername($username);
         // get user row
         $user = $userModel->find($userID)->current();
         // get roles of the user
         $roles = $userModel->getRolesOfUser($userID);
         // check if the user is customer
         $roleModel = new TBB_Model_Role();
         $customerRoleID = $roleModel->getCustomerRoleID();
         foreach ($roles as $role) {
             if ($role['role_id'] == $customerRoleID) {
                 // return customer ID please
                 return $user['customer_id'];
             }
         }
         return null;
     }
     throw new Exception('There is no identity.');
 }
Beispiel #2
0
 /**
  * Authenticate the user logged in
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     try {
         $userModel = new TBB_Model_Users();
         $this->_user = $userModel->authenticate($this->_username, $this->_password);
         return $this->_createResult(Zend_Auth_Result::SUCCESS);
     } catch (Exception $e) {
         if ($e->getMessage() == TBB_Model_Users::WRONG_PW) {
             return $this->_createResult(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(self::BAD_PW_MSG));
         }
         if ($e->getMessage() == TBB_Model_Users::NOT_FOUND) {
             return $this->_createResult(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND, array(self::NOT_FOUND_MSG));
         }
     }
 }
Beispiel #3
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $acl = new TBB_Acl();
     // customer can have account or have no account
     $roles = array();
     $auth = Zend_Auth::getInstance();
     // bug here, comment this if block to enable jquery capability T____T
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         $username = $identity->username;
         $userModel = new TBB_Model_Users();
         $userID = $userModel->getUserIDByUsername($username);
         $roles = $userModel->getRolesOfUser($userID);
     }
     // get module, controller and action names
     $module = $request->module;
     $controller = $request->controller;
     $action = $request->action;
     $resource = $module . ':' . $controller;
     if (!$acl->has($resource)) {
         $resource = $module;
     }
     if (empty($roles)) {
         $roles[] = array('role_name' => 'customer');
     }
     $allowed = false;
     foreach ($roles as $role) {
         $allowed = $acl->isAllowed($role['role_name'], $resource, $action);
         if ($allowed) {
             if ($role['role_name'] == 'admin') {
                 break;
                 // important break
             }
         }
     }
     // end foreach
     // if the user hasn't logged in, send them to 'noauth' page.
     if (!$allowed) {
         $request->setModuleName($module)->setControllerName('error')->setActionName('noauth');
     }
 }
Beispiel #4
0
 public function panelLink($moduleName = 'customer')
 {
     $panelLink = "";
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $identity = $auth->getIdentity();
         $username = $identity->username;
         $userModel = new TBB_Model_Users();
         $userID = $userModel->getUserIDByUsername($username);
         if ($userModel->isAdminUser($userID)) {
             if ($moduleName == 'customer') {
                 $panelLink = '<a class="span-4" href="admin/">Admin Panel</a>';
             } else {
                 if ($moduleName == 'admin') {
                     $panelLink = '<a class="span-4" href="/">Homepage</a>';
                 }
             }
         }
     }
     return $panelLink;
 }