/**
  * Handle a request to link a social account to a non-social account
  *
  * @param  LoginRequest $request
  * @param  string       $userId  ID of the non-social account to link with the social account
  * @return array        Access token
  */
 public function handleLinkRequest(LoginRequest $request, $userId)
 {
     $socialLogin = $this->socialLoginMapper->findByProviderUserId($request->getProvider(), $request->getProviderUserId());
     if ($socialLogin) {
         throw new LinkedAccountExistsException();
     }
     $user = $this->userService->findById($userId);
     if (!$user) {
         throw new OutOfBoundsException('Account not found', self::EXCEPTION_ACCOUNT_NOT_FOUND);
     }
     $socialLoginEntity = new SocialLoginEntity();
     $socialLoginEntity->setUserId($user->getId())->setProvider($request->getProvider())->setProviderUserId($request->getProviderUserId())->setAccessToken($request->getAccessToken())->setAccessTokenExpires($request->getAccessTokenExpires())->setRefreshToken($request->getRefreshToken());
     $socialLogin = $this->socialLoginMapper->persist($socialLoginEntity);
     return $this->handleLogin($user, $request);
 }
 /**
  * Set the last_login timestamp in the database
  *
  * @param string $userId
  */
 protected function setLastLogin($userId)
 {
     $user = $this->userService->findById($userId);
     $result = $this->userService->update($user, ['last_login' => time()]);
 }