From 526c352619cad3b6016c02a2376388e8613908e2 Mon Sep 17 00:00:00 2001 From: Koen Betsens Date: Fri, 2 Dec 2016 07:54:04 +0100 Subject: [PATCH 01/16] Larval 5.1 Branch The Laravel 5.1 Branch is not intended to merge, but rather to reserve a lane for those 5.1 projects that are not ready yet to move to 5.2 --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index ae23d46..5768634 100755 --- a/composer.json +++ b/composer.json @@ -16,7 +16,6 @@ ], "require": { "php": ">=5.4.0", - "laravelcollective/html": "5.2.*", "bshaffer/oauth2-server-php": "v1.6", "cloudoki/except-io-nal": "v0.5.*" }, From 54c1424f409746190769a7d2b55d533bcedc1a1c Mon Sep 17 00:00:00 2001 From: Koen Betsens Date: Fri, 2 Dec 2016 08:36:23 +0100 Subject: [PATCH 02/16] replace resource_path Does not exist in 5.1 --- src/Cloudoki/OaStack/OaStackServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Cloudoki/OaStack/OaStackServiceProvider.php b/src/Cloudoki/OaStack/OaStackServiceProvider.php index e2ce095..5994639 100755 --- a/src/Cloudoki/OaStack/OaStackServiceProvider.php +++ b/src/Cloudoki/OaStack/OaStackServiceProvider.php @@ -30,7 +30,7 @@ public function boot() $this->publishes ( [ - __DIR__.'/Views' => resource_path ('views/vendor/oastack'), + __DIR__.'/Views' => base_path ('resources/views/vendor/oastack'), ]); # Oauth2 i18n @@ -38,7 +38,7 @@ public function boot() $this->publishes ( [ - __DIR__.'/../../lang' => resource_path ('lang/vendor/oastack') + __DIR__.'/../../lang' => base_path ('resources/lang/vendor/oastack') ], 'lang'); # Oauth2 config @@ -78,4 +78,4 @@ public function provides() return ['oastack']; } -} +} \ No newline at end of file From ec88389d879787379458a9ad300afc7723f2f198 Mon Sep 17 00:00:00 2001 From: Koen Betsens Date: Sun, 4 Dec 2016 12:01:10 +0100 Subject: [PATCH 03/16] added Html package v5.1 --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 5768634..91b2324 100755 --- a/composer.json +++ b/composer.json @@ -16,6 +16,7 @@ ], "require": { "php": ">=5.4.0", + "laravelcollective/html": "5.1.*", "bshaffer/oauth2-server-php": "v1.6", "cloudoki/except-io-nal": "v0.5.*" }, From 6b73d63f66ad8cfc56d41ba147acc0f19c5f6c7c Mon Sep 17 00:00:00 2001 From: Koen Betsens Date: Sun, 4 Dec 2016 12:22:52 +0100 Subject: [PATCH 04/16] Blade updates --- .../OaStack/Views/emails/invitation.blade.php | 2 +- .../OaStack/Views/emails/reset.blade.php | 2 +- src/Cloudoki/OaStack/Views/master.blade.php | 2 +- .../OaStack/Views/oauth2/approve.blade.php | 6 ++-- .../OaStack/Views/oauth2/forgot.blade.php | 16 +++++----- .../OaStack/Views/oauth2/invite.blade.php | 24 +++++++-------- .../OaStack/Views/oauth2/login.blade.php | 18 +++++------ .../OaStack/Views/oauth2/registered.blade.php | 4 +-- .../OaStack/Views/oauth2/reset.blade.php | 22 +++++++------- .../OaStack/Views/oauth2/subscribe.blade.php | 30 +++++++++---------- 10 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/Cloudoki/OaStack/Views/emails/invitation.blade.php b/src/Cloudoki/OaStack/Views/emails/invitation.blade.php index e87ef73..39fc5b5 100755 --- a/src/Cloudoki/OaStack/Views/emails/invitation.blade.php +++ b/src/Cloudoki/OaStack/Views/emails/invitation.blade.php @@ -11,7 +11,7 @@

{{ trans('oastack::emails.invite.info', ['account'=> $account]) }}

- {{ $url }} + {!! $url !!}
diff --git a/src/Cloudoki/OaStack/Views/emails/reset.blade.php b/src/Cloudoki/OaStack/Views/emails/reset.blade.php index 844d7b9..04a2785 100755 --- a/src/Cloudoki/OaStack/Views/emails/reset.blade.php +++ b/src/Cloudoki/OaStack/Views/emails/reset.blade.php @@ -11,7 +11,7 @@

{{ trans('oastack::emails.reset.info', ['firstname'=> $user->firstname]) }}

- {{ $url }} + {!! $url !!}
diff --git a/src/Cloudoki/OaStack/Views/master.blade.php b/src/Cloudoki/OaStack/Views/master.blade.php index a06a4b8..3c7728e 100755 --- a/src/Cloudoki/OaStack/Views/master.blade.php +++ b/src/Cloudoki/OaStack/Views/master.blade.php @@ -5,7 +5,7 @@ - {{ HTML::style('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css') }} + {!! HTML::style('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css') !!} diff --git a/src/Cloudoki/OaStack/Views/oauth2/approve.blade.php b/src/Cloudoki/OaStack/Views/oauth2/approve.blade.php index 00c0c36..f730127 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/approve.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/approve.blade.php @@ -12,14 +12,14 @@

{{ trans('oastack::oauth2.user.approve.info', (array) $client) }}

