int api_validate_barcode(QString data){ QMap <QString, QString> map; map["barcode"] = data; map["token"] = g_token; QDomDocument doc; int http = api_request(&doc, "/api/tickets/validate-barcode/", map); if(doc.isNull() || http != STATUS_HTTP_OK) return MAKELRESULT(0, http); QDomElement root = doc.documentElement(); QDomElement statusText = root.firstChildElement("statusText"); if(!statusText.isNull()){ printf("[api_login] found statusText node\n"); if(statusText.text().compare("OK_VALID")){ printf("[api_validate_barcode] fail"); return MAKELRESULT(STATUS_GENERAL_FAILURE, http); } } QDomElement edata = root.firstChildElement("data"); if(!data.isNull()){ QDomElement ticketStatusCode = edata.firstChildElement("ticketStatusCode"); if(!ticketStatusCode.isNull()){ std::cout << "[api_validate_barcode] http code = " << http << "\n"; std::cout << "[api_validate_barcode] return code = " << MAKELRESULT(ticketStatusCode.text().toStdString().at(0) - '0', http) << "\n"; return MAKELRESULT(ticketStatusCode.text().toStdString().at(0) - '0', http); } } return MAKELRESULT(STATUS_GENERAL_FAILURE, http); }
int api_checkin_barcode(QString data, BTS_Sales *bts){ QMap <QString, QString> map; map["barcode"] = data; map["token"] = g_token; QDomDocument doc; int http = api_request(&doc, "/api/tickets/check-in-barcode/", map); return api_checkin2(data, doc, bts, http); }
int api_checkin_name(QString first, QString last, int event_id, BTS_Sales *bts){ QMap <QString, QString> map; map["firstName"] = first; map["lastName"] = last; map["token"] = g_token; QDomDocument doc; int http = api_request(&doc, "/api/attendees/find/", map); if(http == STATUS_HTTP_NOTFOUND){ // no attendee was found! QMessageBox::information(bts, "Attendee Not Found", "This attendee does not exist! Check spelling of name?"); return MAKELRESULT(STATUS_CHECKIN_FAIL, http); } QDomElement root = doc.documentElement(); QDomElement edata = root.firstChildElement("data"); if(!edata.isNull()){ QDomElement attendee = edata.firstChildElement("attendee"); if(!attendee.isNull()){ std::cout << "[api_checkin_name] found an attendee!\n"; QDomElement ticket = attendee.firstChildElement("ticket"); while(!ticket.isNull()){ // ok so a ticket was found //printf("[api_checkin_name] debug: event id: %d || %d\n", event_id, ticket.attribute("event_id").toInt()); if(ticket.attribute("event_id").toInt() == event_id && (ticket.attribute("status").toInt() == 1 || ticket.attribute("status").toInt() == 254)){ std::cout << "[api_checkin_name] found a ticket for this attendee! id: " + ticket.attribute("ticket_id").toStdString() + "\n"; return api_checkin(ticket.attribute("event_id") + "-" + ticket.attribute("batch") + "-" + ticket.attribute("ticket_id") + "-" + ticket.attribute("checksum"), bts); }else{ ticket = ticket.nextSiblingElement(); } } // no ticket was found! QMessageBox::information(bts, "Ticket Not Found", "This attendee does not have a ticket to this event!"); return MAKELRESULT(STATUS_CHECKIN_FAIL, http); }else{ // no attendee was found! QMessageBox::information(bts, "Attendee Not Found", "This attendee does not exist! Check spelling of name?"); return MAKELRESULT(STATUS_CHECKIN_FAIL, http); } }else{ // ??? QMessageBox::information(bts, "Error", "A server error probably occured."); return MAKELRESULT(STATUS_CHECKIN_FAIL, http); } return MAKELRESULT(STATUS_CHECKIN_FAIL, http); }
int api_logout(){ QMap <QString, QString> map; map["token"] = g_token; std::cout << "[api_logout] fdsdfsdf!\n"; // todo: actual error checking! if(api_request(NULL, "/api/access/logout/", map) != STATUS_HTTP_OK) return STATUS_GENERAL_FAILURE; std::cout << "[api_logout] success!\n"; return 0; }
int api_checkin(QString data, BTS_Sales *bts){ QMap <QString, QString> map; QStringList params = data.split("-"); map["event"] = params.at(0); map["batch"] = params.at(1); map["ticket"] = params.at(2); map["checksum"] = params.at(3); map["token"] = g_token; QDomDocument doc; int http = api_request(&doc, "/api/tickets/check-in/", map); return api_checkin2(data, doc, bts, http); }
/** * @brief Function that sends the multipart message request to the API server. * Shows the image being OCR'd in the left-hand side of the interface */ void MainWindow::recognize(){ QHttpMultiPart* multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType); //set up http part message to send to api that contains image data QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/gif")); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\"; filename=\"./Polish_test2.gif\"")); QFile* file = new QFile(fileName); //debugging: make sure file was uploaded if(!file->open(QIODevice::ReadOnly)){ qDebug() << "# Could not upload/open file"; } QByteArray fileContent(file->readAll()); imagePart.setBody(fileContent); //append image data, api key, language, and overlay setting to multipart multipart->append(imagePart); multipart->append(part_parameter("apikey","3653fc62e388957")); multipart->append(part_parameter("language","pol")); multipart->append(part_parameter("isOverlayRequired","false")); //ocr api url QUrl api_url("https://apifree2.ocr.space/parse/image"); //create network request obj that contains the api url QNetworkRequest api_request(api_url); manager = new QNetworkAccessManager; //=(url, multipart encoded message) reply = manager->post(api_request, multipart); QObject::connect(reply, SIGNAL(finished()), this, SLOT(networkData())); //debugging: make sure file was opened; if 0 bytes, it wasn't! qDebug() << file->size() << "bytes"; imagePart.setBodyDevice(file); file->setParent(multipart); networkData(); }
int api_login(QString username, QString password){ QMap <QString, QString> map; map["username"] = username; map["password"] = password; QDomDocument doc; int http = api_request(&doc, "/api/access/login/", map); if(doc.isNull() || http == STATUS_CONNECT_ERROR){ return MAKELRESULT(STATUS_GENERAL_FAILURE, http); } QDomElement root = doc.documentElement(); //QDomNode n = root.firstChild(); QDomElement statusText = root.firstChildElement("statusText"); if(!statusText.isNull()){ printf("[api_login] found statusText node!!!\n"); if(statusText.text().compare("OK")){ printf("[api_login] bad user/password\n"); return MAKELRESULT(STATUS_LOGIN_FAIL, STATUS_HTTP_ACCESSDENIED); } } QDomElement data = root.firstChildElement("data"); if(!data.isNull()){ QDomElement token = data.firstChildElement("token"); if(!token.isNull()){ g_token = token.text(); std::cout << "[api_login] token found: " << g_token.toStdString() + "\n"; return MAKELRESULT(STATUS_LOGIN_OK, http); } } return MAKELRESULT(STATUS_LOGIN_FAIL, http); }