/** * Handle the report append command. * * @param \Gitamin\Commands\Identity\AddIdentityCommand $command * * @return \Gitamin\Models\Identity */ public function handle(AddIdentityCommand $command) { $data = ['user_id' => $command->userId, 'extern_uid' => $command->data['extern_uid'], 'provider_id' => $command->data['provider_id'], 'nickname' => $command->data['nickname'], 'created_at' => Carbon::now()->toDateTimeString()]; // Create the identify $identify = Identity::create($data); Session::pull('connect_data'); return $identify; }
public function callback($slug) { if (Input::has('code')) { $provider = Provider::where('slug', '=', $slug)->firstOrFail(); try { $extern_user = Socialite::with($slug)->user(); } catch (InvalidStateException $e) { return Redirect::to('/auth/login')->withErrors(['授权失效']); } //检查是否已经连接过 $identity = Identity::where('provider_id', '=', $provider->id)->where('extern_uid', '=', $extern_user->id)->first(); if (is_null($identity)) { Session::put('connect_data', ['provider_id' => $provider->id, 'extern_uid' => $extern_user->id, 'nickname' => $extern_user->nickname]); return Redirect::to('/auth/landing'); } //已经连接过,找出user_id, 直接登录 $user = User::find($identity->user_id); if (!Auth::check()) { Auth::login($user, true); //event(new UserWasLoggedinEvent($user)); } return Redirect::to('/')->withSuccess(sprintf('%s %s', trans('gitamin.awesome'), trans('gitamin.login.success_oauth', ['provider' => $provider->name]))); } }