Cloud storage: implement confirmation of email address via PIN

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-06-09 11:21:46 -07:00
parent a04f1fd133
commit 57507cfb93
3 changed files with 23 additions and 9 deletions

View file

@ -935,15 +935,25 @@ CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : QObject(pa
} }
#define CLOUDBACKEND "https://cloud.subsurface-divelog.org/storage" #define CLOUDURL "https://cloud.subsurface-divelog.org/"
#define CLOUDBACKENDSTORAGE CLOUDURL "storage"
#define CLOUDBACKENDVERIFY CLOUDURL "verify"
QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password) QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password, QString pin)
{ {
QNetworkRequest *request = new QNetworkRequest(QUrl(CLOUDBACKEND)); 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("Accept", "text/xml, text/plain");
request->setRawHeader("User-Agent", userAgent.toUtf8()); request->setRawHeader("User-Agent", userAgent.toUtf8());
request->setHeader(QNetworkRequest::ContentTypeHeader, "text/plain"); request->setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
reply = WebServices::manager()->post(*request, qPrintable(QString(email + " " + password))); reply = WebServices::manager()->post(*request, qPrintable(payload));
connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished())); connect(reply, SIGNAL(finished()), this, SLOT(uploadFinished()));
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>))); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
@ -955,8 +965,13 @@ void CloudStorageAuthenticate::uploadFinished()
{ {
QString cloudAuthReply(reply->readAll()); QString cloudAuthReply(reply->readAll());
qDebug() << "Completed connection with cloud storage backend, response" << cloudAuthReply; qDebug() << "Completed connection with cloud storage backend, response" << cloudAuthReply;
prefs.show_cloud_pin = (cloudAuthReply == "[VERIFY]"); if (cloudAuthReply == "[VERIFIED]") {
prefs.show_cloud_pin = false;
emit finishedAuthenticate(prefs.show_cloud_pin); 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) void CloudStorageAuthenticate::uploadError(QNetworkReply::NetworkError error)

View file

@ -114,7 +114,7 @@ slots:
class CloudStorageAuthenticate : public QObject { class CloudStorageAuthenticate : public QObject {
Q_OBJECT Q_OBJECT
public: public:
QNetworkReply* authenticate(QString email, QString password); QNetworkReply* authenticate(QString email, QString password, QString pin = "");
explicit CloudStorageAuthenticate(QObject *parent); explicit CloudStorageAuthenticate(QObject *parent);
signals: signals:
void finishedAuthenticate(bool toggle); void finishedAuthenticate(bool toggle);

View file

@ -1024,8 +1024,7 @@ fraction_t string_to_fraction(const char *str)
int getCloudURL(QString &filename) int getCloudURL(QString &filename)
{ {
QString email = QString(prefs.cloud_storage_email); QString email = QString(prefs.cloud_storage_email);
email.replace("@", "_at_"); email.replace(QRegularExpression("[^a-zA-Z0-9@._+-]"), "");
email.replace(QRegularExpression("[^a-zA-Z0-9._+-]"), "");
if (email.isEmpty() || same_string(prefs.cloud_storage_password, "")) if (email.isEmpty() || same_string(prefs.cloud_storage_password, ""))
return report_error("Please configure Cloud storage email and password in the preferences"); return report_error("Please configure Cloud storage email and password in the preferences");
if (email != prefs.cloud_storage_email_encoded) { if (email != prefs.cloud_storage_email_encoded) {