示例#1
0
 public function myAccountAction()
 {
     $identity = (array) Zend_Auth::getInstance()->getIdentity();
     switch ($identity['role']) {
         case Table_Abstract::ROLE_CENTER:
             $t = new Table_Centers();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_COMPANY:
             $t = new Table_Companies();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_STAFF:
             $t = new Table_Users();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_CLIENT:
             $t = new Table_Users();
             $a = $t->getById($identity['id'])->toArray();
             break;
         case Table_Abstract::ROLE_APPROVER:
             $t = new Table_Approvers();
             $a = $t->getById($identity['id'])->toArray();
             break;
     }
     $this->view->assign('a', $a);
 }
示例#2
0
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
     $errMessage = "Email / Username or password incorrect";
     // Log in by client
     // Log in by client
     // Log in by client
     if ($this->role == 'client') {
         $usersTable = new Table_Users();
         $user = $usersTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($user)) {
             if ($user->getStatus() == Table_Users::STATUS_ACTIVE && $user->getRole() == 'client') {
                 // convert to std-object
                 $oUser = (object) $user->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($user->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($user->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
         // Log in by admin
         // Log in by admin
         // Log in by admin
     } elseif ($this->role == 'staff') {
         $usersTable = new Table_Users();
         $user = $usersTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($user)) {
             if ($user->getStatus() == Table_Users::STATUS_ACTIVE && $user->getRole() == 'staff') {
                 // convert to std-object
                 $oUser = (object) $user->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($user->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($user->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
         // Log in by centers
         // Log in by centers
         // Log in by centers
     } elseif ($this->role == 'center') {
         $centersTable = new Table_Centers();
         $center = $centersTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($center)) {
             if ($center->getStatus() == Table_Users::STATUS_ACTIVE) {
                 // convert to std-object
                 $oUser = (object) $center->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($center->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($center->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
         // Log in by companies
         // Log in by companies
         // Log in by companies
     } elseif ($this->role == 'company') {
         $companiesTable = new Table_Companies();
         $company = $companiesTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($company)) {
             if ($company->getStatus() == Table_Users::STATUS_ACTIVE && $company->getWithCheck() == 1) {
                 // convert to std-object
                 $oUser = (object) $company->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($company->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($company->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             } elseif ($company->getWithCheck() == 0) {
                 $errMessage = "Your account has been set to no checking orders / buybacks";
             }
         }
         // Log in by approvers
         // Log in by approvers
         // Log in by approvers
     } elseif ($this->role == 'approver') {
         $approversTable = new Table_Approvers();
         $approver = $approversTable->getAuthUsernamePassword($this->username, $this->password);
         if (!is_null($approver)) {
             if ($approver->getStatus() == Table_Users::STATUS_ACTIVE) {
                 // convert to std-object
                 $oUser = (object) $approver->toArray();
                 $result = new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $oUser, array());
                 return $result;
             }
             if ($approver->getStatus() == Table_Users::STATUS_INACTIVE) {
                 $code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
                 $errMessage = "Your account is currently inactive. Please contact us for detail";
             } elseif ($approver->getStatus() == Table_Users::STATUS_DELETED) {
                 $errMessage = "Your account has been deleted. Please contact us for detail";
             }
         }
     }
     $result = new Zend_Auth_Result($code, null, array($errMessage));
     return $result;
 }