/** * Deletes a seller API key. * * @param int $id API key. * * @return void */ public function action_delete($id = null) { if (!$id) { throw new HttpNotFoundException(); } $key = Service_Api_Key::find_one($id); if (!$key || $key->seller != Seller::active()) { throw new HttpNotFoundException(); } if (!Service_Api_Key::delete($key)) { Session::set_alert('error', 'There was an error removing the API key.'); } else { Session::set_alert('success', 'The API key has been removed.'); } Response::redirect('settings/api'); }
/** * Loads a seller based on session. * * @return void */ public static function load() { Config::load('api', true); $seller_id = Session::get(self::$namespace . '.id'); if ($seller_id) { $seller = Service_Seller::find_one($seller_id); } elseif ($api_key = Input::param('api_key', Config::get('api.key'))) { $api_key = Service_Api_Key::find_one(array('key' => $api_key)); $seller = $api_key->seller; } else { $seller = Service_Seller::find_one(); } if (!$seller || !$seller->active()) { return false; } self::set($seller); return true; }
/** * Checks for api key authentication. * * @return bool */ protected function _prepare_key_auth() { // Skip auth for front-end interface. if (\Seller::active()) { return true; } \Config::load('api', true); $api_key = \Input::param('api_key', \Config::get('api.key')); if (!$api_key) { return false; } $api_key = \Service_Api_Key::find_one(array('key' => $api_key)); if (!$api_key) { return false; } if ($api_key->seller) { \Seller::set($api_key->seller); } return true; }