When receiving online user credentials insert them into the model.
This commit is contained in:
@ -23,6 +23,8 @@ ServerCommunicator::ServerCommunicator(GenericCore* core)
|
||||
connect(m_core, &GenericCore::sendPostRequest, this,
|
||||
&ServerCommunicator::onSendPostRequestTriggered);
|
||||
connect(this, &ServerCommunicator::biddingsChanged, m_core, &GenericCore::onBiddingsChanged);
|
||||
connect(this, &ServerCommunicator::onlineUserAccountReceived, m_core,
|
||||
&GenericCore::onOnlineUserAccountReceived);
|
||||
}
|
||||
|
||||
bool ServerCommunicator::sslSupported() const {
|
||||
@ -133,7 +135,8 @@ void ServerCommunicator::onGetReplyFailure(const GetRequestTypes type, const QSt
|
||||
m_core->displayStatusMessage(message);
|
||||
}
|
||||
|
||||
void ServerCommunicator::onSendPostRequestTriggered(const PostRequestTypes type, QVariant data) {
|
||||
void ServerCommunicator::onSendPostRequestTriggered(const PostRequestTypes type,
|
||||
const QByteArray data) {
|
||||
QString path;
|
||||
switch (type) {
|
||||
case RegisterUser:
|
||||
@ -152,16 +155,7 @@ void ServerCommunicator::onSendPostRequestTriggered(const PostRequestTypes type,
|
||||
|
||||
const QNetworkRequest request = m_serviceApi->createRequest(path);
|
||||
|
||||
QJsonDocument doc = QJsonDocument();
|
||||
QJsonObject rootObject;
|
||||
|
||||
QJsonObject itemObject;
|
||||
itemObject.insert("email", data.toString());
|
||||
rootObject.insert("user", itemObject);
|
||||
|
||||
doc.setObject(rootObject);
|
||||
|
||||
m_restManager->post(request, doc, this, [this, type](QRestReply& reply) {
|
||||
m_restManager->post(request, data, this, [this, type](QRestReply& reply) {
|
||||
if (reply.isSuccess()) {
|
||||
int statusCode = reply.httpStatus();
|
||||
qInfo() << "Request successful. Status code:" << statusCode;
|
||||
@ -187,7 +181,7 @@ void ServerCommunicator::onPostReplySuccessful(const PostRequestTypes type,
|
||||
switch (type) {
|
||||
case RegisterUser:
|
||||
qInfo() << "Register user successful:" << type;
|
||||
m_core->displayStatusMessage(doc.toJson());
|
||||
onlineUserAccountReply(doc);
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Can't match request type:" << type;
|
||||
@ -225,6 +219,16 @@ void ServerCommunicator::currentBiddingsReply(const QJsonDocument jsonDoc) {
|
||||
.depotWishOne = "one",
|
||||
.depotWishTwo = "two"};
|
||||
const QList<bidding> biddings{dummyBidding};
|
||||
|
||||
emit biddingsChanged(roundNumber, biddings);
|
||||
}
|
||||
|
||||
void ServerCommunicator::onlineUserAccountReply(const QJsonDocument jsonDoc) {
|
||||
qInfo() << "Online user account received.";
|
||||
// TODO move data extraction of jsonDoc into JsonParser
|
||||
const QJsonObject rootObject = jsonDoc["data"].toObject();
|
||||
const QString emailAddress = rootObject["email"].toString();
|
||||
const QString uuid = rootObject["id"].toString();
|
||||
const QString token = rootObject["token"].toString();
|
||||
|
||||
emit onlineUserAccountReceived(emailAddress, uuid, token);
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ class ServerCommunicator : public QObject {
|
||||
void onGetReplySuccessful(const GetRequestTypes type, const QJsonDocument doc);
|
||||
void onGetReplyFailure(const GetRequestTypes type, const QString errorString);
|
||||
|
||||
void onSendPostRequestTriggered(const PostRequestTypes type, QVariant data);
|
||||
void onSendPostRequestTriggered(const PostRequestTypes type, const QByteArray data);
|
||||
void onPostReplySuccessful(const PostRequestTypes type, const QJsonDocument doc);
|
||||
void onPostReplyFailure(const PostRequestTypes type, const QString errorString);
|
||||
|
||||
@ -45,6 +45,9 @@ class ServerCommunicator : public QObject {
|
||||
|
||||
void currentBiddingRoundChanged(int round, bool isRunning);
|
||||
void biddingsChanged(int round, QList<bidding> biddings);
|
||||
void onlineUserAccountReceived(const QString mailAddress,
|
||||
const QString uuid,
|
||||
const QString accessToken);
|
||||
|
||||
private:
|
||||
GenericCore* m_core = nullptr;
|
||||
@ -60,6 +63,7 @@ class ServerCommunicator : public QObject {
|
||||
/// reply parser
|
||||
void currentBiddingRoundChangedReply(const QJsonDocument jsonDoc);
|
||||
void currentBiddingsReply(const QJsonDocument jsonDoc);
|
||||
void onlineUserAccountReply(const QJsonDocument jsonDoc);
|
||||
};
|
||||
|
||||
#endif // SERVERCOMMUNICATOR_H
|
||||
|
||||
Reference in New Issue
Block a user