Cloud storage: initial support for confirming the email PIN

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-06-07 09:54:28 -07:00
parent 318bf5cccc
commit a07376b534
6 changed files with 34 additions and 3 deletions

1
pref.h
View file

@ -94,6 +94,7 @@ struct preferences {
char *cloud_storage_email; char *cloud_storage_email;
char *cloud_storage_email_encoded; char *cloud_storage_email_encoded;
bool save_password_local; bool save_password_local;
bool show_cloud_pin;
}; };
enum unit_system_values { enum unit_system_values {
METRIC, METRIC,

View file

@ -59,7 +59,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, Qt::WindowFlags f) : QDial
connect(ui.btnDisconnectFacebook, &QPushButton::clicked, fb, &FacebookManager::logout); connect(ui.btnDisconnectFacebook, &QPushButton::clicked, fb, &FacebookManager::logout);
connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect); connect(fb, &FacebookManager::justLoggedOut, this, &PreferencesDialog::facebookDisconnect);
#endif #endif
connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int))); connect(ui.proxyType, SIGNAL(currentIndexChanged(int)), this, SLOT(proxyType_changed(int)));
connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *))); connect(ui.buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(buttonClicked(QAbstractButton *)));
connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int))); connect(ui.gflow, SIGNAL(valueChanged(int)), this, SLOT(gflowChanged(int)));
@ -104,6 +103,12 @@ void PreferencesDialog::facebookDisconnect()
#endif #endif
} }
void PreferencesDialog::cloudPinNeeded(bool toggle)
{
ui.cloud_storage_pin->setEnabled(toggle);
ui.cloud_storage_pin->setVisible(toggle);
}
#define DANGER_GF (gf > 100) ? "* { color: red; }" : "" #define DANGER_GF (gf > 100) ? "* { color: red; }" : ""
void PreferencesDialog::gflowChanged(int gf) void PreferencesDialog::gflowChanged(int gf)
{ {
@ -210,6 +215,7 @@ void PreferencesDialog::setUiFromPrefs()
ui.cloud_storage_email->setText(prefs.cloud_storage_email); ui.cloud_storage_email->setText(prefs.cloud_storage_email);
ui.cloud_storage_password->setText(prefs.cloud_storage_password); ui.cloud_storage_password->setText(prefs.cloud_storage_password);
ui.save_password_local->setChecked(prefs.save_password_local); ui.save_password_local->setChecked(prefs.save_password_local);
ui.cloud_storage_pin->setVisible(prefs.show_cloud_pin);
} }
void PreferencesDialog::restorePrefs() void PreferencesDialog::restorePrefs()
@ -364,6 +370,7 @@ void PreferencesDialog::syncSettings()
s.beginGroup("CloudStorage"); s.beginGroup("CloudStorage");
QString email = ui.cloud_storage_email->text(); QString email = ui.cloud_storage_email->text();
QString password = ui.cloud_storage_password->text(); QString password = ui.cloud_storage_password->text();
QString pin = ui.cloud_storage_pin->text();
if (email != prefs.cloud_storage_email || password != prefs.cloud_storage_password) { if (email != prefs.cloud_storage_email || password != prefs.cloud_storage_password) {
// connect to backend server to check / create credentials // connect to backend server to check / create credentials
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
@ -371,6 +378,7 @@ void PreferencesDialog::syncSettings()
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
} }
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);
connect(cloudAuth, SIGNAL(finishedAuthenticate(bool)), this, SLOT(cloudPinNeeded(bool)));
QNetworkReply *reply = cloudAuth->authenticate(email, password); QNetworkReply *reply = cloudAuth->authenticate(email, password);
} }
SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email);
@ -379,6 +387,7 @@ void PreferencesDialog::syncSettings()
SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password); SAVE_OR_REMOVE("password", default_prefs.cloud_storage_password, password);
else else
s.remove("password"); s.remove("password");
SAVE_OR_REMOVE("show_cloud_pin", default_prefs.show_cloud_pin, prefs.show_cloud_pin);
s.endGroup(); s.endGroup();
loadSettings(); loadSettings();
emit settingsChanged(); emit settingsChanged();
@ -495,6 +504,7 @@ void PreferencesDialog::loadSettings()
GET_TXT("password", cloud_storage_password); GET_TXT("password", cloud_storage_password);
GET_TXT("email", cloud_storage_email); GET_TXT("email", cloud_storage_email);
GET_BOOL("save_password_local", save_password_local); GET_BOOL("save_password_local", save_password_local);
GET_BOOL("show_cloud_pin", show_cloud_pin);
s.endGroup(); s.endGroup();
} }

View file

@ -36,6 +36,7 @@ slots:
void on_btnUseDefaultFile_toggled(bool toggle); void on_btnUseDefaultFile_toggled(bool toggle);
void facebookLoggedIn(); void facebookLoggedIn();
void facebookDisconnect(); void facebookDisconnect();
void cloudPinNeeded(bool toggle);
private: private:
explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); explicit PreferencesDialog(QWidget *parent = 0, Qt::WindowFlags f = 0);
void setUiFromPrefs(); void setUiFromPrefs();

View file

@ -451,6 +451,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2">
<widget class="QLabel" name="label_16d">
<property name="text">
<string>Verification PIN</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="cloud_storage_pin">
<property name="toolTip">
<string extracomment="One time verification PIN for Subsurface cloud storage infrastructure"/>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

View file

@ -953,7 +953,10 @@ QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString pas
void CloudStorageAuthenticate::uploadFinished() void CloudStorageAuthenticate::uploadFinished()
{ {
qDebug() << "Completed connection with cloud storage backend, response" << reply->readAll(); QString cloudAuthReply(reply->readAll());
qDebug() << "Completed connection with cloud storage backend, response" << cloudAuthReply;
prefs.show_cloud_pin = (cloudAuthReply == "[VERIFY]");
emit finishedAuthenticate(prefs.show_cloud_pin);
} }
void CloudStorageAuthenticate::uploadError(QNetworkReply::NetworkError error) void CloudStorageAuthenticate::uploadError(QNetworkReply::NetworkError error)

View file

@ -111,11 +111,13 @@ slots:
virtual void buttonClicked(QAbstractButton *button) { } virtual void buttonClicked(QAbstractButton *button) { }
}; };
class CloudStorageAuthenticate : QObject { class CloudStorageAuthenticate : public QObject {
Q_OBJECT Q_OBJECT
public: public:
QNetworkReply* authenticate(QString email, QString password); QNetworkReply* authenticate(QString email, QString password);
explicit CloudStorageAuthenticate(QObject *parent); explicit CloudStorageAuthenticate(QObject *parent);
signals:
void finishedAuthenticate(bool toggle);
private private
slots: slots:
void uploadError(QNetworkReply::NetworkError error); void uploadError(QNetworkReply::NetworkError error);