2017-12-10 11:56:00 +01:00
|
|
|
#include "loginreply.h"
|
|
|
|
|
|
2017-12-10 14:28:07 +01:00
|
|
|
#include <QNetworkReply>
|
2017-12-10 11:56:00 +01:00
|
|
|
|
2017-12-13 23:59:14 +01:00
|
|
|
LoginReply::LoginReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung) :
|
2017-12-10 14:28:07 +01:00
|
|
|
ZeiterfassungReply(zeiterfassung),
|
2017-12-13 23:59:14 +01:00
|
|
|
m_reply(std::move(reply))
|
2017-12-10 14:28:07 +01:00
|
|
|
{
|
2017-12-13 23:59:14 +01:00
|
|
|
connect(m_reply.get(), &QNetworkReply::finished, this, &LoginReply::requestFinished);
|
2017-12-10 14:28:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LoginReply::requestFinished()
|
|
|
|
|
{
|
|
|
|
|
if(m_reply->error() != QNetworkReply::NoError)
|
|
|
|
|
{
|
|
|
|
|
setSuccess(false);
|
2017-12-23 11:14:16 +01:00
|
|
|
setMessage(tr("Request error occured: %0").arg(m_reply->errorString()));
|
2017-12-10 14:28:07 +01:00
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!m_reply->hasRawHeader(QByteArrayLiteral("Location")))
|
|
|
|
|
{
|
|
|
|
|
setSuccess(false);
|
2017-12-12 20:38:58 +01:00
|
|
|
setMessage(tr("Response did not contain a Location header."));
|
2017-12-10 14:28:07 +01:00
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto location = m_reply->rawHeader(QByteArrayLiteral("Location"));
|
|
|
|
|
|
|
|
|
|
if(location == QByteArrayLiteral("/evoApps/pages/home.jsp"))
|
|
|
|
|
{
|
|
|
|
|
setSuccess(true);
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
else if(location == QByteArrayLiteral("/evoApps/pages/login.jsp?error=user"))
|
|
|
|
|
{
|
|
|
|
|
setSuccess(false);
|
|
|
|
|
setMessage(tr("Authentication failure. Please check username and password."));
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setSuccess(false);
|
|
|
|
|
setMessage(tr("An unknown authentication failure occured. Redirected to: %0").arg(QString(location)));
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
m_reply = Q_NULLPTR;
|
|
|
|
|
|
|
|
|
|
Q_EMIT finished();
|
2017-12-10 11:56:00 +01:00
|
|
|
}
|