Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,23 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "~5.0"
"php": "^8.2",
"illuminate/support": "^12.0"
},
"autoload": {
"classmap": [
"src/migrations"
],
"psr-0": {
"Snowfire\\App\\": "src/"
"psr-4": {
"Snowfire\\App\\": "src/Snowfire/App/"
}
},
"minimum-stability": "stable"
"minimum-stability": "stable",
"extra": {
"laravel": {
"providers": [
"Snowfire\\App\\SnowfireServiceProvider"
]
}
}
}
32 changes: 27 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
## Snowfire App

This packages makes it possible to connect your Laravel app to Snowfire.
This package makes it possible to connect your Laravel app to Snowfire.

## Laravel Compatibility

This package is compatible with Laravel 5 through Laravel 12.

## Install the package

Add this to your composer.json

"snowfire/snowfire-app": "dev-master"
```json
"snowfire/snowfire-app": "dev-master"
```

Or install via Composer:

```bash
composer require snowfire/snowfire-app
```

### Laravel 5

Add this to your service providers in `config/app.php`

'Snowfire\App\SnowfireServiceProvider'
```php
'Snowfire\App\SnowfireServiceProvider'
```

### Laravel 6+

Service providers are auto-discovered in Laravel 6+.

Add this to your route middlewares in `app/Http/Kernel.php`

'snowfire' => 'Snowfire\App\Middleware\SnowfireMiddleware',
'snowfireAdmin' => 'Snowfire\App\Middleware\SnowfireAdminMiddleware',
```php
'snowfire' => \Snowfire\App\Middleware\SnowfireMiddleware::class,
'snowfireAdmin' => \Snowfire\App\Middleware\SnowfireAdminMiddleware::class,
```

Publish the config file

Expand Down
18 changes: 12 additions & 6 deletions src/Snowfire/App/Middleware/SnowfireAdminMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php namespace Snowfire\App\Middleware;
<?php

namespace Snowfire\App\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Redirect;
use Snowfire\App\Facades\Snowfire;

class SnowfireAdminMiddleware {

Expand All @@ -11,17 +17,17 @@ class SnowfireAdminMiddleware {
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next)
{
$id = $request->route()->getParameter('snowfireAppId');
$id = $request->route()->parameter('snowfireAppId');
$accountsRepository = app()->make('\Snowfire\App\Repositories\AccountsRepository');
$app = $accountsRepository->getById($id);

if ( ! \Snowfire::authorized($id)) {
if ( ! Snowfire::authorized($id)) {
if ($app) {
return \Redirect::to($app->site_url . 'a;applications/application/moduleTab/' . \Snowfire::parameter('id'));
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);
return Response::make('Not authorized, please login again through Snowfire', 403);
}
}

Expand Down
16 changes: 11 additions & 5 deletions src/Snowfire/App/Middleware/SnowfireMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php namespace Snowfire\App\Middleware;
<?php

namespace Snowfire\App\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Config;
use Snowfire\App\Facades\Snowfire;

class SnowfireMiddleware {

Expand All @@ -11,15 +17,15 @@ class SnowfireMiddleware {
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
public function handle(Request $request, Closure $next)
{
if ( ! \Snowfire::isRequestFromSnowfire() && ! config('snowfire.debug')) {
return \Response::make('Please request this url from a Snowfire component', 500);
if ( ! Snowfire::isRequestFromSnowfire() && ! Config::get('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')) {
if (Config::get('snowfire.debug')) {

// In debug mode, use the first account id
$app = $accountsRepository->first();
Expand Down
21 changes: 13 additions & 8 deletions src/Snowfire/App/SnowfireServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php namespace Snowfire\App;
<?php

namespace Snowfire\App;

use Illuminate\Support\ServiceProvider;
use Config;
use Illuminate\Support\Facades\Config;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Facades\Route;

class SnowfireServiceProvider extends ServiceProvider {

Expand All @@ -20,15 +23,17 @@ class SnowfireServiceProvider extends ServiceProvider {
*/
public function boot()
{
include __DIR__ . '/../../routes.php';
$this->loadRoutesFrom(__DIR__ . '/../../routes.php');

// Config publishing
$this->publishes([
__DIR__ . '/../../config/snowfire.php' => config_path('snowfire.php'),
]);
], 'snowfire-config');

// Migrations publishing
$this->publishes([
__DIR__.'/../../migrations/' => base_path('/database/migrations')
], 'migrations');
__DIR__.'/../../migrations/' => database_path('migrations')
], 'snowfire-migrations');
}

/**
Expand All @@ -42,7 +47,7 @@ public function register()
__DIR__ . '/../../config/snowfire.php', 'snowfire'
);

$this->app['snowfire'] = $this->app->share(function($app)
$this->app->singleton('snowfire', function($app)
{
$defaultConfig = [
'acceptUrl' => route('snowfire.accept'),
Expand All @@ -69,7 +74,7 @@ public function register()
*/
public function provides()
{
return array('snowfire');
return ['snowfire'];
}

}
29 changes: 18 additions & 11 deletions src/routes.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<?php

Route::group(['prefix' => 'snowfire'], function() {
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Snowfire\App\Facades\Snowfire;

Route::get('/install', ['as' => 'snowfire.install', function() {
Route::group(['prefix' => 'snowfire', 'middleware' => ['web']], function() {

Route::get('/install', function() {
return Response::make(Snowfire::xml(), 200, ['content-type' => 'text/xml']);
}]);
})->name('snowfire.install');

Route::post('/accept', ['as' => 'snowfire.accept', function()
Route::post('/accept', function()
{
$storage = \Snowfire\App\Storage\AccountStorage::where('site_url', '=', Request::get('domain'))->first();

Expand All @@ -23,20 +30,20 @@

//Log::info('sfapp/accept', [$_GET, $_POST]);
return Response::make(Snowfire::response(true), 200, ['content-type' => 'text/xml']);
}]);
})->name('snowfire.accept');

Route::post('/uninstall', ['as' => 'snowfire.uninstall', function()
Route::post('/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']);
}]);
})->name('snowfire.uninstall');

// Admin tab
Route::get('/tab-proxy', ['as' => 'snowfire.tab', function()
Route::get('/tab-proxy', function()
{
$accountsRepository = app('Snowfire\App\Repositories\AccountsRepository');
$appKey = Request::get('snowfireAppKey');
Expand All @@ -55,10 +62,10 @@

return Redirect::route(Snowfire::parameter('tabRedirectRoute'), [$app->id]);

}]);
})->name('snowfire.tab');

// Proxy an URL to send a user between core domain and snowfire loaded app
Route::get('snowfire/proxy/{hash}', ['as' => 'snowfire.proxy', function($hash)
Route::get('proxy/{hash}', function($hash)
{
$proxy = \Snowfire\App\Proxy::getByHash($hash);

Expand All @@ -71,6 +78,6 @@
\Snowfire\App\Proxy::cleanup();

return Redirect::to($proxy->to_url);
}]);
})->name('snowfire.proxy');

});