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