Extract token from response

This commit is contained in:
Pierre HUBERT 2020-06-12 18:26:55 +02:00
parent 4a54dfcaed
commit dde3ad35df
3 changed files with 14 additions and 1 deletions

View File

@ -1,3 +1,5 @@
#include <QJsonDocument>
#include "apiresponse.h"
APIResponse::APIResponse(int code, QByteArray content) :
@ -16,7 +18,14 @@ QByteArray APIResponse::getContent() const
return mContent;
}
bool APIResponse::isError()
{
return mCode != 200;
}
QJsonObject APIResponse::getObject() const
{
return QJsonDocument::fromJson(mContent).object();
}

View File

@ -5,6 +5,7 @@
*/
#include <QByteArray>
#include <QJsonObject>
#pragma once
@ -19,6 +20,8 @@ public:
bool isError();
QJsonObject getObject() const;
private:
int mCode;
QByteArray mContent;

View File

@ -83,7 +83,8 @@ void LoginWindow::onResponse(APIResponse res)
return;
}
QMessageBox::information(this, "ok", "success");
auto token = res.getObject().value("tokens").toObject().value("token1").toString();
QMessageBox::information(this, "ok", token);
}
void LoginWindow::on_submitButton_clicked()