1
0
mirror of https://gitlab.com/comunic/comunicterm synced 2024-11-16 10:31:06 +00:00

Get current user ID

This commit is contained in:
Pierre HUBERT 2020-01-09 13:20:46 +01:00
parent 9488cd27a5
commit 963edbf6e3
2 changed files with 14 additions and 0 deletions

View File

@ -1,6 +1,8 @@
#include <cpprest/http_client.h>
#include <cpprest/json.h>
#include <helpers/accounthelper.h>
#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)

View File

@ -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;
}