/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $id = $request->route()->getParameter('snowfireAppId'); $accountsRepository = app()->make('\\Snowfire\\App\\Repositories\\AccountsRepository'); $app = $accountsRepository->getById($id); if (!\Snowfire::authorized($id)) { if ($app) { return \Redirect::to($app->site_url . 'a;applications/application/moduleTab/' . \Snowfire::parameter('id')); } else { return \Response::make('Not authorized, please login again through Snowfire', 403); } } app()->make('view')->composer('*', function ($view) use($app) { $view->snowfire = $app; }); app()->instance('snowfire', $app); return $next($request); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!\Snowfire::isRequestFromSnowfire() && !config('snowfire.debug')) { return \Response::make('Please request this url from a Snowfire component', 500); } $accountsRepository = app()->make('\\Snowfire\\App\\Repositories\\AccountsRepository'); if (config('snowfire.debug')) { // In debug mode, use the first account id $app = $accountsRepository->first(); } else { // Load Snowfire account based on URL parse_str($request->getQueryString(), $query); $app = $accountsRepository->getByKey($query['key']); } app()->make('view')->composer('*', function ($view) use($app) { $view->snowfire = $app; }); app()->instance('snowfire', $app); return $next($request); }
/** * Get singleton instance * @return Snowfire */ public static function &getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
return Response::make(Snowfire::response(true), 200, ['content-type' => 'text/xml']); }]); Route::post('/uninstall', ['as' => 'snowfire.uninstall', function () { //Log::info('sfapp/uninstall', [$_GET, $_POST]); $account = \Snowfire\App\Storage\AccountStorage::whereAppKey(Request::get('appKey'))->first(); $account->state = 'UNINSTALLED'; $account->save(); return Response::make(Snowfire::response(true), 200, ['content-type' => 'text/xml']); }]); // Admin tab Route::get('/tab-proxy', ['as' => 'snowfire.tab', function () { $accountsRepository = app('Snowfire\\App\\Repositories\\AccountsRepository'); $appKey = Request::get('snowfireAppKey'); $app = $accountsRepository->getByKey($appKey); if (!$app) { return Response::make('Invalid Snowfire app key', 403); } Snowfire::login(Request::get('snowfireAppKey'), Request::get('snowfireUserKey')); return Redirect::route(Snowfire::parameter('tabRedirectRoute'), [$app->id]); }]); // Proxy an URL to send a user between core domain and snowfire loaded app Route::get('snowfire/proxy/{hash}', ['as' => 'snowfire.proxy', function ($hash) { $proxy = \Snowfire\App\Proxy::getByHash($hash); Auth::loginUsingId($proxy->user_id); // Save to session, so we know how to redirect back to the app via Snowfire when we're done \Snowfire\App\Proxy::saveInSession($hash); // Cleanup expired hashes \Snowfire\App\Proxy::cleanup(); return Redirect::to($proxy->to_url); }]); });