Esempio n. 1
0
         // First time this google ID appeared in the DB
         $googleProvider->save();
         $user->fetchProviders();
         $jwt = $user->getJWT();
         $headersHandler->sendJSONData(['token' => $jwt]);
         $outputHandler->write($jwt);
     } else {
         // Someone is already using that account with other Vote App account
         $headersHandler->sendHeaderCode(401);
         $headersHandler->sendJSONData(['error' => "google account already in use"]);
         $outputHandler->write("google account " . $retrievedData['email'] . " already in use");
     }
 } else {
     // b from the list
     $googleProvider = new GoogleProvider($database, 0, $google_client);
     $accessToken = $googleProvider->getAccessToken($code);
     $userGoogleData = $googleProvider->retrieveData();
     // Check if id from userGoogleData exists as google_id in google_users
     $checkIDQuery = $database->prepare("SELECT id, user_id FROM google_users WHERE google_id = :googleID LIMIT 1;");
     $checkIDQuery->bindParam(":googleID", $userGoogleData['id'], PDO::PARAM_INT);
     $checkIDQuery->execute();
     $checkIDData = $checkIDQuery->fetch(PDO::FETCH_ASSOC);
     if ($checkIDData) {
         // Already exists, log in existing user
         $user = new User($database);
         $user->fetchUser($checkIDData['user_id']);
         $jwt = $user->getJWT();
         $headersHandler->sendJSONData(['token' => $jwt]);
         $outputHandler->write($jwt);
     } else {
         // Does not exist, register user