/**
  * Login or register a user with social provider.
  *
  * @param Request $request
  * @param UserRepository $repository
  * @param $provider
  * @return \Illuminate\Http\RedirectResponse
  */
 public function login(Request $request, UserRepository $repository, $provider)
 {
     $this->assertProvider($provider);
     $providerCode = $request->has('code') || $request->has('oauth_token');
     if (!$providerCode) {
         return $this->getAuthorizationFirst($provider);
     }
     $user = $repository->loginSocialiteUser($this->getSocialiteUser($provider), $provider);
     $this->guard()->login($user);
     flash()->success(trans('messages.login.title', ['name' => $user->name]), trans('messages.login.content'));
     return isset($request->ref) ? redirect(route($request->ref)) : redirect($this->redirectTo);
 }
 /**
  * Update the user profile.
  *
  * @param ProfileRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update(ProfileRequest $request, UserRepository $repository)
 {
     $repository->updateUser($this->user, $request);
     flash()->success(trans('messages.success'), trans('messages.user_profile.profile_success'));
     return redirect()->back();
 }