コード例 #1
0
 public function testUserIsRegistered()
 {
     $tw_user = new User();
     $tw_user->map(['id' => '123']);
     $mock = Mockery::mock('Laravel\\Socialite\\Contracts\\Factory');
     $mock->shouldReceive('driver')->once()->with('twitter')->andReturnSelf();
     $mock->shouldReceive('user')->once()->andReturn($tw_user);
     $this->app->instance('Laravel\\Socialite\\Contracts\\Factory', $mock);
     $authMock = Mockery::mock('App\\Services\\Authentication');
     $authMock->shouldReceive('loginOrCreateUser')->with($tw_user, 'twitter')->once();
     $this->app->instance('App\\Services\\Authentication', $authMock);
     $this->get('login/twitter/callback');
     $this->assertRedirectedTo('/');
 }
コード例 #2
0
 /**
  * @test
  */
 public function associateWithExistingUserIfEmailAddressMatches()
 {
     $firstName = 'Jane';
     $lastName = 'Lork';
     //allow GUID to be set
     User::unguard();
     User::create(['guid' => md5(uniqid() . microtime()), 'email' => $this->providerUser->getEmail(), 'first_name' => $firstName, 'last_name' => $lastName, 'primary_address_id' => Address::firstOrFail()->id]);
     User::reguard();
     $this->call('GET', '/login/' . ThirdPartyAuthenticator::PROVIDER_GOOGLE, ['code' => uniqid()]);
     // logged in as pre-existing user
     $this->followRedirects()->see($firstName . ' ' . $lastName);
     //assert user was not created
     $name = explode(' ', $this->providerUser->getName());
     $createdUser = User::where('first_name', $name[0])->where('last_name', $name[1])->where('email', $this->providerUser->getEmail())->where('avatar', $this->providerUser->getAvatar())->count() > 0;
     $this->assertFalse($createdUser);
 }
コード例 #3
0
 /**
  * ユーザを登録する
  *
  * @param User $gitHubUser
  *
  * @return int $userId
  */
 public function registerUser(User $gitHubUser)
 {
     $gitHubId = $gitHubUser->getId();
     // 登録済みであればuser IDを返却
     if ($user = $this->userModel->getUserByGitHubId($gitHubId)) {
         return $user->id;
     }
     // usersに新たに登録
     $userId = $this->userModel->insertUser('tmp');
     // XXX: テーブル設計見直し
     // テーブル格納用データ
     $gitHubInformation = ['user_id' => $userId, 'token' => $gitHubUser->token, 'github_id' => $gitHubUser->getId(), 'nickname' => $gitHubUser->getNickname(), 'name' => $gitHubUser->getName(), 'email' => $gitHubUser->getEmail(), 'avatar' => $gitHubUser->getAvatar()];
     $this->gitHubInfoModel->insert($gitHubInformation);
     return $userId;
 }
コード例 #4
0
ファイル: SocialiteTest.php プロジェクト: TFidryForks/spira
 public function testUniqueUsername()
 {
     // Insert some test users to
     $this->createUser(['username' => 'Foo Baz']);
     $this->createUser(['username' => 'Bar Foo']);
     $this->createUser(['username' => 'BarFoo']);
     $this->createUser(['username' => 'Bar Baz']);
     $this->createUser(['username' => 'BarBaz']);
     $this->createUser(['username' => 'Bar.Baz']);
     $this->createUser(['username' => 'foo']);
     $this->createUser(['username' => 'bar']);
     $this->createUser(['username' => 'bar 1']);
     $this->createUser(['username' => 'bar 2']);
     $user = new User();
     $user->map(['user' => ['first_name' => '', 'last_name' => '']]);
     $user->name = 'Foo Bar';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('Foo Bar', $socialUser->username);
     $user->name = 'Foo Baz';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('FooBaz', $socialUser->username);
     $user->name = 'Bar Baz';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('Baz Bar', $socialUser->username);
     $this->createUser(['username' => 'Baz Bar']);
     $user->name = 'Bar Baz';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('BBaz', $socialUser->username);
     $user->name = 'Foo';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('Foo 1', $socialUser->username);
     $user->name = 'bar';
     $socialUser = ParserFactory::parse($user, 'facebook');
     $this->assertEquals('bar 3', $socialUser->username);
 }
コード例 #5
0
ファイル: AuthController.php プロジェクト: hpiso/quizzFB
 /**
  * @param $user
  * @return \Illuminate\Http\RedirectResponse|\Laravel\Lumen\Http\Redirector
  */
 public function findOrStore(\Laravel\Socialite\Two\User $user)
 {
     $userBase = User::where('id', $user->getId())->first();
     $city = isset($user['location']) ? explode(',', $user['location']['name'])[0] : null;
     $country = isset($user['location']) ? explode(',', $user['location']['name'])[1] : null;
     if ($userBase == null) {
         // L'utilisateur n'existe pas en base, on l'ajoute
         $userBase = new User(['id' => $user->getId(), 'token' => $user->token, 'email' => $user->getEmail(), 'first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'avatar' => $user->getAvatar(), 'avatar_original' => $user->avatar_original, 'gender' => $user['gender'], 'admin' => false, 'age' => $user['age_range']['min'], 'city' => $city, 'country' => trim($country)]);
     } else {
         // Utilisateur trouvé en base, on met à jour ses informations
         $userBase->update(['token' => $user->token, 'email' => $user->getEmail(), 'first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'avatar' => $user->getAvatar(), 'avatar_original' => $user->avatar_original, 'gender' => $user['gender'], 'age' => $user['age_range']['min'], 'city' => $city, 'country' => trim($country)]);
     }
     $userBase->save();
     return $userBase;
 }
コード例 #6
0
ファイル: FacebookService.php プロジェクト: b3zman41/zuck
 public static function createUserForFacebookUser(Two\User $user)
 {
     return User::forceCreate(['id' => $user->getId(), 'username' => $user->getName(), 'avatar' => $user->getAvatar(), 'access_token' => $user->token]);
 }