/**
  * Returns an initialized \Zend_Auth_Adapter_Interface
  *
  * @param \Gems_User_User $user
  * @param string $password
  * @return \Zend_Auth_Adapter_Interface
  */
 public function getAuthAdapter(\Gems_User_User $user, $password)
 {
     $adapter = new \Zend_Auth_Adapter_DbTable($this->db, 'gems__user_passwords', 'gul_login', 'gup_password');
     $pwd_hash = $this->hashPassword($password);
     $select = $adapter->getDbSelect();
     $select->join('gems__user_logins', 'gup_id_user = gul_id_user', array())->where('gul_can_login = 1')->where('gul_id_organization = ?', $user->getBaseOrganizationId());
     $adapter->setIdentity($user->getLoginName())->setCredential($pwd_hash);
     return $adapter;
 }
 /**
  * Sets the user up as a new staff user
  *
  * @param \Gems_User_User $user
  * @param string $password
  */
 protected function makeNewStaffUser(\Gems_User_User $user, $password)
 {
     $staff_id = $user->getUserId();
     $sql = 'SELECT gul_id_user FROM gems__user_logins WHERE gul_can_login = 1 AND gul_login = ? AND gul_id_organization = ?';
     try {
         $user_id = $this->db->fetchOne($sql, array($user->getLoginName(), $user->getBaseOrganizationId()));
         $currentTimestamp = new \MUtil_Db_Expr_CurrentTimestamp();
         // Move to USER_STAFF
         $values['gup_id_user'] = $user_id;
         $values['gup_password'] = $this->hashNewPassword($password);
         $values['gup_reset_key'] = null;
         $values['gup_reset_requested'] = null;
         $values['gup_reset_required'] = 0;
         $values['gup_changed'] = $currentTimestamp;
         $values['gup_changed_by'] = $staff_id;
         $values['gup_created'] = $currentTimestamp;
         $values['gup_created_by'] = $staff_id;
         $this->db->insert('gems__user_passwords', $values);
         // Update user class
         $values = array();
         $values['gul_user_class'] = \Gems_User_UserLoader::USER_STAFF;
         $values['gul_changed'] = $currentTimestamp;
         $values['gul_changed_by'] = $staff_id;
         $this->db->update('gems__user_logins', $values, $this->db->quoteInto('gul_id_user = ?', $user_id));
         // Remove old password
         $values = array();
         $values['gsf_password'] = null;
         $values['gsf_changed'] = $currentTimestamp;
         $values['gsf_changed_by'] = $user_id;
         $this->db->update('gems__staff', $values, $this->db->quoteInto('gsf_id_user = ?', $staff_id));
         $user->refresh(\Gems_User_UserLoader::USER_STAFF);
     } catch (\Zend_Db_Exception $e) {
         \GemsEscort::getInstance()->logger->log($e->getMessage(), \Zend_Log::ERR);
         // Fall through as this does not work if the database upgrade did not run
         // \MUtil_Echo::r($e);
     }
 }
 /**
  * Returns an initialized \Zend_Auth_Adapter_Interface
  *
  * @param \Gems_User_User $user
  * @param string $password
  * @return \Zend_Auth_Adapter_Interface
  */
 public function getAuthAdapter(\Gems_User_User $user, $password)
 {
     //Ok hardcoded for now this needs to be read from the userdefinition
     $configData = $this->loadConfig(array('gor_id_organization' => $user->getBaseOrganizationId()));
     $config = array('ip' => $configData['grcfg_ip'], 'authenticationport' => $configData['grcfg_port'], 'sharedsecret' => $configData['grcfg_secret']);
     //Unset empty
     foreach ($config as $key => $value) {
         if (empty($value)) {
             unset($config[$key]);
         }
     }
     $adapter = new \Gems_User_Adapter_Radius($config);
     $adapter->setIdentity($user->getLoginName())->setCredential($password);
     return $adapter;
 }