summaryrefslogtreecommitdiffstats
path: root/qt-ui/subsurfacewebservices.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-09 17:16:31 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-09 17:16:31 -0700
commit8282ed23488b734f126bf58fc18474c4a7db5c23 (patch)
tree994b4919a16917a71570c47e7bd5bbdb54e5d54d /qt-ui/subsurfacewebservices.cpp
parent9d0f2a6571f541862fd8204c067ea2f5ed2c4091 (diff)
parent57507cfb93984e520fdd9545c84ea3b921c2914e (diff)
downloadsubsurface-8282ed23488b734f126bf58fc18474c4a7db5c23.tar.gz
Merge branch 'cloudstorage'
Diffstat (limited to 'qt-ui/subsurfacewebservices.cpp')
-rw-r--r--qt-ui/subsurfacewebservices.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp
index 5e7f016dd..6050782b2 100644
--- a/qt-ui/subsurfacewebservices.cpp
+++ b/qt-ui/subsurfacewebservices.cpp
@@ -934,3 +934,61 @@ QNetworkReply* UserSurveyServices::sendSurvey(QString values)
reply = manager()->get(request);
return reply;
}
+
+CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : QObject(parent)
+{
+ userAgent = getUserAgent();
+
+}
+
+#define CLOUDURL "https://cloud.subsurface-divelog.org/"
+#define CLOUDBACKENDSTORAGE CLOUDURL "storage"
+#define CLOUDBACKENDVERIFY CLOUDURL "verify"
+
+QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password, QString pin)
+{
+ QString payload(email + " " + password);
+ QUrl requestUrl;
+ if (pin == "") {
+ requestUrl = QUrl(CLOUDBACKENDSTORAGE);
+ } else {
+ requestUrl = QUrl(CLOUDBACKENDVERIFY);
+ payload += " " + pin;
+ }
+ QNetworkRequest *request = new QNetworkRequest(requestUrl);
+ request->setRawHeader("Accept", "text/xml, text/plain");
+ request->setRawHeader("User-Agent", userAgent.toUtf8());
+ request->setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
+ reply = WebServices::manager()->post(*request, qPrintable(payload));
+ connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished()));
+ connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
+ connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
+ SLOT(uploadError(QNetworkReply::NetworkError)));
+ return reply;
+}
+
+void CloudStorageAuthenticate::uploadFinished()
+{
+ QString cloudAuthReply(reply->readAll());
+ qDebug() << "Completed connection with cloud storage backend, response" << cloudAuthReply;
+ if (cloudAuthReply == "[VERIFIED]") {
+ prefs.show_cloud_pin = false;
+ emit finishedAuthenticate(prefs.show_cloud_pin);
+ } else if (cloudAuthReply == "[VERIFY]") {
+ prefs.show_cloud_pin = true;
+ emit finishedAuthenticate(prefs.show_cloud_pin);
+ }
+}
+
+void CloudStorageAuthenticate::uploadError(QNetworkReply::NetworkError error)
+{
+ qDebug() << "Received error response from cloud storage backend:" << reply->errorString();
+}
+
+void CloudStorageAuthenticate::sslErrors(QList<QSslError> errorList)
+{
+ qDebug() << "Received error response trying to set up https connection with cloud storage backend:";
+ Q_FOREACH (QSslError err, errorList) {
+ qDebug() << err.errorString();
+ }
+}