Skip to content

Commit

Permalink
Added mergado hooks route to routes.php
Browse files Browse the repository at this point in the history
Changed oauthController
changed getrosourceOwnerId to getUserId on Accesstoken

Signed-off-by: hudecsamuel <[email protected]>
  • Loading branch information
hudecsamuel committed Jun 15, 2016
1 parent f67f767 commit 14b9737
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
34 changes: 34 additions & 0 deletions app/Http/Controllers/HookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Controllers;

use App\Hooks\CreateHook;
use App\Hooks\DeleteHook;
use Illuminate\Http\Request;

use App\Http\Requests;

class HookController extends Controller
{
public function index(Request $request)
{
$data = $request->all();

if(!isset($data["action"])) {
return response()->json(["message" => "Action undefined!"], 400);
}

switch ($data["action"]) {
case "app.enable":
$hook = new CreateHook($data["entity_id"]);
break;
case "app.disable":
$hook = new DeleteHook($data["entity_id"]);
break;
default:
return response()->json(["message" => "Unsupported action!"], 400);
}

return $hook->run();
}
}
22 changes: 6 additions & 16 deletions app/Http/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers;

use App\Auth;
use App\FailLog;
use App\Exceptions\AuthorizationException;
use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;

class OAuthController extends Controller
Expand All @@ -28,7 +29,6 @@ public function auth($eshopId)
public function token(Request $request)
{


if ($request->has('code')) {
//request token
return $this->oauth->getToken($request);
Expand All @@ -41,26 +41,16 @@ public function token(Request $request)

switch ($error) {
case 'invalid_entity':
return redirect()->route('error', ['message' => trans('error.invalid-entity')]);
break;
throw new AuthorizationException(trans('error.invalid-entity'));
case 'user_permission_error':
return redirect()->route('error', ['message' => trans('error.user_permission_error')]);
break;
throw new AuthorizationException(trans('error.user_permission_error'));
case (preg_match('/invalid_request.*/', $error) ? true : false) :
return redirect()->route('error', ['message' => trans('error.oauth_invalid_request')]);
break;
throw new AuthorizationException(trans('error.oauth_invalid_request'));
}

FailLog::create([
"message" => $error . " occured when trying to authorize"
]);

return redirect()->route('error');
} else {

FailLog::create([
"message" => $error . " occured and application will try to authorize again."
]);
Log::notice($error . " occured and application is going to try to authorize again.");

Session::put('oauthError', true);
return $this->oauth->getAuthCode(Session::get('entity_id'));
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProjectLogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function store($eshopId, $projectId, Request $request)

$date = date_create_from_format($dateFormat, $request->input('date'));

$user = User::find(Session::get('oauth')->getResourceOwnerId());
$user = User::find(Session::get('oauth')->getUserId());

$log = Log::create([
'date' => $date->format('Y-m-d H:i:s'),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserLogsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class UserLogsController extends Controller

public function __construct()
{
$this->user = User::find(Session::get('oauth')->getResourceOwnerId());
$this->user = User::find(Session::get('oauth')->getUserId());
}

/**
Expand Down
12 changes: 5 additions & 7 deletions app/Http/Middleware/OAuth2Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@ class OAuth2Session
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{

$eshopId = $request->route()->parameter('eshop_id');
if(!(Session::has('oauth')) || Session::get('oauth')->hasExpired()) {
if (!(Session::has('oauth')) || Session::get('oauth')->hasExpired()) {
Session::put('next', $request->path());
return redirect()->route('auth', $eshopId);
}

if(!Session::has('locale'))
{
Session::put('locale', User::find(Session::get('oauth')->getResourceOwnerId())->locale);
if (!Session::has('locale')) {
Session::put('locale', User::find(Session::get('oauth')->getUserId())->locale);
}

App::setLocale(Session::get('locale'));
Expand Down
5 changes: 3 additions & 2 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
Route::get('eshop/{eshop_id}/auth', ['uses' => 'OAuthController@auth', 'as' => 'auth']);
});

Route::post("/_mergado/hook/", "HookController@index");

/*
|--------------------------------------------------------------------------
| Application Routes
Expand All @@ -29,6 +31,7 @@
| kernel and includes session state, CSRF protection, and more.
|
*/

Route::group(['middleware' => ['web', 'oauth']], function () {


Expand All @@ -48,8 +51,6 @@

Route::get('widget/eshop/{eshop_id}/project/{project_id}', 'WidgetController@projectWidget');
Route::get('widget/eshop/{eshop_id}', 'WidgetController@eshopWidget');


});


0 comments on commit 14b9737

Please sign in to comment.