1
0
mirror of https://gitlab.com/comunic/comunicterm synced 2025-06-19 16:45:17 +00:00

Can set login tokens from command line

This commit is contained in:
2020-01-10 15:31:07 +01:00
parent c48659057e
commit daa4a24941
3 changed files with 60 additions and 6 deletions

View File

@ -39,20 +39,39 @@ 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();
if(!refreshUserID())
return ERROR;
// 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;
}
bool AccountHelper::signedIn()
{
return mToken1.length() > 0 && mToken2.length() > 0 && mUserID > 0;
}
bool AccountHelper::refreshUserID()
{
// Get current user ID
auto response = ApiRequest("user/getCurrentUserID", true).exec();
if(response.code() != 200) return false;
AccountHelper::mUserID = response.object().at("userID").as_number().to_int32();
return true;
}
int AccountHelper::userID()
{
return mUserID;
}
void AccountHelper::setLoginTokens(std::vector<string> tokens)
{
AccountHelper::mToken1 = tokens[0];
AccountHelper::mToken2 = tokens[1];
}
vector<string> AccountHelper::loginTokens()
{
auto tokens = vector<string>();

View File

@ -25,8 +25,12 @@ public:
const std::string &pass);
static bool signedIn();
static bool refreshUserID();
static int userID();
static void setLoginTokens(std::vector<std::string> tokens);
static std::vector<std::string> loginTokens();
private: