refs #751, detect invalid JSON message

(which normally means a PHP error message in HTML)
* utility function to remove HTML parts
* adjustments
This commit is contained in:
Klaus Basan
2016-08-31 17:13:40 +02:00
committed by Roland Winklmeier
parent 2cc88d9c6a
commit 03c642d88a
4 changed files with 22 additions and 5 deletions

View File

@@ -109,12 +109,18 @@ namespace BlackCore
if (nwReply->error() == QNetworkReply::NoError)
{
QString json(nwReply->readAll());
const QString json(nwReply->readAll().trimmed());
if (json.isEmpty())
{
CLogMessage(this).error("Authentication failed, no response from %1") << urlString;
return;
}
if (!json.startsWith('{') || !json.endsWith('}'))
{
CLogMessage(this).error("Illegal JSON object: %1") << CNetworkUtils::removeHtmlPartsFromPhpErrorMessage(json);
return;
}
QJsonObject jsonObj(Json::jsonObjectFromString(json));
CAuthenticatedUser user(CAuthenticatedUser::fromDatabaseJson(jsonObj));