From 963edbf6e320adaa9993b1707ae2d5a6ff0755c1 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 9 Jan 2020 13:20:46 +0100 Subject: [PATCH] Get current user ID --- api_request.cpp | 8 ++++++++ helpers/accounthelper.cpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/api_request.cpp b/api_request.cpp index fa54221..1eb0fbc 100644 --- a/api_request.cpp +++ b/api_request.cpp @@ -1,6 +1,8 @@ #include #include +#include + #include "api_request.h" #include "config.h" @@ -14,6 +16,12 @@ ApiRequest::ApiRequest(const std::string &uri, bool needLogin) { this->addArg("serviceName", API_CLIENT_NAME); this->addArg("serviceToken", API_CLIENT_TOKEN); + + if(needLogin) { + const auto tokens = AccountHelper::loginTokens(); + this->addArg("userToken1", tokens[0]); + this->addArg("userToken2", tokens[1]); + } } void ApiRequest::addArg(const std::string &name, const std::string &value) diff --git a/helpers/accounthelper.cpp b/helpers/accounthelper.cpp index 31874e4..3d3dce3 100644 --- a/helpers/accounthelper.cpp +++ b/helpers/accounthelper.cpp @@ -39,6 +39,12 @@ LoginResult AccountHelper::Login(const std::string &email, const std::string &pa AccountHelper::mToken1 = tokens.at("token1").as_string(); AccountHelper::mToken2 = tokens.at("token2").as_string(); + + // Get current user ID + auto response = ApiRequest("user/getCurrentUserID", true).exec(); + if(response.code() != 200) return ERROR; + AccountHelper::mUserID = response.object().at("userID").as_number().to_int32(); + return SUCCESS; }