verify_login.cpp 786 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2017 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <nlohmann/json.hpp>
  5. #include "web_service/verify_login.h"
  6. #include "web_service/web_backend.h"
  7. #include "web_service/web_result.h"
  8. namespace WebService {
  9. bool VerifyLogin(const std::string& host, const std::string& username, const std::string& token) {
  10. Client client(host, username, token);
  11. auto reply = client.GetJson("/profile", false).returned_data;
  12. if (reply.empty()) {
  13. return false;
  14. }
  15. nlohmann::json json = nlohmann::json::parse(reply);
  16. const auto iter = json.find("username");
  17. if (iter == json.end()) {
  18. return username.empty();
  19. }
  20. return username == *iter;
  21. }
  22. } // namespace WebService