/**
  * @param string $service
  * @param array $input
  * @return \App\Models\AuthenticatableBase
  */
 public function getAuthModelId($service, $input)
 {
     $columnName = $this->serviceAuthenticationRepository->getAuthModelColumn();
     $authInfo = $this->serviceAuthenticationRepository->findByServiceAndId($service, array_get($input, 'service_id'));
     if (!empty($authInfo)) {
         return $authInfo->{$columnName};
     }
     $authUser = $this->authenticatableRepository->findByEmail(array_get($input, 'email'));
     if (!empty($authUser)) {
         $authInfo = $this->serviceAuthenticationRepository->findByServiceAndAuthModelId($service, $authUser->id);
         if (!empty($authInfo)) {
             return null;
         }
     } else {
         $authUser = $this->authenticatableRepository->create($input);
     }
     $input[$columnName] = $authUser->id;
     $this->serviceAuthenticationRepository->create($input);
     return $authUser->id;
 }
コード例 #2
0
 /**
  * @param  string $token
  * @return \App\Models\Base
  */
 public function signInWithFacebook($token)
 {
     $facebookService = new FacebookService();
     $node = $facebookService->getMe($token);
     if (empty($node)) {
         return null;
     }
     $facebookId = $node->getId();
     $email = $node->getEmail();
     if (empty($email)) {
         return null;
     }
     $user = $this->authenticatableRepository->findByFacebookId($facebookId);
     if (empty($user)) {
         $user = $this->authenticatableRepository->findByEmail($email);
     }
     if (empty($user)) {
         $user = $this->authenticatableRepository->create(['email' => $email, 'password' => '']);
     }
     $guard = $this->getGuard();
     $guard->login($user);
     return $guard->user();
 }