-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperasite.cpp
49 lines (37 loc) · 1.25 KB
/
operasite.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "operasite.h"
#include <QTextStream>
#define cout QTextStream(stdout)
#define cin QTextStream(stdin)
operaSite::operaSite(QObject *parent) : QObject(parent)
{
pedido = new QNetworkRequest(urlPedidos);
pedido->setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded; charset=UTF-8");
}
bool operaSite::fazLogin(QString usuario, QString senha)
{
dadosPedido.append("user=" + usuario + "&");
dadosPedido.append("password=" + senha + "&");
dadosPedido.append("hf=login");
QNetworkReply *resposta_login = gerenciadorConexao.post(*pedido, dadosPedido);
QEventLoop loop_espera;
QObject::connect(resposta_login, SIGNAL(finished()), &loop_espera, SLOT(quit()));
loop_espera.exec();
dadosPedido.clear();
if(resposta_login->readAll() == "\"1\"")
return true;
else
return false;
}
int operaSite::pegaSaldo()
{
dadosPedido.append("hf=exibir-saldo&restaurante=0");
QNetworkReply *resposta_saldo = gerenciadorConexao.post(*pedido, dadosPedido);
QEventLoop loop_espera;
connect(resposta_saldo, SIGNAL(finished()), &loop_espera, SLOT(quit()));
loop_espera.exec();
dadosPedido.clear();
if (resposta_saldo->readAll().contains("Sem saldo no momento"))
return 0;
else
return -1; // Não implementado ainda :(
}