/** * @param Request $request * * @return \Illuminate\Http\JsonResponse|null * * @throws ActionCanceledException */ public function create(Request $request) { $event_instance = new UserCreate($request, $this->setUser()); if ($this->events->fire($event_instance) === false) { throw new ActionCanceledException('user-create'); } $event_results = $this->events->fire(new UserCreateValidate($request)); $validation_result = (new EventCollector())->push($event_results)->asValidator(); if ($validation_result !== null) { return $validation_result; } $this->userRepository->create($request->all()); return $this->authenticate($request); }
/** * Handle social provider callback action for authorisation * * @param string $provider */ public function handle($provider) { $user = $this->socialite()->driver($provider)->user(); //Check is this email present in DB $existing = $this->social->findByProvider($user->getId(), $provider); if (empty($existing)) { //There is no combination of this social id and provider, so create new one // As there no use of user if social is not created, do this in database transaction $existing = DB::transaction(function () use($user, $provider) { $socialUser = $this->social->create(['social_id' => $user->getId(), 'provider' => $provider, 'user_id' => $this->user->create(['email' => $user->getEmail(), 'name' => $user->getName()])->id]); return $socialUser; }); } Auth::login($existing->user, true); }