From 90e6848863fb43bdc2ac0adfd3fbdcf85fb26411 Mon Sep 17 00:00:00 2001 From: Icehawg Date: Fri, 15 Nov 2013 09:19:03 -0500 Subject: [PATCH 1/3] Modified to work with one table. Added "provider" field. Removed old migrations. Added new one. --- .../LaravelOauth/Eloquent/Facebook.php | 6 --- .../LaravelOauth/Eloquent/Github.php | 6 --- .../LaravelOauth/Eloquent/Google.php | 6 --- .../LaravelOauth/Eloquent/Instagram.php | 6 --- .../LaravelOauth/Eloquent/Oauth.php | 6 +++ .../LaravelOauth/Eloquent/Twitter.php | 6 --- src/controllers/OAuthController.php | 8 ++-- ...13_09_01_024008_migration_oauth_github.php | 37 ------------------- ...13_09_01_024008_migration_oauth_google.php | 37 ------------------- ...09_01_024008_migration_oauth_instagram.php | 37 ------------------- ...3_09_01_024008_migration_oauth_twitter.php | 37 ------------------- ... => 2013_11_15_084112_migration_oauth.php} | 7 ++-- 12 files changed, 14 insertions(+), 185 deletions(-) delete mode 100644 src/Thomaswelton/LaravelOauth/Eloquent/Facebook.php delete mode 100644 src/Thomaswelton/LaravelOauth/Eloquent/Github.php delete mode 100644 src/Thomaswelton/LaravelOauth/Eloquent/Google.php delete mode 100644 src/Thomaswelton/LaravelOauth/Eloquent/Instagram.php create mode 100644 src/Thomaswelton/LaravelOauth/Eloquent/Oauth.php delete mode 100644 src/Thomaswelton/LaravelOauth/Eloquent/Twitter.php delete mode 100644 src/migrations/2013_09_01_024008_migration_oauth_github.php delete mode 100644 src/migrations/2013_09_01_024008_migration_oauth_google.php delete mode 100644 src/migrations/2013_09_01_024008_migration_oauth_instagram.php delete mode 100644 src/migrations/2013_09_01_024008_migration_oauth_twitter.php rename src/migrations/{2013_09_01_024008_migration_oauth_facebook.php => 2013_11_15_084112_migration_oauth.php} (79%) diff --git a/src/Thomaswelton/LaravelOauth/Eloquent/Facebook.php b/src/Thomaswelton/LaravelOauth/Eloquent/Facebook.php deleted file mode 100644 index d0321f1..0000000 --- a/src/Thomaswelton/LaravelOauth/Eloquent/Facebook.php +++ /dev/null @@ -1,6 +0,0 @@ -oauth->user($provider)->getUID(); - $modelName = "Thomaswelton\\LaravelOauth\\Eloquent\\".ucfirst($provider); + $modelName = "Thomaswelton\\LaravelOauth\\Eloquent\\Oauth"; $model = new $modelName(); - $user = $model->where('oauth_uid', '=', $uid)->firstOrFail(); + $user = $model->where('oauth_uid', '=', $uid)->where->('provider', '=', $provider)->firstOrFail(); Auth::loginUsingId($user->user_id); } @@ -49,14 +49,14 @@ public function index($provider) if(is_object($user->$providerClass)){ $model = $user->$providerClass; }else{ - $modelName = "Thomaswelton\\LaravelOauth\\Eloquent\\".$providerClass; + $modelName = "Thomaswelton\\LaravelOauth\\Eloquent\\Oauth"; $model = new $modelName(); } $model->oauth_uid = $uid; $model->access_token = $token->getAccessToken(); $model->expire_time = $token->getEndOfLife(); - + $model->provider = $provider; $user->$provider()->save($model); }else{ throw new NotLoggedInException("NOT_LOGGED_IN", 1); diff --git a/src/migrations/2013_09_01_024008_migration_oauth_github.php b/src/migrations/2013_09_01_024008_migration_oauth_github.php deleted file mode 100644 index 6090583..0000000 --- a/src/migrations/2013_09_01_024008_migration_oauth_github.php +++ /dev/null @@ -1,37 +0,0 @@ -increments('id'); - $table->integer('user_id')->unsigned()->unique(); - $table->text('oauth_uid'); - $table->text('access_token'); - $table->integer('expire_time'); - - $table->timestamps(); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('oauth_github'); - } - -} diff --git a/src/migrations/2013_09_01_024008_migration_oauth_google.php b/src/migrations/2013_09_01_024008_migration_oauth_google.php deleted file mode 100644 index a2b606d..0000000 --- a/src/migrations/2013_09_01_024008_migration_oauth_google.php +++ /dev/null @@ -1,37 +0,0 @@ -increments('id'); - $table->integer('user_id')->unsigned()->unique(); - $table->text('oauth_uid'); - $table->text('access_token'); - $table->integer('expire_time'); - - $table->timestamps(); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('oauth_google'); - } - -} diff --git a/src/migrations/2013_09_01_024008_migration_oauth_instagram.php b/src/migrations/2013_09_01_024008_migration_oauth_instagram.php deleted file mode 100644 index be49a6f..0000000 --- a/src/migrations/2013_09_01_024008_migration_oauth_instagram.php +++ /dev/null @@ -1,37 +0,0 @@ -increments('id'); - $table->integer('user_id')->unsigned()->unique(); - $table->text('oauth_uid'); - $table->text('access_token'); - $table->integer('expire_time'); - - $table->timestamps(); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('oauth_instagram'); - } - -} diff --git a/src/migrations/2013_09_01_024008_migration_oauth_twitter.php b/src/migrations/2013_09_01_024008_migration_oauth_twitter.php deleted file mode 100644 index 3df0292..0000000 --- a/src/migrations/2013_09_01_024008_migration_oauth_twitter.php +++ /dev/null @@ -1,37 +0,0 @@ -increments('id'); - $table->integer('user_id')->unsigned()->unique(); - $table->text('oauth_uid'); - $table->text('access_token'); - $table->integer('expire_time'); - - $table->timestamps(); - - $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::drop('oauth_twitter'); - } - -} diff --git a/src/migrations/2013_09_01_024008_migration_oauth_facebook.php b/src/migrations/2013_11_15_084112_migration_oauth.php similarity index 79% rename from src/migrations/2013_09_01_024008_migration_oauth_facebook.php rename to src/migrations/2013_11_15_084112_migration_oauth.php index c720e7b..ed881ea 100644 --- a/src/migrations/2013_09_01_024008_migration_oauth_facebook.php +++ b/src/migrations/2013_11_15_084112_migration_oauth.php @@ -2,7 +2,7 @@ use Illuminate\Database\Migrations\Migration; -class MigrationOauthFacebook extends Migration { +class MigrationOauth extends Migration { /** * Run the migrations. @@ -11,12 +11,13 @@ class MigrationOauthFacebook extends Migration { */ public function up() { - Schema::create('oauth_facebook', function($table) { + Schema::create('oauth', function($table) { $table->increments('id'); $table->integer('user_id')->unsigned()->unique(); $table->text('oauth_uid'); $table->text('access_token'); $table->integer('expire_time'); + $table->integer('provider'); $table->timestamps(); @@ -31,7 +32,7 @@ public function up() */ public function down() { - Schema::drop('oauth_facebook'); + Schema::drop('oauth'); } } From 7dd7bb418115aaad8f3a1fdad8ec9e7acf7dfaff Mon Sep 17 00:00:00 2001 From: Jean-Guy Landriault Date: Fri, 15 Nov 2013 09:25:44 -0500 Subject: [PATCH 2/3] Update 2013_11_15_084112_migration_oauth.php Whoops. Had provider field as integer instead of text. Fixed that. --- src/migrations/2013_11_15_084112_migration_oauth.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/migrations/2013_11_15_084112_migration_oauth.php b/src/migrations/2013_11_15_084112_migration_oauth.php index ed881ea..b599ac0 100644 --- a/src/migrations/2013_11_15_084112_migration_oauth.php +++ b/src/migrations/2013_11_15_084112_migration_oauth.php @@ -17,7 +17,7 @@ public function up() $table->text('oauth_uid'); $table->text('access_token'); $table->integer('expire_time'); - $table->integer('provider'); + $table->text('provider'); $table->timestamps(); From fdbd0550da8b6c8ffaf34192108eb713c6ed2ae0 Mon Sep 17 00:00:00 2001 From: Jean-Guy Landriault Date: Fri, 15 Nov 2013 16:28:02 -0500 Subject: [PATCH 3/3] Update OAuthController.php --- src/controllers/OAuthController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/OAuthController.php b/src/controllers/OAuthController.php index a38a104..49fbb14 100644 --- a/src/controllers/OAuthController.php +++ b/src/controllers/OAuthController.php @@ -33,7 +33,7 @@ public function index($provider) $modelName = "Thomaswelton\\LaravelOauth\\Eloquent\\Oauth"; $model = new $modelName(); - $user = $model->where('oauth_uid', '=', $uid)->where->('provider', '=', $provider)->firstOrFail(); + $user = $model->where('oauth_uid', '=', $uid)->where('provider', '=', $provider)->firstOrFail(); Auth::loginUsingId($user->user_id); }