/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('social_provider_types')->delete();
     SocialProviderType::create(['name' => 'facebook']);
     SocialProviderType::create(['name' => 'google']);
     SocialProviderType::create(['name' => 'twitter']);
 }
Beispiel #2
0
 public function socialCallback($provider)
 {
     $socialProviderType = SocialProviderType::where('name', $provider)->first();
     $socialProviderData = Socialize::with($provider)->user()->map([]);
     $socialProvider = SocialProvider::where('social_provider_id', $socialProviderData->id)->where('social_provider_type_id', $socialProviderType->id)->first();
     if (Auth::check()) {
         $user = Auth::user();
         if (!$socialProvider) {
             $socialProvider = new SocialProvider();
             $socialProvider->token = isset($socialProviderData->token) ? $socialProviderData->token : null;
             $socialProvider->social_provider_id = isset($socialProviderData->id) ? $socialProviderData->id : null;
             $socialProvider->token_secret = isset($socialProviderData->tokenSecret) ? $socialProviderData->tokenSecret : '';
             $socialProvider->social_provider_type_id = $socialProviderType->id;
             $socialProvider->nickname = '' + $socialProviderData->nickname;
             $socialProvider->email = $socialProviderData->email;
             $socialProvider->name = $socialProviderData->name;
             $socialProvider->avatar = $socialProviderData->avatar;
             $socialProvider->other_provider_info = \Psy\Util\Json::encode($socialProviderData);
             $socialProvider->save();
             $user->socialProviders()->save($socialProvider);
             Auth::login($user);
         }
     } else {
         if ($socialProvider) {
             Auth::login($socialProvider->user);
         } else {
             $socialProvider = new SocialProvider();
             $socialProvider->token = isset($socialProviderData->token) ? $socialProviderData->token : null;
             $socialProvider->social_provider_id = isset($socialProviderData->id) ? $socialProviderData->id : null;
             $socialProvider->token_secret = isset($socialProviderData->tokenSecret) ? $socialProviderData->tokenSecret : '';
             $socialProvider->social_provider_type_id = $socialProviderType->id;
             $socialProvider->nickname = '' + $socialProviderData->nickname;
             $socialProvider->email = $socialProviderData->email;
             $socialProvider->name = $socialProviderData->name;
             $socialProvider->avatar = $socialProviderData->avatar;
             $socialProvider->other_provider_info = \Psy\Util\Json::encode($socialProviderData);
             $socialProvider->save();
             $user = User::firstOrNew(['email' => $socialProvider->email]);
             $user->name = isset($user->name) ? $user->name : $socialProvider->name;
             $user->username = null;
             $user->password = null;
             $user->email = isset($user->email) ? $user->email : $socialProvider->email;
             $user->avatar = isset($user->avatar) ? $user->avatar : $socialProvider->avatar;
             $user->save();
             $user->socialProviders()->save($socialProvider);
             Auth::login($user);
         }
     }
 }