-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
40 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php namespace AdamWathan\EloquentOAuth; | ||
|
||
class EloquentIdentityStore implements IdentityStore | ||
{ | ||
public function getByProvider($provider, $providerUser) | ||
{ | ||
return OAuthIdentity::where('provider', $provider) | ||
->where('provider_user_id', $providerUser->id) | ||
->first(); | ||
} | ||
|
||
public function flush($user, $provider) | ||
{ | ||
OAuthIdentity::where('user_id', $user->getKey()) | ||
->where('provider', $provider) | ||
->delete(); | ||
} | ||
|
||
public function store($identity) | ||
{ | ||
$identity->save(); | ||
} | ||
|
||
public function userExists($provider, $providerUser) | ||
{ | ||
return (bool) $this->getByProvider($provider, $providerUser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,9 @@ | ||
<?php namespace AdamWathan\EloquentOAuth; | ||
|
||
class IdentityStore | ||
interface IdentityStore | ||
{ | ||
public function getByProvider($provider, $providerUser) | ||
{ | ||
return OAuthIdentity::where('provider', $provider) | ||
->where('provider_user_id', $providerUser->id) | ||
->first(); | ||
} | ||
|
||
public function flush($user, $provider) | ||
{ | ||
OAuthIdentity::where('user_id', $user->getKey()) | ||
->where('provider', $provider) | ||
->delete(); | ||
} | ||
|
||
public function store($identity) | ||
{ | ||
$identity->save(); | ||
} | ||
|
||
public function userExists($provider, $providerUser) | ||
{ | ||
return (bool) $this->getByProvider($provider, $providerUser); | ||
} | ||
public function getByProvider($provider, $providerUser); | ||
public function flush($user, $provider); | ||
public function store($identity); | ||
public function userExists($provider, $providerUser); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
|
||
use AdamWathan\EloquentOAuth\OAuthIdentity; | ||
use AdamWathan\EloquentOAuth\IdentityStore; | ||
use AdamWathan\EloquentOAuth\EloquentIdentityStore; | ||
use Illuminate\Database\Eloquent\Model as Eloquent; | ||
use Mockery as M; | ||
use SocialNorm\User as UserDetails; | ||
|
@@ -36,7 +36,7 @@ public function test_get_by_provider() | |
'email' => '[email protected]', | ||
'avatar' => 'http://example.com/photos/john_doe.jpg', | ||
)); | ||
$identities = new IdentityStore; | ||
$identities = new EloquentIdentityStore; | ||
$identity = $identities->getByProvider('facebook', $details); | ||
$this->assertEquals(2, $identity->user_id); | ||
$this->assertEquals('facebook', $identity->provider); | ||
|
@@ -66,7 +66,7 @@ public function test_get_by_provider_when_no_match() | |
'email' => '[email protected]', | ||
'avatar' => 'http://example.com/photos/john_doe.jpg', | ||
)); | ||
$identities = new IdentityStore; | ||
$identities = new EloquentIdentityStore; | ||
$identity = $identities->getByProvider('facebook', $details); | ||
$this->assertNull($identity); | ||
} | ||
|
@@ -88,7 +88,7 @@ public function test_flush() | |
|
||
$this->assertEquals(1, OAuthIdentity::where('provider', 'facebook')->where('user_id', 2)->count()); | ||
|
||
$identities = new IdentityStore; | ||
$identities = new EloquentIdentityStore; | ||
$user = M::mock(); | ||
$user->shouldReceive('getKey')->andReturn(2); | ||
$identities->flush($user, 'facebook'); | ||
|
@@ -107,7 +107,7 @@ public function test_store() | |
|
||
$this->assertEquals(0, OAuthIdentity::count()); | ||
|
||
$identities = new IdentityStore; | ||
$identities = new EloquentIdentityStore; | ||
$identities->store($identity); | ||
|
||
$this->assertEquals(1, OAuthIdentity::count()); | ||
|
@@ -129,7 +129,7 @@ public function test_user_exists_returns_true_when_user_exists() | |
'email' => '[email protected]', | ||
'avatar' => 'http://example.com/photos/john_doe.jpg', | ||
)); | ||
$identities = new IdentityStore; | ||
$identities = new EloquentIdentityStore; | ||
$this->assertTrue($identities->userExists('facebook', $details)); | ||
} | ||
|
||
|
@@ -149,7 +149,7 @@ public function test_user_exists_returns_false_when_user_doesnt_exist() | |
'email' => '[email protected]', | ||
'avatar' => 'http://example.com/photos/john_doe.jpg', | ||
)); | ||
$identities = new IdentityStore; | ||
$identities = new EloquentIdentityStore; | ||
$this->assertFalse($identities->userExists('facebook', $details)); | ||
} | ||
} |