mirror of
				https://gitlab.com/comunic/comunicterm
				synced 2025-11-04 12:14:04 +00:00 
			
		
		
		
	Can set login tokens from command line
This commit is contained in:
		@@ -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>();
 | 
			
		||||
 
 | 
			
		||||
@@ -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:
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user