Пример #1
0
 /**
  * Create a social entry and user if not exists
  *
  * @param array                  $socialData
  * @param SocialRedirectContract $listener
  *
  * @return mixed
  */
 public function firstOrCreate(array $socialData, SocialRedirectContract $listener)
 {
     $account = $this->model->whereEmail($socialData['email'])->whereProvider($socialData['provider'])->first();
     if ($account) {
         // update social account info and swap it with the existing user
         $user = $this->updateAccountInfo($account, $socialData);
         flash(trans('auth.successLogin', ['name' => $account->user->name]));
     } else {
         // create new user if not exists
         $user = User::whereEmail($socialData['email'])->first();
         $user = $this->createUserIfNotExist($user, $socialData);
         // crate new social account from the user
         $account = $user->socials()->create($socialData);
     }
     return $listener->onSocialLoginSuccess($user);
 }
Пример #2
0
 /**
  * Create a user if not exists
  *
  * @param array $userData
  * @param       $listener
  *
  * @return mixed
  * @throws \Exception
  */
 public function firstOrCreate(array $userData, SocialRedirectContract $listener)
 {
     $user = $this->model->whereEmail($userData['email'])->first();
     if ($user) {
         $this->updateUserInfo($user, $userData);
         if ($user->activated != 1) {
             event('UserActivated', [$user]);
         }
         flash(trans('auth.successLogin', ['name' => $user->name]));
     } else {
         $user = $this->model->create($userData);
         // Grant default Role to this User
         $defaultRole = Role::whereSlug(config('acl.defaultRole'))->first();
         $user->attachRole($defaultRole);
         $user = $user->fresh();
         event('UserActivated', [$user]);
         flash(trans('auth.activated'));
     }
     return $listener->onSocialLoginSuccess($user);
 }