protected function verify(Request $request)
 {
     if (!($email = $request->query('email')) or !($token = $request->query('token'))) {
         return $this->returnErrorView(trans('authentication::verification.link_invalid'));
     }
     if (!($emailVerification = $this->emailVerificationRepository->where('email', '=', $email)->first())) {
         return $this->returnErrorView(trans('authentication::verification.email_not_found', ['email' => $email]));
     }
     $user = $this->userRepository->where('email', '=', $email)->firstOrFail();
     if ($user->isVerified()) {
         return $this->returnErrorView(trans('authentication::verification.already_verified'));
     }
     if ($emailVerification->attempts >= EmailVerification::MAX_ATTEMPTS) {
         return $this->returnBlockedView();
     }
     if ($token !== $emailVerification->token) {
         $emailVerification->increment('attempts');
         return $this->returnErrorView(trans('authentication::verification.attempt_failed', ['time' => $emailVerification->attempts]));
     }
     if ($emailVerification->created_at->diffInHours(Carbon::now()) >= EmailVerification::TIMEOUT_HOURS) {
         return $this->returnErrorView(trans('authentication::verification.link_expired'));
     }
     $this->userRepository->save($user->verify());
     $this->emailVerificationRepository->delete($emailVerification);
     Auth::login($user);
     return view('authentication::__front.verification.success');
 }
 public function handleProviderCallback($provider, UserRepository $userRepository)
 {
     /** @var User $oauthUser */
     $oauthUser = Socialite::driver($provider)->user();
     $oauthId = $oauthUser->getId();
     $idField = $provider . '_id';
     // if user with the oauth id already exists simply authenticate
     // meaning user has used this provider but may not have authenticated manually before
     // or used any other providers
     if ($user = $userRepository->where($idField, '=', $oauthId)->first()) {
         return $this->authenticateAndSendResponse($user);
     }
     // if email exists then add the provider id to user
     // this means user has authencated manually or other providers before
     if ($user = $userRepository->where('email', '=', $oauthUser->getEmail())->first()) {
         $user->{$idField} = $oauthId;
         // verify if not already verified
         list($saved, $user) = $userRepository->save($user->verify());
     } else {
         $user = $userRepository->createOauthUser($oauthUser, $idField, $oauthId);
     }
     return $this->authenticateAndSendResponse($user);
 }