- {{ Form::open (['before' => 'csrf', 'action'=> ['\Cloudoki\OaStack\Controllers\OaStackViewController@approve', 'approve'=> $user->id, 'session_token'=> $session_token]]) }} + {!! Form::open (['before' => 'csrf', 'action'=> ['\Cloudoki\OaStack\Controllers\OaStackViewController@approve', 'approve'=> $user->id, 'session_token'=> $session_token]]) !!}
- {{ Form::submit(trans('oastack::oauth2.user.approve.allow'), ['class'=> 'btn btn-default form-btn']) }} + {!! Form::submit(trans('oastack::oauth2.user.approve.allow'), ['class'=> 'btn btn-default form-btn']) !!} {{ trans('oastack::oauth2.user.approve.deny') }}
- {{ Form::close () }} + {!! Form::close () !!} diff --git a/src/Cloudoki/OaStack/Views/oauth2/forgot.blade.php b/src/Cloudoki/OaStack/Views/oauth2/forgot.blade.php index 2469c0a..76992d0 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/forgot.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/forgot.blade.php @@ -16,7 +16,7 @@ Error: - {{ $error }} + {!! $error !!} @@ -27,23 +27,23 @@ - {{ Form::open (['before' => 'csrf', 'action'=> + {!! Form::open (['before' => 'csrf', 'action'=> [ '\Cloudoki\OaStack\Controllers\OaStackViewController@resetrequest', 'client_id'=> Request::input ('client_id'), 'redirect_uri'=> Request::input ('redirect_uri'), 'response_type'=> Request::input ('response_type'), 'state'=> Request::input ('state') ]]) - }} + !!}
- {{ Form::label ('email', trans('oastack::oauth2.user.forgot.email'), ['class'=> 'input-group-addon']) }} - {{ Form::email ('email', '', ['required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('email', trans('oastack::oauth2.user.forgot.email'), ['class'=> 'input-group-addon']) !!} + {!! Form::email ('email', '', ['required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::submit(trans('oastack::oauth2.user.forgot.submit'), ['class'=> 'btn btn-primary']) }} - {{ Form::button(trans('oastack::oauth2.user.forgot.back'), ['onclick'=> 'history.go(-1);', 'class'=> 'btn btn-default']) }} + {!! Form::submit(trans('oastack::oauth2.user.forgot.submit'), ['class'=> 'btn btn-primary']) !!} + {!! Form::button(trans('oastack::oauth2.user.forgot.back'), ['onclick'=> 'history.go(-1);', 'class'=> 'btn btn-default']) !!} - {{ Form::close() }} + {!! Form::close() !!} @endif diff --git a/src/Cloudoki/OaStack/Views/oauth2/invite.blade.php b/src/Cloudoki/OaStack/Views/oauth2/invite.blade.php index e448701..1862e79 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/invite.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/invite.blade.php @@ -20,42 +20,42 @@ Error: - {{ $message }} + {!! $message !!} @else

{{ trans('oastack::oauth2.user.invite.info') }}

- {{ Form::open (['url' => '#']) }} + {!! Form::open (['url' => '#']) !!}
- {{ Form::label ('firstname', trans('oastack::oauth2.user.invite.firstname'), ['class'=> 'input-group-addon']) }} - {{ Form::text ('firstname', '', ['placeholder'=> trans('oastack::oauth2.user.invite.fholder'), 'required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('firstname', trans('oastack::oauth2.user.invite.firstname'), ['class'=> 'input-group-addon']) !!} + {!! Form::text ('firstname', '', ['placeholder'=> trans('oastack::oauth2.user.invite.fholder'), 'required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('lastname', trans('oastack::oauth2.user.invite.lastname'), ['class'=> 'input-group-addon']) }} - {{ Form::text ('lastname', '', ['placeholder'=> trans('oastack::oauth2.user.invite.lholder'), 'required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('lastname', trans('oastack::oauth2.user.invite.lastname'), ['class'=> 'input-group-addon']) !!} + {!! Form::text ('lastname', '', ['placeholder'=> trans('oastack::oauth2.user.invite.lholder'), 'required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('email', trans('oastack::oauth2.user.invite.email'), ['class'=> 'input-group-addon']) }} - {{ Form::email ('email', '', ['placeholder'=> trans('oastack::oauth2.user.invite.eholder'), 'required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('email', trans('oastack::oauth2.user.invite.email'), ['class'=> 'input-group-addon']) !!} + {!! Form::email ('email', '', ['placeholder'=> trans('oastack::oauth2.user.invite.eholder'), 'required'=> 'required', 'class'=> 'form-control']) !!}

{{ trans('oastack::oauth2.user.invite.account') }} - {{ Form::select('size', $accounts, ['class'=> 'input-group-addon']) }} + {!! Form::select('size', $accounts, ['class'=> 'input-group-addon']) !!}

- {{ Form::submit(trans('oastack::oauth2.user.invite.submit'), ['class'=> 'btn btn-primary']) }} + {!! Form::submit(trans('oastack::oauth2.user.invite.submit'), ['class'=> 'btn btn-primary']) !!} - {{ Form::close () }} + {!! Form::close () !!} @endif @@ -63,7 +63,7 @@ diff --git a/src/Cloudoki/OaStack/Views/oauth2/login.blade.php b/src/Cloudoki/OaStack/Views/oauth2/login.blade.php index a6cf656..488e8fe 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/login.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/login.blade.php @@ -16,7 +16,7 @@ Error: - {{ $error }} + {!! $error !!} @@ -27,30 +27,30 @@ - {{ Form::open (['before' => 'csrf', 'action'=> + {!! Form::open (['before' => 'csrf', 'action'=> [ '\Cloudoki\OaStack\Controllers\OaStackViewController@loginrequest', 'client_id'=> Request::input ('client_id'), 'redirect_uri'=> Request::input ('redirect_uri'), 'response_type'=> Request::input ('response_type'), 'state'=> Request::input ('state') ]]) - }} + !!}
- {{ Form::label ('email', trans('oastack::oauth2.user.login.email'), ['class'=> 'input-group-addon']) }} - {{ Form::email ('email', '', ['required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('email', trans('oastack::oauth2.user.login.email'), ['class'=> 'input-group-addon']) !!} + {!! Form::email ('email', '', ['required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('password', trans('oastack::oauth2.user.login.password'), ['class'=> 'input-group-addon']) }} - {{ Form::password ('password', ['required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('password', trans('oastack::oauth2.user.login.password'), ['class'=> 'input-group-addon']) !!} + {!! Form::password ('password', ['required'=> 'required', 'class'=> 'form-control']) !!}

{{ trans('oastack::oauth2.user.login.forgot') }} - {{ Form::submit(trans('oastack::oauth2.user.login.submit'), ['class'=> 'btn btn-default']) }} + {!! Form::submit(trans('oastack::oauth2.user.login.submit'), ['class'=> 'btn btn-default']) !!} - {{ Form::close() }} + {!! Form::close() !!} @endif diff --git a/src/Cloudoki/OaStack/Views/oauth2/registered.blade.php b/src/Cloudoki/OaStack/Views/oauth2/registered.blade.php index 80e6031..fdd8f11 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/registered.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/registered.blade.php @@ -18,7 +18,7 @@ Error: @foreach ($error as $message) - {{ $message }} + {!! $message !!}
@endforeach @@ -58,7 +58,7 @@
- {{ $redirecturi or "" }} + {!! $redirecturi or "" !!}
@endif diff --git a/src/Cloudoki/OaStack/Views/oauth2/reset.blade.php b/src/Cloudoki/OaStack/Views/oauth2/reset.blade.php index d741a09..c4fd971 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/reset.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/reset.blade.php @@ -16,7 +16,7 @@ Error: - {{ $error }} + {!! $error !!} @@ -25,35 +25,35 @@

{{ trans('oastack::oauth2.user.reset.info') }}

- {{ Form::open (['before' => 'csrf', 'action'=> + {!! Form::open (['before' => 'csrf', 'action'=> [ '\Cloudoki\OaStack\Controllers\OaStackViewController@changepassword', 'reset_token'=> $reset_token ]]) - }} + !!}
- {{ Form::label ('email', trans('oastack::oauth2.user.reset.email'), ['class'=> 'input-group-addon']) }} - {{ Form::email ('email', '', ['required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('email', trans('oastack::oauth2.user.reset.email'), ['class'=> 'input-group-addon']) !!} + {!! Form::email ('email', '', ['required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('password', trans('oastack::oauth2.user.reset.password'), ['class'=> 'input-group-addon']) }} - {{ Form::password ('password', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) }} + {!! Form::label ('password', trans('oastack::oauth2.user.reset.password'), ['class'=> 'input-group-addon']) !!} + {!! Form::password ('password', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) !!} {{trans('oastack::oauth2.user.reset.minchars')}}

- {{ Form::label ('password_confirmation', trans('oastack::oauth2.user.reset.password_conf'), ['class'=> 'input-group-addon']) }} - {{ Form::password ('password_confirmation', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) }} + {!! Form::label ('password_confirmation', trans('oastack::oauth2.user.reset.password_conf'), ['class'=> 'input-group-addon']) !!} + {!! Form::password ('password_confirmation', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) !!}

- {{ Form::submit(trans('oastack::oauth2.user.reset.submit'), ['class'=> 'btn btn-primary']) }} + {!! Form::submit(trans('oastack::oauth2.user.reset.submit'), ['class'=> 'btn btn-primary']) !!} - {{ Form::close() }} + {!! Form::close() !!} @endif diff --git a/src/Cloudoki/OaStack/Views/oauth2/subscribe.blade.php b/src/Cloudoki/OaStack/Views/oauth2/subscribe.blade.php index 7460f68..cadaa69 100755 --- a/src/Cloudoki/OaStack/Views/oauth2/subscribe.blade.php +++ b/src/Cloudoki/OaStack/Views/oauth2/subscribe.blade.php @@ -20,49 +20,49 @@ Error: - {{ $message }} + {!! $message !!} @else

{{ trans('oastack::oauth2.user.subscribe.info', ['account'=> $account['name']]) }}

- {{ Form::open (['url' => '#']) }} + {!! Form::open (['url' => '#']) !!}
- {{ Form::label ('firstname', trans('oastack::oauth2.user.subscribe.firstname'), ['class'=> 'input-group-addon']) }} - {{ Form::text ('firstname', $user['firstname'], ['placeholder'=> trans('oastack::oauth2.user.subscribe.fholder'), 'required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('firstname', trans('oastack::oauth2.user.subscribe.firstname'), ['class'=> 'input-group-addon']) !!} + {!! Form::text ('firstname', $user['firstname'], ['placeholder'=> trans('oastack::oauth2.user.subscribe.fholder'), 'required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('lastname', trans('oastack::oauth2.user.subscribe.lastname'), ['class'=> 'input-group-addon']) }} - {{ Form::text ('lastname', $user['lastname'], ['placeholder'=> trans('oastack::oauth2.user.subscribe.lholder'), 'required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('lastname', trans('oastack::oauth2.user.subscribe.lastname'), ['class'=> 'input-group-addon']) !!} + {!! Form::text ('lastname', $user['lastname'], ['placeholder'=> trans('oastack::oauth2.user.subscribe.lholder'), 'required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('email', trans('oastack::oauth2.user.subscribe.email'), ['class'=> 'input-group-addon']) }} - {{ Form::email ('email', $user['email'], ['placeholder'=> trans('oastack::oauth2.user.subscribe.eholder'), 'required'=> 'required', 'class'=> 'form-control']) }} + {!! Form::label ('email', trans('oastack::oauth2.user.subscribe.email'), ['class'=> 'input-group-addon']) !!} + {!! Form::email ('email', $user['email'], ['placeholder'=> trans('oastack::oauth2.user.subscribe.eholder'), 'required'=> 'required', 'class'=> 'form-control']) !!}

- {{ Form::label ('password', trans('oastack::oauth2.user.subscribe.password'), ['class'=> 'input-group-addon']) }} - {{ Form::password ('password', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) }} + {!! Form::label ('password', trans('oastack::oauth2.user.subscribe.password'), ['class'=> 'input-group-addon']) !!} + {!! Form::password ('password', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) !!} {{trans('oastack::oauth2.user.subscribe.minchars')}}

- {{ Form::label ('password_confirmation', trans('oastack::oauth2.user.subscribe.password_conf'), ['class'=> 'input-group-addon']) }} - {{ Form::password ('password_confirmation', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) }} + {!! Form::label ('password_confirmation', trans('oastack::oauth2.user.subscribe.password_conf'), ['class'=> 'input-group-addon']) !!} + {!! Form::password ('password_confirmation', ['required'=> 'required', 'minlength'=> 6, 'class'=> 'form-control']) !!}

- {{ Form::submit(trans('oastack::oauth2.user.subscribe.submit'), ['class'=> 'btn btn-default']) }} + {!! Form::submit(trans('oastack::oauth2.user.subscribe.submit'), ['class'=> 'btn btn-default']) !!} - {{ Form::close () }} + {!! Form::close () !!} @endif @@ -70,7 +70,7 @@ From 99af02628c5dd91791e7fcad6fb376847a98eeff Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Wed, 14 Dec 2016 18:59:43 +0000 Subject: [PATCH 05/16] Fixed some Laravel 5.1 compatibilities, made the modle less opinionated. Devs can now provide their own job dispatcher implementation. Devs can now provide their own user model implementation. Added indexes to the `oauth_access_tokens` table. --- .../OaStack/Controllers/BaseController.php | 62 ++++++++++++++----- .../OaStack/Controllers/OAuth2Controller.php | 37 +++++++---- .../Controllers/OaStackViewController.php | 9 +-- .../OaStack/Models/Oauth2AccessToken.php | 22 +++++-- src/Cloudoki/OaStack/Traits/User.php | 54 ++++++++++++++++ src/config/oastack.php | 13 ++-- ...stack_create_oauth_access_tokens_table.php | 6 +- 7 files changed, 159 insertions(+), 44 deletions(-) create mode 100644 src/Cloudoki/OaStack/Traits/User.php diff --git a/src/Cloudoki/OaStack/Controllers/BaseController.php b/src/Cloudoki/OaStack/Controllers/BaseController.php index 06c658f..b22482a 100755 --- a/src/Cloudoki/OaStack/Controllers/BaseController.php +++ b/src/Cloudoki/OaStack/Controllers/BaseController.php @@ -5,7 +5,7 @@ use Validator; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Illuminate\Validation\ValidationException; +use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Support\Facades\Redirect; @@ -28,7 +28,6 @@ class BaseController extends Controller */ var $request; - /** * BaseController construct * MQ preps @@ -49,7 +48,10 @@ protected function prepInput ($attr) // Add display fallback $attr['display'] = $this->request->input ('display', self::display); - return array_merge ($this->request->all(), $attr); + $postParams = $this->request->request->all(); + $queryParams = $this->request->all(); + + return array_merge ($queryParams, $postParams, $attr); } /** @@ -63,11 +65,9 @@ public function validate ($input, $rules = []) // Add path attributes $input = $this->prepInput ($input); - // Perform validation $validator = Validator::make ($input, $rules); - // Check if the validator failed if ($validator->fails ()) @@ -90,15 +90,15 @@ public static function jobdispatch($job, $jobload, $direct = false) # Response $response = app()->frontqueue->request($job, $jobload); - - if (isset ($response->error)) - + + if (isset ($response->error)) + return response ($response->error, $response->code); # Frontqueue call - return $direct? - - $response: + return $direct? + + $response: response()->json ($response); } @@ -111,18 +111,46 @@ public static function jobdispatch($job, $jobload, $direct = false) */ public function restDispatch ($method, $controller, $input = [], $rules = []) { + # Extend rules $rules = array_merge ($this->baseValidationRules, $rules); # Validation $payload = array_intersect_key ($this->validate ($input, $rules), $rules); - # Request Foreground Job - $response = self::jobdispatch ('controllerDispatch', (object) ['action'=> $method, 'controller'=> $controller, 'payload'=> (object) $payload], true); - - return is_string ($response)? - - json_decode ($response): + $externalDispatcher = config ('oastack.jobDispatcher', null); + + if ($externalDispatcher !== null) { + // Instead of using the built-in job dispatching logic, + // we call the user-specified method that handles it + // in the base application. + $dispatchFunc = array($externalDispatcher, 'dispatch'); + + $response = call_user_func($dispatchFunc, + 'controllerDispatch', + (object) [ + 'action'=> $method, + 'controller'=> $controller, + 'payload'=> (object) $payload + ], + true + ); + } else { + # Request Foreground Job + $response = self::jobdispatch ( + 'controllerDispatch', + (object) [ + 'action'=> $method, + 'controller'=> $controller, + 'payload'=> (object) $payload + ], + true + ); + } + + return is_string ($response)? + + json_decode ($response): (object) $response; } diff --git a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php index 382dcd8..ff601f6 100755 --- a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php +++ b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php @@ -45,15 +45,29 @@ public static function login ($payload) throw new \Cloudoki\InvalidParameterException ('Invalid client id or redirect uri'); } - # Validate user - if (!empty($payload->email)) { - $user = User::email ($payload->email)->first (); - } else { + + if (empty($payload->email)) { throw new \Cloudoki\InvalidParameterException ('Invalid e-mail.'); } - if (!isset($user) || !$user->checkPassword ($payload->password)) { - throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); + $userModelClass = config ('oastack.userModel', null); + + if ($userModelClass != null) { + // We have to use the base app's user model and authentication strategy + $userModel = app()->make($userModelClass); + + $user = call_user_func(array($userModel, 'findByLoginId'), $payload->email); + + if (!isset($user) || !$user->checkPassword ($payload->password)) { + throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); + } + } else { + // We're allowed to use our own `user` model and authentication strategy + $user = User::email ($payload->email)->first (); + + if (!isset($user) || !$user->checkPassword ($payload->password)) { + throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); + } } # Validate Authorization $authorization = $user->oauth2authorizations ()->where ('client_id', $client->getClientId ())->first (); @@ -64,7 +78,7 @@ public static function login ($payload) [ 'access_token'=> Oauth2AccessToken::generateAccessToken(), 'client_id'=> $client->getClientId (), - 'user_id'=> $user->getId (), + 'user_id'=> $user->id, 'expires'=> new Carbon('+ 2 minute', Config::get ('app.timezone')) ]); @@ -85,7 +99,7 @@ public static function login ($payload) [ 'access_token'=> Oauth2AccessToken::generateAccessToken(), 'client_id'=> $client->getClientId (), - 'user_id'=> $user->getId (), + 'user_id'=> $user->id, 'expires'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))->addYear () ]); @@ -111,19 +125,18 @@ public static function authorize ($payload) # Validate session token $sessiontoken = Oauth2AccessToken::whereAccessToken ($payload->session_token)->valid ()->first (); - if (!$sessiontoken || $sessiontoken->user->getId () != (int) $payload->approve) + if (!$sessiontoken || $sessiontoken->user->id != (int) $payload->approve) throw new \Cloudoki\InvalidParameterException ('Session expired or invalid approval.'); - # Token handling - Oauth2Authorization::create (['client_id'=> $sessiontoken->client->getClientId (), 'user_id'=> $sessiontoken->user->getId (), 'authorization_date'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))]); + Oauth2Authorization::create (['client_id'=> $sessiontoken->client->getClientId (), 'user_id'=> $sessiontoken->user->id, 'authorization_date'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))]); $accesstoken = Oauth2AccessToken::create ( [ 'access_token'=> Oauth2AccessToken::generateAccessToken(), 'client_id'=> $sessiontoken->client->getClientId (), - 'user_id'=> $sessiontoken->user->getId (), + 'user_id'=> $sessiontoken->user->id, 'expires'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))->addYear () ]); diff --git a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php index 919eafe..27bd23f 100755 --- a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php +++ b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php @@ -14,7 +14,7 @@ class OaStackViewController extends BaseController { 'email'=> 'required|email', 'password'=> 'required|min:4', 'client_id'=> 'required|min:18', - 'response_type'=> 'required|min:5', + 'response_type'=> 'required|min:4', 'redirect_uri'=> 'required|min:8', 'state'=> '' ); @@ -75,9 +75,10 @@ public function login () */ public function loginrequest () { + // Request Foreground Job $login = $this->restDispatch ('login', 'Cloudoki\OaStack\OAuth2Controller', [], self::$loginRules); - + if (isset ($login->error)) return view('oastack::oauth2.login', ['error'=> isset ($login->message)? $login->message: "something went wrong"]); @@ -184,10 +185,10 @@ public function subscribe ($token) { // Request Foreground Job $invite = $this->restDispatch ('identifyinvite', 'Cloudoki\OaStack\OAuth2Controller', ['token'=> $token], self::$invitationRules); - + // Build View - return view ('oastack::oauth2.subscribe', + return view ('oastack::oauth2.subscribe', [ 'user'=> (array) $invite->user, 'account'=> (array) $invite->account diff --git a/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php b/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php index ff71788..e9f658d 100755 --- a/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php +++ b/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php @@ -2,7 +2,6 @@ namespace Cloudoki\OaStack\Models; -use Cloudoki\OaStack\Models\User; use Cloudoki\OaStack\Models\Oauth2Client; use \Illuminate\Database\Eloquent\Model as Eloquent; @@ -34,7 +33,8 @@ class Oauth2AccessToken extends Eloquent */ public function user () { - return $this->belongsTo (User::class); + $userModelClass = config ('oastack.userModel', 'Cloudoki\\OaStack\\Models\\User'); + return $this->belongsTo ($userModelClass); } /** @@ -98,6 +98,20 @@ public function getToken () return $this->access_token; } + /** + * Expires all authentication tokens of the provided user id. + * + * @param int $userId + * + * @return null + */ + public static function expireAllUserTokens ($userId) + { + self::where('user_id', '=', $userId) + ->whereRaw('expires > now()') + ->update(['expires' => date('Y-m-d H:i:s')]); + } + /** * Generates an unique access token. @@ -112,7 +126,7 @@ public function getToken () */ protected static function generateAccessToken() { - if (function_exists('mcrypt_create_iv')) + if (function_exists('mcrypt_create_iv')) { $randomData = mcrypt_create_iv(20, MCRYPT_DEV_URANDOM); if ($randomData !== false && strlen($randomData) === 20) @@ -128,7 +142,7 @@ protected static function generateAccessToken() return bin2hex($randomData); } - if (@file_exists('/dev/urandom')) + if (@file_exists('/dev/urandom')) { $randomData = file_get_contents('/dev/urandom', false, null, 0, 20); if ($randomData !== false && strlen($randomData) === 20) diff --git a/src/Cloudoki/OaStack/Traits/User.php b/src/Cloudoki/OaStack/Traits/User.php new file mode 100644 index 0000000..6ee7d8e --- /dev/null +++ b/src/Cloudoki/OaStack/Traits/User.php @@ -0,0 +1,54 @@ +first(); + } + + /** + * Acces Token relationship + * + * @return hasMany + */ + public function oauth2accesstokens () + { + return $this->hasMany('Cloudoki\OaStack\Models\Oauth2AccessToken'); + } + + /** + * Authorisations relationship + * + * @return hasMany + */ + public function oauth2authorizations () + { + return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Authorization'); + } + + /** + * Clients relationship + * + * @return hasMany + */ + public function oauth2clients () + { + return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Client'); + } + + /** + * Check password + * + * @param string $value + * @return bool + */ + public function checkPassword ($value) + { + return Hash::check ($value, $this->password); + } + +} \ No newline at end of file diff --git a/src/config/oastack.php b/src/config/oastack.php index a8969f0..8260890 100755 --- a/src/config/oastack.php +++ b/src/config/oastack.php @@ -1,7 +1,7 @@ 'http://localhost/oauth2/invitation', 'reset_url' => 'http://localhost/oauth2/reset', - 'privacy_url' => 'http://en.wikipedia.org/wiki/Privacy_policy' + 'privacy_url' => 'http://en.wikipedia.org/wiki/Privacy_policy', + // Optional. A job dispatcher class with a static `dispatch` method. + 'jobDispatcher' => null, + // Optional. The `user` model of the base application. + // The user model must use the provided Traits\User trait. + 'userModel' => null, ); diff --git a/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php b/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php index 3437d81..9b423c0 100755 --- a/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php +++ b/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php @@ -13,13 +13,13 @@ class OastackCreateOauthAccessTokensTable extends Migration { public function up() { if (!Schema::hasTable('oauth_access_tokens')) - + Schema::create ('oauth_access_tokens', function (Blueprint $table) { $table->increments ('id'); - $table->string ('access_token', 40); + $table->string ('access_token', 40)->unique(); $table->string ('client_id', 80); - $table->integer ('user_id'); + $table->integer ('user_id')->index(); $table->timestamp ('expires'); $table->string ('scope', 80)->nullable (); }); From 5893f2d4e06aae5cb4d36a1daba6900efa5f93ed Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Thu, 15 Dec 2016 10:21:08 +0000 Subject: [PATCH 06/16] Decoupled the `user` object view/presentation. Now, base apps can provide their own logic to create a user representation object with the fields that this module's views require. --- .../OaStack/Controllers/OAuth2Controller.php | 14 ++++++++----- src/Cloudoki/OaStack/Traits/User.php | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php index ff601f6..e195291 100755 --- a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php +++ b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php @@ -69,6 +69,7 @@ public static function login ($payload) throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); } } + # Validate Authorization $authorization = $user->oauth2authorizations ()->where ('client_id', $client->getClientId ())->first (); @@ -82,11 +83,13 @@ public static function login ($payload) 'expires'=> new Carbon('+ 2 minute', Config::get ('app.timezone')) ]); + + return [ 'view'=> 'approve', 'session_token'=> $sessiontoken->getToken (), - 'user'=> $user->schema ('basic'), + 'user'=> $user->getViewPresenter (), 'client'=> $client->schema ('basic') ]; } @@ -103,6 +106,7 @@ public static function login ($payload) 'expires'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))->addYear () ]); + return [ 'uri'=> $client->getRedirectUri () . '?access_token=' . $accesstoken->getToken () @@ -248,7 +252,7 @@ public static function resetpassword ($payload) public static function changepassword ($payload) { $token = $payload->reset_token; - + $user = User::email ($payload->email) ->whereHas ('accounts', function ($q) use ($token) { $q->where ('account_user.reset_token', $token); }) ->first (); @@ -263,7 +267,7 @@ public static function changepassword ($payload) throw new \Cloudoki\InvalidParameterException ('The passwords do not match.'); - + # Update user $user->setPassword ($payload->password) ->setResetToken (null) @@ -305,7 +309,7 @@ public function identifyinvite ($payload) else return [ - 'user'=> $user->schema ('full'), + 'user'=> $user->getViewPresenter (), 'account'=> $account->schema ('basic') ]; } @@ -361,7 +365,7 @@ public function registeruser () public function registerclient ($payload = null) { $payload = $payload ?: json_decode (Input::get ('payload')); - + $client = new Oauth2Client(); $client->appendPayload ($payload) ->save(); diff --git a/src/Cloudoki/OaStack/Traits/User.php b/src/Cloudoki/OaStack/Traits/User.php index 6ee7d8e..0d2ae62 100644 --- a/src/Cloudoki/OaStack/Traits/User.php +++ b/src/Cloudoki/OaStack/Traits/User.php @@ -6,6 +6,11 @@ trait User { + /** + * Get a user by its main username/email identifier. + * + * @return hasMany + */ public static function findByLoginId($identifier) { return self::where('email', '=', $identifier)->first(); } @@ -51,4 +56,20 @@ public function checkPassword ($value) return Hash::check ($value, $this->password); } + /** + * Return an object with the most important user properties + * which will be used for the view templates. + * The object must contain at least the following properties: + * - id + * - email + * - firstname + * - lastname + * - fullname + */ + public function getViewPresenter () { + $user = $this->schema ('basic'); + $user->fullname = $user->firstname . ' ' . $user->lastname; + + return $user; + } } \ No newline at end of file From c969c651951735930c62e4ce5adc2f1351d58a85 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Thu, 15 Dec 2016 11:34:30 +0000 Subject: [PATCH 07/16] Added possibility to configure module through env vars. --- src/Cloudoki/OaStack/Controllers/BaseController.php | 2 +- src/Cloudoki/OaStack/Controllers/OAuth2Controller.php | 2 +- src/Cloudoki/OaStack/Models/Oauth2AccessToken.php | 2 +- src/config/oastack.php | 11 +++++------ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Cloudoki/OaStack/Controllers/BaseController.php b/src/Cloudoki/OaStack/Controllers/BaseController.php index b22482a..51bfc44 100755 --- a/src/Cloudoki/OaStack/Controllers/BaseController.php +++ b/src/Cloudoki/OaStack/Controllers/BaseController.php @@ -118,7 +118,7 @@ public function restDispatch ($method, $controller, $input = [], $rules = []) # Validation $payload = array_intersect_key ($this->validate ($input, $rules), $rules); - $externalDispatcher = config ('oastack.jobDispatcher', null); + $externalDispatcher = config ('oastack.job_dispatcher', null); if ($externalDispatcher !== null) { // Instead of using the built-in job dispatching logic, diff --git a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php index e195291..6976773 100755 --- a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php +++ b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php @@ -50,7 +50,7 @@ public static function login ($payload) throw new \Cloudoki\InvalidParameterException ('Invalid e-mail.'); } - $userModelClass = config ('oastack.userModel', null); + $userModelClass = config ('oastack.user_model', null); if ($userModelClass != null) { // We have to use the base app's user model and authentication strategy diff --git a/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php b/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php index e9f658d..bb62cc0 100755 --- a/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php +++ b/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php @@ -33,7 +33,7 @@ class Oauth2AccessToken extends Eloquent */ public function user () { - $userModelClass = config ('oastack.userModel', 'Cloudoki\\OaStack\\Models\\User'); + $userModelClass = config ('oastack.user_model', 'Cloudoki\\OaStack\\Models\\User'); return $this->belongsTo ($userModelClass); } diff --git a/src/config/oastack.php b/src/config/oastack.php index 8260890..cdeffb2 100755 --- a/src/config/oastack.php +++ b/src/config/oastack.php @@ -11,13 +11,12 @@ | You might want to edit this config in your .app/config/vendor environment. | */ - - 'invite_url' => 'http://localhost/oauth2/invitation', - 'reset_url' => 'http://localhost/oauth2/reset', - 'privacy_url' => 'http://en.wikipedia.org/wiki/Privacy_policy', + 'invite_url' => env('OASTACK_INVITE_URL', 'http://localhost/oauth2/invitation'), + 'reset_url' => env('OASTACK_RESET_URL', 'http://localhost/oauth2/reset'), + 'privacy_url' => env('OASTACK_PRIVACY_URL', 'http://en.wikipedia.org/wiki/Privacy_policy'), // Optional. A job dispatcher class with a static `dispatch` method. - 'jobDispatcher' => null, + 'job_dispatcher' => env('OASTACK_JOB_DISPATCHER', null), // Optional. The `user` model of the base application. // The user model must use the provided Traits\User trait. - 'userModel' => null, + 'user_model' => env('OASTACK_USER_MODEL', null), ); From 99b2d7f8b60bb13a0d8dfa7d88b09c3adee0703e Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Tue, 20 Dec 2016 17:47:38 +0000 Subject: [PATCH 08/16] Showing the correct error message on authentication errors --- src/Cloudoki/OaStack/Controllers/OaStackViewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php index 27bd23f..2a1221c 100755 --- a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php +++ b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php @@ -81,7 +81,7 @@ public function loginrequest () if (isset ($login->error)) - return view('oastack::oauth2.login', ['error'=> isset ($login->message)? $login->message: "something went wrong"]); + return view('oastack::oauth2.login', ['error'=> isset ($login->error)? $login->error: "something went wrong"]); else if (isset ($login->view)) From a6bec943c550ff7f14ad7cd1c2a8c07121406255 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Wed, 21 Dec 2016 11:26:19 +0000 Subject: [PATCH 09/16] Added a custom package-level exception handler Now we can return error messages with the usual UI styling of this package. --- .../OaStack/Controllers/BaseController.php | 8 +++ src/Cloudoki/OaStack/Exceptions/Handler.php | 50 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/Cloudoki/OaStack/Exceptions/Handler.php diff --git a/src/Cloudoki/OaStack/Controllers/BaseController.php b/src/Cloudoki/OaStack/Controllers/BaseController.php index 51bfc44..b3310c4 100755 --- a/src/Cloudoki/OaStack/Controllers/BaseController.php +++ b/src/Cloudoki/OaStack/Controllers/BaseController.php @@ -7,6 +7,7 @@ use Illuminate\Routing\Controller; use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Support\Facades\Redirect; +use Cloudoki\OaStack\Exceptions\Handler as OaStackHandler; class BaseController extends Controller @@ -34,6 +35,13 @@ class BaseController extends Controller */ public function __construct (Request $request) { + // Override the base app's global exception handler with this + // package's custom exception handler + // As seen here: https://laracasts.com/discuss/channels/requests/custom-exception-handler-based-on-route-group + \App::singleton( + \Illuminate\Contracts\Debug\ExceptionHandler::class, + OaStackHandler::class + ); $this->request = $request; } diff --git a/src/Cloudoki/OaStack/Exceptions/Handler.php b/src/Cloudoki/OaStack/Exceptions/Handler.php new file mode 100644 index 0000000..05348b9 --- /dev/null +++ b/src/Cloudoki/OaStack/Exceptions/Handler.php @@ -0,0 +1,50 @@ +view('oastack::oauth2.login', ['error'=> 'Invalid request.']); + } +} From 8a29ce038ef0c1c746a5916a2788d1407b24c38f Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Wed, 21 Dec 2016 12:38:20 +0000 Subject: [PATCH 10/16] Using the custom exception handler only for the view-related endpoints. --- src/Cloudoki/OaStack/Controllers/BaseController.php | 9 --------- .../OaStack/Controllers/OaStackViewController.php | 13 +++++++++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Cloudoki/OaStack/Controllers/BaseController.php b/src/Cloudoki/OaStack/Controllers/BaseController.php index b3310c4..1ebc57d 100755 --- a/src/Cloudoki/OaStack/Controllers/BaseController.php +++ b/src/Cloudoki/OaStack/Controllers/BaseController.php @@ -7,8 +7,6 @@ use Illuminate\Routing\Controller; use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Support\Facades\Redirect; -use Cloudoki\OaStack\Exceptions\Handler as OaStackHandler; - class BaseController extends Controller { @@ -35,13 +33,6 @@ class BaseController extends Controller */ public function __construct (Request $request) { - // Override the base app's global exception handler with this - // package's custom exception handler - // As seen here: https://laracasts.com/discuss/channels/requests/custom-exception-handler-based-on-route-group - \App::singleton( - \Illuminate\Contracts\Debug\ExceptionHandler::class, - OaStackHandler::class - ); $this->request = $request; } diff --git a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php index 2a1221c..950f518 100755 --- a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php +++ b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use Cloudoki\OaStack\Controllers\BaseController; use Cloudoki\InvalidParameterException; +use Cloudoki\OaStack\Exceptions\Handler as OaStackHandler; class OaStackViewController extends BaseController { @@ -59,6 +60,18 @@ class OaStackViewController extends BaseController { 'user_id' => 'required|integer', ); + public function __construct (Request $request) + { + parent::__construct($request); + // Override the base app's global exception handler with this + // package's custom exception handler + // As seen here: https://laracasts.com/discuss/channels/requests/custom-exception-handler-based-on-route-group + \App::singleton( + \Illuminate\Contracts\Debug\ExceptionHandler::class, + OaStackHandler::class + ); + } + /** * User Login * Show user login fields From 5ef69512730ddafc479d460601ad2a391bc47c47 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Wed, 21 Dec 2016 15:49:13 +0000 Subject: [PATCH 11/16] Several improvements including decoupling from internal transport requirements. * The User model and api->blm job dispatcher can now be provided by the base Laravel app. * Package-specific exception handler so we can transform exceptions into errors that are shown in the login view instead of dumping a stack trace in the browser. * * Added indexes to the `oauth_access_tokens` table for faster lookups. --- .../OaStack/Controllers/BaseController.php | 63 +++++++++++----- .../OaStack/Controllers/OAuth2Controller.php | 51 ++++++++----- .../Controllers/OaStackViewController.php | 24 ++++-- src/Cloudoki/OaStack/Exceptions/Handler.php | 50 +++++++++++++ .../OaStack/Models/Oauth2AccessToken.php | 22 +++++- src/Cloudoki/OaStack/Traits/User.php | 75 +++++++++++++++++++ src/config/oastack.php | 16 ++-- ...stack_create_oauth_access_tokens_table.php | 6 +- 8 files changed, 254 insertions(+), 53 deletions(-) create mode 100644 src/Cloudoki/OaStack/Exceptions/Handler.php create mode 100644 src/Cloudoki/OaStack/Traits/User.php diff --git a/src/Cloudoki/OaStack/Controllers/BaseController.php b/src/Cloudoki/OaStack/Controllers/BaseController.php index 06c658f..1ebc57d 100755 --- a/src/Cloudoki/OaStack/Controllers/BaseController.php +++ b/src/Cloudoki/OaStack/Controllers/BaseController.php @@ -5,10 +5,9 @@ use Validator; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Illuminate\Validation\ValidationException; +use Illuminate\Contracts\Validation\ValidationException; use Illuminate\Support\Facades\Redirect; - class BaseController extends Controller { /** @@ -28,7 +27,6 @@ class BaseController extends Controller */ var $request; - /** * BaseController construct * MQ preps @@ -49,7 +47,10 @@ protected function prepInput ($attr) // Add display fallback $attr['display'] = $this->request->input ('display', self::display); - return array_merge ($this->request->all(), $attr); + $postParams = $this->request->request->all(); + $queryParams = $this->request->all(); + + return array_merge ($queryParams, $postParams, $attr); } /** @@ -63,11 +64,9 @@ public function validate ($input, $rules = []) // Add path attributes $input = $this->prepInput ($input); - // Perform validation $validator = Validator::make ($input, $rules); - // Check if the validator failed if ($validator->fails ()) @@ -90,15 +89,15 @@ public static function jobdispatch($job, $jobload, $direct = false) # Response $response = app()->frontqueue->request($job, $jobload); - - if (isset ($response->error)) - + + if (isset ($response->error)) + return response ($response->error, $response->code); # Frontqueue call - return $direct? - - $response: + return $direct? + + $response: response()->json ($response); } @@ -111,18 +110,46 @@ public static function jobdispatch($job, $jobload, $direct = false) */ public function restDispatch ($method, $controller, $input = [], $rules = []) { + # Extend rules $rules = array_merge ($this->baseValidationRules, $rules); # Validation $payload = array_intersect_key ($this->validate ($input, $rules), $rules); - # Request Foreground Job - $response = self::jobdispatch ('controllerDispatch', (object) ['action'=> $method, 'controller'=> $controller, 'payload'=> (object) $payload], true); - - return is_string ($response)? - - json_decode ($response): + $externalDispatcher = config ('oastack.job_dispatcher', null); + + if ($externalDispatcher !== null) { + // Instead of using the built-in job dispatching logic, + // we call the user-specified method that handles it + // in the base application. + $dispatchFunc = array($externalDispatcher, 'dispatch'); + + $response = call_user_func($dispatchFunc, + 'controllerDispatch', + (object) [ + 'action'=> $method, + 'controller'=> $controller, + 'payload'=> (object) $payload + ], + true + ); + } else { + # Request Foreground Job + $response = self::jobdispatch ( + 'controllerDispatch', + (object) [ + 'action'=> $method, + 'controller'=> $controller, + 'payload'=> (object) $payload + ], + true + ); + } + + return is_string ($response)? + + json_decode ($response): (object) $response; } diff --git a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php index 382dcd8..6976773 100755 --- a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php +++ b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php @@ -45,16 +45,31 @@ public static function login ($payload) throw new \Cloudoki\InvalidParameterException ('Invalid client id or redirect uri'); } - # Validate user - if (!empty($payload->email)) { - $user = User::email ($payload->email)->first (); - } else { + + if (empty($payload->email)) { throw new \Cloudoki\InvalidParameterException ('Invalid e-mail.'); } - if (!isset($user) || !$user->checkPassword ($payload->password)) { - throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); + $userModelClass = config ('oastack.user_model', null); + + if ($userModelClass != null) { + // We have to use the base app's user model and authentication strategy + $userModel = app()->make($userModelClass); + + $user = call_user_func(array($userModel, 'findByLoginId'), $payload->email); + + if (!isset($user) || !$user->checkPassword ($payload->password)) { + throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); + } + } else { + // We're allowed to use our own `user` model and authentication strategy + $user = User::email ($payload->email)->first (); + + if (!isset($user) || !$user->checkPassword ($payload->password)) { + throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); + } } + # Validate Authorization $authorization = $user->oauth2authorizations ()->where ('client_id', $client->getClientId ())->first (); @@ -64,15 +79,17 @@ public static function login ($payload) [ 'access_token'=> Oauth2AccessToken::generateAccessToken(), 'client_id'=> $client->getClientId (), - 'user_id'=> $user->getId (), + 'user_id'=> $user->id, 'expires'=> new Carbon('+ 2 minute', Config::get ('app.timezone')) ]); + + return [ 'view'=> 'approve', 'session_token'=> $sessiontoken->getToken (), - 'user'=> $user->schema ('basic'), + 'user'=> $user->getViewPresenter (), 'client'=> $client->schema ('basic') ]; } @@ -85,10 +102,11 @@ public static function login ($payload) [ 'access_token'=> Oauth2AccessToken::generateAccessToken(), 'client_id'=> $client->getClientId (), - 'user_id'=> $user->getId (), + 'user_id'=> $user->id, 'expires'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))->addYear () ]); + return [ 'uri'=> $client->getRedirectUri () . '?access_token=' . $accesstoken->getToken () @@ -111,19 +129,18 @@ public static function authorize ($payload) # Validate session token $sessiontoken = Oauth2AccessToken::whereAccessToken ($payload->session_token)->valid ()->first (); - if (!$sessiontoken || $sessiontoken->user->getId () != (int) $payload->approve) + if (!$sessiontoken || $sessiontoken->user->id != (int) $payload->approve) throw new \Cloudoki\InvalidParameterException ('Session expired or invalid approval.'); - # Token handling - Oauth2Authorization::create (['client_id'=> $sessiontoken->client->getClientId (), 'user_id'=> $sessiontoken->user->getId (), 'authorization_date'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))]); + Oauth2Authorization::create (['client_id'=> $sessiontoken->client->getClientId (), 'user_id'=> $sessiontoken->user->id, 'authorization_date'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))]); $accesstoken = Oauth2AccessToken::create ( [ 'access_token'=> Oauth2AccessToken::generateAccessToken(), 'client_id'=> $sessiontoken->client->getClientId (), - 'user_id'=> $sessiontoken->user->getId (), + 'user_id'=> $sessiontoken->user->id, 'expires'=> Carbon::now(new DateTimeZone(Config::get ('app.timezone')))->addYear () ]); @@ -235,7 +252,7 @@ public static function resetpassword ($payload) public static function changepassword ($payload) { $token = $payload->reset_token; - + $user = User::email ($payload->email) ->whereHas ('accounts', function ($q) use ($token) { $q->where ('account_user.reset_token', $token); }) ->first (); @@ -250,7 +267,7 @@ public static function changepassword ($payload) throw new \Cloudoki\InvalidParameterException ('The passwords do not match.'); - + # Update user $user->setPassword ($payload->password) ->setResetToken (null) @@ -292,7 +309,7 @@ public function identifyinvite ($payload) else return [ - 'user'=> $user->schema ('full'), + 'user'=> $user->getViewPresenter (), 'account'=> $account->schema ('basic') ]; } @@ -348,7 +365,7 @@ public function registeruser () public function registerclient ($payload = null) { $payload = $payload ?: json_decode (Input::get ('payload')); - + $client = new Oauth2Client(); $client->appendPayload ($payload) ->save(); diff --git a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php index 919eafe..950f518 100755 --- a/src/Cloudoki/OaStack/Controllers/OaStackViewController.php +++ b/src/Cloudoki/OaStack/Controllers/OaStackViewController.php @@ -6,6 +6,7 @@ use Illuminate\Http\Request; use Cloudoki\OaStack\Controllers\BaseController; use Cloudoki\InvalidParameterException; +use Cloudoki\OaStack\Exceptions\Handler as OaStackHandler; class OaStackViewController extends BaseController { @@ -14,7 +15,7 @@ class OaStackViewController extends BaseController { 'email'=> 'required|email', 'password'=> 'required|min:4', 'client_id'=> 'required|min:18', - 'response_type'=> 'required|min:5', + 'response_type'=> 'required|min:4', 'redirect_uri'=> 'required|min:8', 'state'=> '' ); @@ -59,6 +60,18 @@ class OaStackViewController extends BaseController { 'user_id' => 'required|integer', ); + public function __construct (Request $request) + { + parent::__construct($request); + // Override the base app's global exception handler with this + // package's custom exception handler + // As seen here: https://laracasts.com/discuss/channels/requests/custom-exception-handler-based-on-route-group + \App::singleton( + \Illuminate\Contracts\Debug\ExceptionHandler::class, + OaStackHandler::class + ); + } + /** * User Login * Show user login fields @@ -75,12 +88,13 @@ public function login () */ public function loginrequest () { + // Request Foreground Job $login = $this->restDispatch ('login', 'Cloudoki\OaStack\OAuth2Controller', [], self::$loginRules); - + if (isset ($login->error)) - return view('oastack::oauth2.login', ['error'=> isset ($login->message)? $login->message: "something went wrong"]); + return view('oastack::oauth2.login', ['error'=> isset ($login->error)? $login->error: "something went wrong"]); else if (isset ($login->view)) @@ -184,10 +198,10 @@ public function subscribe ($token) { // Request Foreground Job $invite = $this->restDispatch ('identifyinvite', 'Cloudoki\OaStack\OAuth2Controller', ['token'=> $token], self::$invitationRules); - + // Build View - return view ('oastack::oauth2.subscribe', + return view ('oastack::oauth2.subscribe', [ 'user'=> (array) $invite->user, 'account'=> (array) $invite->account diff --git a/src/Cloudoki/OaStack/Exceptions/Handler.php b/src/Cloudoki/OaStack/Exceptions/Handler.php new file mode 100644 index 0000000..05348b9 --- /dev/null +++ b/src/Cloudoki/OaStack/Exceptions/Handler.php @@ -0,0 +1,50 @@ +view('oastack::oauth2.login', ['error'=> 'Invalid request.']); + } +} diff --git a/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php b/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php index ff71788..bb62cc0 100755 --- a/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php +++ b/src/Cloudoki/OaStack/Models/Oauth2AccessToken.php @@ -2,7 +2,6 @@ namespace Cloudoki\OaStack\Models; -use Cloudoki\OaStack\Models\User; use Cloudoki\OaStack\Models\Oauth2Client; use \Illuminate\Database\Eloquent\Model as Eloquent; @@ -34,7 +33,8 @@ class Oauth2AccessToken extends Eloquent */ public function user () { - return $this->belongsTo (User::class); + $userModelClass = config ('oastack.user_model', 'Cloudoki\\OaStack\\Models\\User'); + return $this->belongsTo ($userModelClass); } /** @@ -98,6 +98,20 @@ public function getToken () return $this->access_token; } + /** + * Expires all authentication tokens of the provided user id. + * + * @param int $userId + * + * @return null + */ + public static function expireAllUserTokens ($userId) + { + self::where('user_id', '=', $userId) + ->whereRaw('expires > now()') + ->update(['expires' => date('Y-m-d H:i:s')]); + } + /** * Generates an unique access token. @@ -112,7 +126,7 @@ public function getToken () */ protected static function generateAccessToken() { - if (function_exists('mcrypt_create_iv')) + if (function_exists('mcrypt_create_iv')) { $randomData = mcrypt_create_iv(20, MCRYPT_DEV_URANDOM); if ($randomData !== false && strlen($randomData) === 20) @@ -128,7 +142,7 @@ protected static function generateAccessToken() return bin2hex($randomData); } - if (@file_exists('/dev/urandom')) + if (@file_exists('/dev/urandom')) { $randomData = file_get_contents('/dev/urandom', false, null, 0, 20); if ($randomData !== false && strlen($randomData) === 20) diff --git a/src/Cloudoki/OaStack/Traits/User.php b/src/Cloudoki/OaStack/Traits/User.php new file mode 100644 index 0000000..0d2ae62 --- /dev/null +++ b/src/Cloudoki/OaStack/Traits/User.php @@ -0,0 +1,75 @@ +first(); + } + + /** + * Acces Token relationship + * + * @return hasMany + */ + public function oauth2accesstokens () + { + return $this->hasMany('Cloudoki\OaStack\Models\Oauth2AccessToken'); + } + + /** + * Authorisations relationship + * + * @return hasMany + */ + public function oauth2authorizations () + { + return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Authorization'); + } + + /** + * Clients relationship + * + * @return hasMany + */ + public function oauth2clients () + { + return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Client'); + } + + /** + * Check password + * + * @param string $value + * @return bool + */ + public function checkPassword ($value) + { + return Hash::check ($value, $this->password); + } + + /** + * Return an object with the most important user properties + * which will be used for the view templates. + * The object must contain at least the following properties: + * - id + * - email + * - firstname + * - lastname + * - fullname + */ + public function getViewPresenter () { + $user = $this->schema ('basic'); + $user->fullname = $user->firstname . ' ' . $user->lastname; + + return $user; + } +} \ No newline at end of file diff --git a/src/config/oastack.php b/src/config/oastack.php index a8969f0..cdeffb2 100755 --- a/src/config/oastack.php +++ b/src/config/oastack.php @@ -1,7 +1,7 @@ 'http://localhost/oauth2/invitation', - 'reset_url' => 'http://localhost/oauth2/reset', - 'privacy_url' => 'http://en.wikipedia.org/wiki/Privacy_policy' + */ + 'invite_url' => env('OASTACK_INVITE_URL', 'http://localhost/oauth2/invitation'), + 'reset_url' => env('OASTACK_RESET_URL', 'http://localhost/oauth2/reset'), + 'privacy_url' => env('OASTACK_PRIVACY_URL', 'http://en.wikipedia.org/wiki/Privacy_policy'), + // Optional. A job dispatcher class with a static `dispatch` method. + 'job_dispatcher' => env('OASTACK_JOB_DISPATCHER', null), + // Optional. The `user` model of the base application. + // The user model must use the provided Traits\User trait. + 'user_model' => env('OASTACK_USER_MODEL', null), ); diff --git a/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php b/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php index 3437d81..9b423c0 100755 --- a/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php +++ b/src/migrations/2016_03_01_094650_oastack_create_oauth_access_tokens_table.php @@ -13,13 +13,13 @@ class OastackCreateOauthAccessTokensTable extends Migration { public function up() { if (!Schema::hasTable('oauth_access_tokens')) - + Schema::create ('oauth_access_tokens', function (Blueprint $table) { $table->increments ('id'); - $table->string ('access_token', 40); + $table->string ('access_token', 40)->unique(); $table->string ('client_id', 80); - $table->integer ('user_id'); + $table->integer ('user_id')->index(); $table->timestamp ('expires'); $table->string ('scope', 80)->nullable (); }); From 0ce11b78d4ac0c40ea2f5e1595b0216d5078aeee Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Wed, 21 Dec 2016 16:39:24 +0000 Subject: [PATCH 12/16] Fixed login issue related to the decoupling. Now the module uses its own User trait as well. --- .../OaStack/Controllers/OAuth2Controller.php | 21 ++----- src/Cloudoki/OaStack/Models/User.php | 58 ++++--------------- 2 files changed, 16 insertions(+), 63 deletions(-) diff --git a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php index 6976773..2665968 100755 --- a/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php +++ b/src/Cloudoki/OaStack/Controllers/OAuth2Controller.php @@ -50,24 +50,15 @@ public static function login ($payload) throw new \Cloudoki\InvalidParameterException ('Invalid e-mail.'); } - $userModelClass = config ('oastack.user_model', null); + $userModelClass = config ('oastack.user_model', User::class); - if ($userModelClass != null) { - // We have to use the base app's user model and authentication strategy - $userModel = app()->make($userModelClass); + // We have to use the base app's user model and authentication strategy + $userModel = app()->make($userModelClass); - $user = call_user_func(array($userModel, 'findByLoginId'), $payload->email); + $user = call_user_func(array($userModel, 'findByLoginId'), $payload->email); - if (!isset($user) || !$user->checkPassword ($payload->password)) { - throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); - } - } else { - // We're allowed to use our own `user` model and authentication strategy - $user = User::email ($payload->email)->first (); - - if (!isset($user) || !$user->checkPassword ($payload->password)) { - throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); - } + if (!isset($user) || !$user->checkPassword ($payload->password)) { + throw new \Cloudoki\InvalidParameterException ('Invalid password or e-mail.'); } # Validate Authorization diff --git a/src/Cloudoki/OaStack/Models/User.php b/src/Cloudoki/OaStack/Models/User.php index 3e97647..94723ff 100755 --- a/src/Cloudoki/OaStack/Models/User.php +++ b/src/Cloudoki/OaStack/Models/User.php @@ -5,6 +5,8 @@ use Cloudoki\OaStack\Models\Oauth2Authorization; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Hash; +use Cloudoki\OaStack\Traits\User as UserTrait; + /** * User Model * Add the namespace if you want to extend your custom User model with this one. @@ -12,7 +14,8 @@ class User extends BaseModel { use SoftDeletes; - + use UserTrait; + /** * The model type. * @@ -40,36 +43,6 @@ public function accounts () return $this->belongsToMany ('Cloudoki\OaStack\Models\Account')->withPivot ('invitation_token'); } - /** - * Acces Token relationship - * - * @return hasMany - */ - public function oauth2accesstokens () - { - return $this->hasMany('Cloudoki\OaStack\Models\Oauth2AccessToken'); - } - - /** - * Authorisations relationship - * - * @return hasMany - */ - public function oauth2authorizations () - { - return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Authorization'); - } - - /** - * Clients relationship - * - * @return hasMany - */ - public function oauth2clients () - { - return $this->hasMany('Cloudoki\OaStack\Models\Oauth2Client'); - } - /** * Get Accounts * All accounts related to the user. @@ -127,7 +100,7 @@ public function getFirstName () public function setFirstName ($firstname) { $this->firstname = $firstname; - + return $this; } @@ -149,10 +122,10 @@ public function getLastName () public function setLastName ($name) { $this->lastname = $name; - + return $this; } - + /** * Get user name * @@ -181,7 +154,7 @@ public function getEmail () public function setEmail ($email) { $this->email = $email; - + return $this; } @@ -194,19 +167,8 @@ public function setEmail ($email) public function setPassword($value) { $this->password = Hash::make ($value); - - return $this; - } - /** - * Check password - * - * @param string $value - * @return bool - */ - public function checkPassword ($value) - { - return Hash::check ($value, $this->password); + return $this; } /** @@ -243,7 +205,7 @@ public function makeToken () return md5 (uniqid ( $rand[rand (0, 9)] . ' ' . $rand[rand (0, 9)], true)); } - + /** * Set Reset Token * From e0f72916e7f8351e750ff998da49993cc44e0092 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Tue, 10 Jan 2017 14:37:42 +0000 Subject: [PATCH 13/16] Added info to README about the Laravel 5.1 maintenance branch and tags. --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index cce7fe2..39b2c9b 100755 --- a/README.md +++ b/README.md @@ -88,6 +88,20 @@ $ nano app/config/app.php $ php artisan dump-autoload ``` +##Laravel 5.1 + +Laravel 5.1 maintenance is kept in the `lvl51` branch and the releases are tagged as `v5.1.x`. + +For the installation follow the same instructions of the Laravel 5.2 installation. Just change the relevant line in `composer.json` to + +``` +"cloudoki/oauth2-stack": "v5.1.*" +``` + +or use a specific version to lock the dependency to it. + +--- + If you go deep into the package you'll find out that the `/oauth2` routes are defined right there. Feel free to override this by copy-pasting the routes to your project `./app/routes.php` file and disabling the include in `OaStackServiceProvider.php`. The same goes for the filters file, which identifies `auth`, a basic token check. From 344e2ddf66f88b29fd6db9ce01a778a9d94a2543 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Tue, 10 Jan 2017 15:33:15 +0000 Subject: [PATCH 14/16] Improved README again for the laravel 5.1 maintenance branch. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39b2c9b..f80107f 100755 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ The goal of this package is to split it up in multiple Framework Branches. Right **v0.5** is the stable Laravel 5.2 compatible release +**v5.1.x** is the tag pattern for the the stable Laravel 5.1 compatible release ##### Dependencies **Oauth2 Server** - The Oauth2 Stack is based on [Brent Shaffer's Oauth2 Server](https://github.com/bshaffer/oauth2-server-php), tweaked for multi-layer usage. @@ -114,7 +115,7 @@ $ php artisan config:publish cloudoki/oauth2-stack ``` *You may also create environment specific configs by placing them like so `app/config/packages/cloudoki/oastack/environment`.* -**Laravel 5.2** +**Laravel 5.1 and 5.2** ``` $ php artisan vendor:publish ``` @@ -133,7 +134,7 @@ The Oauth2 related models, **Oauth2AccessToken**, **Oauth2Authorization**, **Oau $ php artisan migrate --package="cloudoki/oauth2-stack" ``` -**Laravel 5.2** +**Laravel 5.1 and 5.2** ``` $ php artisan vendor:publish --tag="migrations" ``` From 2cb1dcf7ee0246fb44aa91ca9c48214d2ea89972 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Mon, 30 Jan 2017 16:04:09 +0000 Subject: [PATCH 15/16] Providing a more explicit error message for `InvalidParameterException`s. --- src/Cloudoki/OaStack/Exceptions/Handler.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Cloudoki/OaStack/Exceptions/Handler.php b/src/Cloudoki/OaStack/Exceptions/Handler.php index 05348b9..d00f2fd 100644 --- a/src/Cloudoki/OaStack/Exceptions/Handler.php +++ b/src/Cloudoki/OaStack/Exceptions/Handler.php @@ -3,6 +3,7 @@ namespace Cloudoki\OaStack\Exceptions; use Exception; +use Cloudoki\InvalidParameterException; use App\Exceptions\Handler as AppExceptionHandler; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Database\Eloquent\ModelNotFoundException; @@ -45,6 +46,11 @@ public function report(Exception $e) */ public function render($request, Exception $e) { - return response()->view('oastack::oauth2.login', ['error'=> 'Invalid request.']); + if ($e instanceof InvalidParameterException) { + $message = $e->getMessage(); + } else { + $message = 'Invalid request.'; + } + return response()->view('oastack::oauth2.login', ['error'=> $message]); } } From 6f22481a288ec7cb9798d762186b40b1b8952f09 Mon Sep 17 00:00:00 2001 From: Tiago Alves Date: Mon, 20 Mar 2017 17:53:37 +0000 Subject: [PATCH 16/16] Reverted a Laravel 5.1 compatibility change. Change introduced in 99af02628c5dd91791e7fcad6fb376847a98eeff. This branch is for Laravel 5.2+, that's why I'm removing the Laravel 5.1 related change that was merged into this branch. --- src/Cloudoki/OaStack/Controllers/BaseController.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Cloudoki/OaStack/Controllers/BaseController.php b/src/Cloudoki/OaStack/Controllers/BaseController.php index 1ebc57d..ef1402d 100755 --- a/src/Cloudoki/OaStack/Controllers/BaseController.php +++ b/src/Cloudoki/OaStack/Controllers/BaseController.php @@ -5,7 +5,7 @@ use Validator; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Illuminate\Contracts\Validation\ValidationException; +use Illuminate\Validation\ValidationException; use Illuminate\Support\Facades\Redirect; class BaseController extends Controller @@ -47,10 +47,7 @@ protected function prepInput ($attr) // Add display fallback $attr['display'] = $this->request->input ('display', self::display); - $postParams = $this->request->request->all(); - $queryParams = $this->request->all(); - - return array_merge ($queryParams, $postParams, $attr); + return array_merge ($this->request->all(), $attr); } /**