Show more useful error on login failure

develop
kaetemi 3 years ago committed by Nimetu
parent 6d60cfee71
commit 5fcaafbc60

@ -63,6 +63,8 @@ public:
/// Disconnect if connected (otherwise does nothing)
void disconnect();
const char *lastError() { return &m_ErrorBuf[0]; }
protected:
/// Helper
@ -78,6 +80,8 @@ private:
std::vector<uint8> _ReceiveBuffer;
std::string _Auth; // must be kept here because curl only stores the char pointer
std::vector<char> m_ErrorBuf;
};
extern CCurlHttpClient CurlHttpClient;

@ -124,15 +124,17 @@ bool CCurlHttpClient::sendRequest(const std::string& methodWB, const std::string
curl_easy_setopt(_Curl, CURLOPT_WRITEFUNCTION, CCurlHttpClient::writeDataFromCurl);
curl_easy_setopt(_Curl, CURLOPT_WRITEDATA, this);
char errorbuf [CURL_ERROR_SIZE+1];
curl_easy_setopt(_Curl, CURLOPT_ERRORBUFFER, errorbuf);
if (!m_ErrorBuf.size())
m_ErrorBuf.resize(CURL_ERROR_SIZE + 1);
m_ErrorBuf[0] = '\0';
curl_easy_setopt(_Curl, CURLOPT_ERRORBUFFER, &m_ErrorBuf[0]);
// Send
CURLcode res = curl_easy_perform(_Curl);
if (res != 0)
{
if (verbose)
nlwarning(errorbuf);
nlwarning(&m_ErrorBuf[0]);
return false;
}

@ -2832,7 +2832,7 @@ string checkLogin(const string &login, const string &password, const string &cli
{
// ask server for salt
if(!HttpClient.sendGet(url + "?cmd=ask&cp=2&login=" + login + "&lg=" + ClientCfg.LanguageCode, "", pPM->isVerboseLog()))
return "Can't send (error code 60)";
return std::string("Can't send (error code 60) ") + HttpClient.lastError();
if(pPM->isVerboseLog()) nlinfo("Sent request for password salt");
@ -2906,13 +2906,13 @@ string checkLogin(const string &login, const string &password, const string &cli
std::string cryptedPassword = CCrypt::crypt(password, Salt);
if(!HttpClient.sendGet(url + "?cmd=login&login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=2" + "&lg=" + ClientCfg.LanguageCode + customParameters))
return "Can't send (error code 2)";
return std::string("Can't send (error code 2) ") + HttpClient.lastError();
}
else
{
// don't send login and password if empty
if(!HttpClient.sendGet(url + "?cmd=login&clientApplication=" + clientApp + "&cp=2" + "&lg=" + ClientCfg.LanguageCode + customParameters))
return "Can't send (error code 2)";
return std::string("Can't send (error code 2) ") + HttpClient.lastError();
}
// the response should contains the result code and the cookie value
@ -3022,7 +3022,7 @@ string checkLogin(const string &login, const string &password, const string &cli
std::string cryptedPassword = CCrypt::crypt(password, Salt);
if(!HttpClient.sendGet(url + "?login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=2"))
return "Can't send (error code 2)";
return std::string("Can't send (error code 2) ") + HttpClient.lastError();
/*
if(!send(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?login="+login+"&password="+password+"&clientApplication="+clientApp))
return "Can't send (error code 2)";

Loading…
Cancel
Save