/**
  * Attempt to find a UserInterface by given login credentials
  * returns the UserInterface or null on error
  *
  * @param array $credentials
  * @return null|User
  */
 public function findByAuth($provider, $identifier)
 {
     $user = null;
     $login = $this->repository->findByAuth($provider, $identifier);
     if ($login !== null) {
         $user = $login->getUser();
     }
     return $user;
 }
 /**
  * Attempt to login to a social-auth provider
  * If successful, attach the social-auth user to the currently logged in user on this system
  *
  * @param $provider_name
  * @return \Illuminate\Http\RedirectResponse|null
  */
 public function attach($provider_name)
 {
     $response = null;
     $profile = null;
     $identifier = $this->auth($provider_name, $profile);
     if (!$this->checkRegistered($provider_name, $identifier)) {
         $id = Auth::user()->getAuthIdentifier();
         $login = $this->login_repository->create();
         $login->setProvider($provider_name);
         $login->setIdentifier($identifier);
         $login->setUser($id);
         if ($this->login_repository->save($login)) {
             $providers = SocialAuth::getConnectedProviders();
             $socialProfile = $providers[$provider_name]->getProfile();
             Event::fire('social-auth.attach', ['user' => Auth::user(), 'provider' => $provider_name, 'profile' => $socialProfile]);
             $response = Redirect::back()->with(['message' => trans('social-auth::user.account attach success', ['provider' => $provider_name, 'accountname' => $socialProfile->getDisplayName()])]);
         } else {
             $response = Redirect::back()->withErrors(['message' => trans('social-auth::user.account attach fail', ['accoutnname' => $profile->displayName])]);
         }
     } else {
         $response = Redirect::back()->withErrors(['message' => trans('social-auth::user.account already registered', ['accountname' => $profile->displayName])]);
     }
     return $response;
 }