/** * Setup the test environment. */ public function setUp() { parent::setUp(); SocialConnection::setUsersModel(User::class); $this->withFactories(__DIR__ . '/../database/factories'); $this->artisan('migrate', ['--database' => 'testing', '--realpath' => realpath(__DIR__ . '/../database/migrations')]); $this->artisan('db:seed', ['--database' => 'testing', '--class' => 'SociableDatabaseSeeder']); $this->beforeApplicationDestroyed(function () { $this->artisan('migrate:rollback'); }); }
public function getAuthLink(SessionManager $session, Manager $auth, $provider) { $user = Socialite::driver($provider)->user(); $dbUser = $auth->user(); $link = SocialConnection::ofCredentials($provider, $user->id)->first(); $linked = !is_null($link); $authenticated = !is_null($dbUser); // Link: Authenticated not linked if ($authenticated && !$linked) { // Link $dbUser->attachProvider($provider, $user); return redirect('/')->with('success', 'Account connected to "' . $provider . '" successfully.'); } elseif (!$authenticated && $linked) { // Log in user $dbUser = $auth->login($link->user_id); return redirect('/')->with('success', 'Authentication with "' . $provider . '" was successful'); } else { // Store to connect accounts after login $session->put('social_link', ['user' => $user, 'provider' => $provider]); // No user found - redirect to login return redirect('login')->with('error', 'No matching records found, please login to link accounts.'); } }
/** * @test */ public function it_can_set_and_retrieve_the_users_model() { SocialConnection::setUsersModel('foo'); $this->assertEquals('foo', SocialConnection::getUsersModel()); }