_init('auctaneshipstation/user'); } public function load($user, $field=null) { if (is_object($user)) { return parent::load($user->getUserId(), 'admin_user_id'); } else { return parent::load($user, $field); } } /** * Perform authentication with remote server * @return unknown */ public function authenticate() { $client = new Varien_Http_Client(Mage::getStoreConfig('auctane/shipstation/authenticate_url'), array( 'storeresponse' => true )); $request = ''; $client->setRawData($request, 'text/xml') ->request(Varien_Http_Client::POST); $response = $client->getLastResponse(); if ($response->isError()) { throw new Exception($response->getMessage()); } $xml = new SimpleXMLElement($response->getBody()); if ($xml['Success'] != 'true') { if ($xml['ErrorMessage']) throw new Exception($xml['ErrorMessage']); else throw new Exception(Mage::helper('auctaneshipstation')->__('Unable to authenticate')); } $this->setAuthToken($xml['AuthToken']) ->setAuthUrl($xml['AuthUrl']); if (!$this->hasAdminUserId()) { $user = Mage::helper('auctaneshipstation')->getAdminUser(); if ($user) { $this->setAdminUserId($user->getUserId()); } } return $this; } // Shortcuts for encrypted field public function getAuthToken() { return Mage::helper('auctaneshipstation')->decrypt($this->getAuthTokenEnc()); } public function setAuthToken($token) { return $this->setAuthTokenEnc(Mage::helper('auctaneshipstation')->encrypt($token)); } public function hasAuthToken() { return $this->hasAuthTokenEnc(); } public function unsAuthToken() { return $this->unsAuthTokenEnc(); } }