verify_login.cpp 757 B

123456789101112131415161718192021222324252627
  1. // SPDX-FileCopyrightText: 2017 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <nlohmann/json.hpp>
  4. #include "web_service/verify_login.h"
  5. #include "web_service/web_backend.h"
  6. #include "web_service/web_result.h"
  7. namespace WebService {
  8. bool VerifyLogin(const std::string& host, const std::string& username, const std::string& token) {
  9. Client client(host, username, token);
  10. auto reply = client.GetJson("/profile", false).returned_data;
  11. if (reply.empty()) {
  12. return false;
  13. }
  14. nlohmann::json json = nlohmann::json::parse(reply);
  15. const auto iter = json.find("username");
  16. if (iter == json.end()) {
  17. return username.empty();
  18. }
  19. return username == *iter;
  20. }
  21. } // namespace WebService