From b72d0f2174bd17a5016936a1cbf90dcd912c1d8a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Wed, 10 Nov 2010 10:51:36 +0200 Subject: [PATCH] Changes to logout prosess and login state storing, logout bug fix - logout process is initiated calling FacebookAuthentication::logOut() - logged in state is now stored by FacebookAuthentication and checked by using isLoggedIn() method - fixed bug: user was not able to log out when network connection was not awailable - handler for login browser's SSL errors - clean-up, removed LoginDialog --- src/engine/engine.cpp | 57 +++++---------- src/engine/engine.h | 9 +-- src/error.h | 1 - src/facebookservice/facebookauthentication.cpp | 31 ++++++++- src/facebookservice/facebookauthentication.h | 42 ++++++++--- src/situareservice/situareservice.cpp | 11 ++- src/src.pro | 2 - src/ui/logindialog.cpp | 89 ------------------------ src/ui/logindialog.h | 88 ----------------------- src/ui/mainwindow.cpp | 53 +------------- src/ui/mainwindow.h | 45 +----------- 11 files changed, 97 insertions(+), 331 deletions(-) delete mode 100644 src/ui/logindialog.cpp delete mode 100644 src/ui/logindialog.h diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ac16568..de715c9 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -61,7 +61,7 @@ SituareEngine::SituareEngine() qDebug() << __PRETTY_FUNCTION__; m_ui = new MainWindow; - m_ui->updateItemVisibility(); + m_ui->updateItemVisibility(false); Application *application = static_cast(qApp); application->registerWindow(m_ui->winId()); @@ -250,15 +250,8 @@ void SituareEngine::error(const int context, const int error) break; case SituareError::SESSION_EXPIRED: m_ui->buildInformationBox(tr("Session expired. Please login again"), true); - m_facebookAuthenticator->clearAccountInformation(true); // keep username = true - m_situareService->clearUserData(); - m_ui->loggedIn(false); - m_ui->loginFailed(); - break; - case SituareError::LOGIN_FAILED: - m_ui->toggleProgressIndicator(false); - m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true); - m_ui->loginFailed(); + m_facebookAuthenticator->logOut(); + m_facebookAuthenticator->login(); break; case SituareError::UPDATE_FAILED: m_ui->toggleProgressIndicator(false); @@ -358,42 +351,27 @@ void SituareEngine::loginActionPressed() { qDebug() << __PRETTY_FUNCTION__; - if (m_networkAccessManager->isConnected()) { - if(m_ui->loginState()) { - logout(); - m_situareService->clearUserData(); - } else { - m_facebookAuthenticator->login(); - } - } - else { + if (m_facebookAuthenticator->isLoggedIn()) + m_facebookAuthenticator->logOut(); + else if (m_networkAccessManager->isConnected()) + m_facebookAuthenticator->login(); + else error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError); - } } -void SituareEngine::loginOk() +void SituareEngine::onLogin() { - /// @ OLD CODE, REFACTOR! loggedIn -> FB authenticator etc. qDebug() << __PRETTY_FUNCTION__; m_ui->loggedIn(true); - m_ui->show(); - m_situareService->fetchLocations(); // request user locations + m_situareService->fetchLocations(); if (m_gps->isRunning()) m_ui->readAutomaticLocationUpdateSettings(); } -void SituareEngine::loginProcessCancelled() -{ - qDebug() << __PRETTY_FUNCTION__; - - m_ui->toggleProgressIndicator(false); - m_ui->updateItemVisibility(); -} - -void SituareEngine::logout() +void SituareEngine::onLogout() { qDebug() << __PRETTY_FUNCTION__; @@ -404,7 +382,8 @@ void SituareEngine::logout() m_ui, SIGNAL(clearUpdateLocationDialogData())); emit clearUpdateLocationDialogData(); - m_facebookAuthenticator->clearAccountInformation(); // clear all + m_situareService->updateSession(""); // empty session string means logged out + m_automaticUpdateFirstStart = true; } @@ -538,7 +517,7 @@ void SituareEngine::setGPS(bool enabled) m_gps->start(); m_gps->requestLastPosition(); - if(m_ui->loginState()) + if(m_facebookAuthenticator->isLoggedIn()) m_ui->readAutomaticLocationUpdateSettings(); } else if (!enabled && m_gps->isRunning()) { @@ -589,7 +568,9 @@ void SituareEngine::signalsFromFacebookAuthenticator() m_situareService, SLOT(updateSession(QString))); connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)), - this, SLOT(loginOk())); + this, SLOT(onLogin())); + + connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout())); } void SituareEngine::signalsFromGeocodingService() @@ -648,10 +629,6 @@ void SituareEngine::signalsFromMainWindow() connect(m_ui, SIGNAL(gpsTriggered(bool)), this, SLOT(setGPS(bool))); - //signals from dialogs - connect(m_ui, SIGNAL(cancelLoginProcess()), - this, SLOT(loginProcessCancelled())); - connect(m_ui, SIGNAL(requestReverseGeo()), this, SLOT(requestAddress())); diff --git a/src/engine/engine.h b/src/engine/engine.h index e76274c..4e1930a 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -99,18 +99,13 @@ public slots: * @brief Slot to intercept signal from successful login * */ - void loginOk(); - - /** - * @brief Slot to intercept signal when user has cancelled login process - */ - void loginProcessCancelled(); + void onLogin(); /** * @brief Changes application state when logged out * */ - void logout(); + void onLogout(); /** * @brief Calls reverseGeo from SituareService to translate coordinates to street address diff --git a/src/error.h b/src/error.h index 14af6f0..054135f 100644 --- a/src/error.h +++ b/src/error.h @@ -29,7 +29,6 @@ namespace SituareError { ERROR_GENERAL = 0, // an unknown/unspecified error ERROR_MISSING_ARGUMENT, // missing mandatory argument for requested action SESSION_EXPIRED = 10, // situare session credentials expired - LOGIN_FAILED, // login to situare service failed UPDATE_FAILED, // location update to situare failed DATA_RETRIEVAL_FAILED, // user/friends list retrieval failed ADDRESS_RETRIEVAL_FAILED, // reversegeo request failed diff --git a/src/facebookservice/facebookauthentication.cpp b/src/facebookservice/facebookauthentication.cpp index fbb64e1..aaeff49 100644 --- a/src/facebookservice/facebookauthentication.cpp +++ b/src/facebookservice/facebookauthentication.cpp @@ -48,6 +48,7 @@ const QString FB_LOGIN_URL = "https://www.facebook.com/login.php"; FacebookAuthentication::FacebookAuthentication(MainWindow *mainWindow, QObject *parent) : QObject(parent), + m_loggedIn(false), m_browser(0), m_mainWindow(mainWindow) { @@ -66,7 +67,6 @@ void FacebookAuthentication::clearAccountInformation(bool keepUsername) { qDebug() << __PRETTY_FUNCTION__; - ///< @todo (HIGH) clear session from SituareService QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME); if(!keepUsername) { @@ -88,6 +88,13 @@ void FacebookAuthentication::destroyLogin() m_browser->deleteLater(); } +bool FacebookAuthentication::isLoggedIn() +{ + qWarning() << __PRETTY_FUNCTION__; + + return m_loggedIn; +} + void FacebookAuthentication::login() { qWarning() << __PRETTY_FUNCTION__; @@ -104,6 +111,10 @@ void FacebookAuthentication::login() connect(m_browser, SIGNAL(destroyed(QObject*)), this, SLOT(browserDestroyed())); + connect(m_browser->page()->networkAccessManager(), + SIGNAL(sslErrors(QNetworkReply*, QList)), + this, SLOT(sslErrors(QNetworkReply*, QList))); + connect(m_browser->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)), this, SLOT(networkReplyHandler(QNetworkReply*))); } @@ -126,6 +137,15 @@ void FacebookAuthentication::login() } } +void FacebookAuthentication::logOut() +{ + qWarning() << __PRETTY_FUNCTION__; + + clearAccountInformation(); + m_loggedIn = false; + emit loggedOut(); +} + void FacebookAuthentication::networkReplyHandler(QNetworkReply *reply) { qWarning() <<__PRETTY_FUNCTION__; @@ -157,6 +177,14 @@ QString FacebookAuthentication::parseSession(const QUrl &url) return QString(); } +void FacebookAuthentication::sslErrors(QNetworkReply *reply, const QList &errors) +{ + qWarning() << __PRETTY_FUNCTION__; + + Q_UNUSED(errors); + reply->ignoreSslErrors(); +} + void FacebookAuthentication::urlChanged(const QUrl &url) { qWarning() << __PRETTY_FUNCTION__ << url.toString(); @@ -181,6 +209,7 @@ void FacebookAuthentication::urlChanged(const QUrl &url) qWarning() << __PRETTY_FUNCTION__ << "login finished, parsed session:" << session; if (!session.isEmpty()) { destroyLogin(); + m_loggedIn = true; emit loggedIn(session); } } diff --git a/src/facebookservice/facebookauthentication.h b/src/facebookservice/facebookauthentication.h index b1c1d11..28725bd 100644 --- a/src/facebookservice/facebookauthentication.h +++ b/src/facebookservice/facebookauthentication.h @@ -27,6 +27,7 @@ #include class QNetworkReply; +class QSslError; class QWebView; class MainWindow; @@ -58,7 +59,21 @@ public: /******************************************************************************* * MEMBER FUNCTIONS AND SLOTS ******************************************************************************/ -public: +public slots: + /** + * @brief Clears account information from settings + * + * @param keepUsername keep = true, false otherwise + */ + void clearAccountInformation(bool keepUsername = false); + + /** + * @brief Is the user currently logged in + * + * @returns True if the user is logged in, otherwise false + */ + bool isLoggedIn(); + /** * @brief Initiate login process * @@ -66,14 +81,10 @@ public: */ void login(); -public slots: - /** - * @brief Clears account information from settings - * - * @param keepUsername keep = true, false otherwise - */ - void clearAccountInformation(bool keepUsername = false); + * @brief Log out + */ + void logOut(); private: /** @@ -105,6 +116,11 @@ private slots: void networkReplyHandler(QNetworkReply *reply); /** + * @brief Handler for SSL errors, ignores the error + */ + void sslErrors(QNetworkReply *reply, const QList &errors); + + /** * @brief Handler for browser URL changes * * Does check the new URL and based on that invokes the login dialog with visible browser view @@ -129,14 +145,24 @@ signals: /** * @brief Emitted when logged in successfully * + * All login related actions should be connected to this signal. + * * @param session Session data */ void loggedIn(const QString session); + /** + * @brief Emitted when logged out + * + * All logout related actions should be connected to this signal. + */ + void loggedOut(); + /******************************************************************************* * DATA MEMBERS ******************************************************************************/ private: + bool m_loggedIn; ///< Is the user currently logged in QWebView *m_browser; ///< Login browser MainWindow *m_mainWindow; ///< MainWindow }; diff --git a/src/situareservice/situareservice.cpp b/src/situareservice/situareservice.cpp index fd0aea6..5bbb36e 100644 --- a/src/situareservice/situareservice.cpp +++ b/src/situareservice/situareservice.cpp @@ -545,9 +545,14 @@ void SituareService::updateSession(const QString &session) m_session = session; - foreach (QString request, m_requestsWaitingAccessToken) { - appendAccessToken(request); - sendRequest(request); + if (!m_session.isEmpty()) { + foreach (QString request, m_requestsWaitingAccessToken) { + appendAccessToken(request); + sendRequest(request); + } + } + else { + clearUserData(); } m_requestsWaitingAccessToken.clear(); diff --git a/src/src.pro b/src/src.pro index 4402841..4337dda 100644 --- a/src/src.pro +++ b/src/src.pro @@ -61,7 +61,6 @@ SOURCES += main.cpp \ ui/locationlistview.cpp \ ui/indicatorbuttonpanel.cpp \ ui/locationsearchpanel.cpp \ - ui/logindialog.cpp \ ui/mainwindow.cpp \ ui/mapscale.cpp \ ui/panelbar.cpp \ @@ -143,7 +142,6 @@ HEADERS += application.h \ ui/listview.h \ ui/listitem.h \ ui/listitemdelegate.h \ - ui/logindialog.h \ ui/locationlistitem.h \ ui/locationlistview.h \ ui/locationsearchpanel.h \ diff --git a/src/ui/logindialog.cpp b/src/ui/logindialog.cpp deleted file mode 100644 index 23b3e00..0000000 --- a/src/ui/logindialog.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Henri Lampela - henri.lampela@ixonos.com - - Situare is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as published by the Free Software Foundation. - - Situare is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Situare; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#include -#include -#include -#include -#include -#include - -#include "logindialog.h" - -LoginDialog::LoginDialog(QWidget *parent) - : QDialog(parent) -{ - qDebug() << __PRETTY_FUNCTION__; - - setWindowTitle(tr("Login to Situare with Facebook account")); - - m_emailEdit = new QLineEdit(); - m_passwordEdit = new QLineEdit(); - m_passwordEdit->setEchoMode(QLineEdit::Password); - - QGridLayout *gridLayout = new QGridLayout(this); - QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical); - QPushButton *connectButton = buttonBox->addButton(QDialogButtonBox::Ok); - QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel); - connectButton->setText(tr("Login")); - - QFormLayout *form = new QFormLayout(); - form->addRow(new QLabel(tr("E-mail:")), m_emailEdit); - form->addRow(new QLabel(tr("Password:")), m_passwordEdit); - - gridLayout->addLayout(form, 0, 0, 2, 1); - gridLayout->addWidget(buttonBox, 0, 1, 1, 1); - - connect(connectButton, SIGNAL(clicked()), - this, SLOT(accept())); - connect(cancelButton, SIGNAL(clicked()), - this, SLOT(reject())); - - setLayout(gridLayout); -} - -void LoginDialog::setEmailField(const QString &email) -{ - qDebug() << __PRETTY_FUNCTION__; - if(!email.isEmpty()) { - m_emailEdit->setText(email); - m_passwordEdit->setFocus(Qt::OtherFocusReason); - } -} - -void LoginDialog::clearTextFields() -{ - qDebug() << __PRETTY_FUNCTION__; - - m_passwordEdit->clearFocus(); - m_emailEdit->setText(""); // clear() method bugging in Qt 4.6, it leaves "dead" cursor - m_emailEdit->setFocus(Qt::OtherFocusReason); - m_passwordEdit->setText(""); - -} - -void LoginDialog::userInput(QString &email, QString &password) -{ - qDebug() << __PRETTY_FUNCTION__; - - email = m_emailEdit->text(); - password = m_passwordEdit->text(); -} diff --git a/src/ui/logindialog.h b/src/ui/logindialog.h deleted file mode 100644 index 15e6c12..0000000 --- a/src/ui/logindialog.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Henri Lampela - henri.lampela@ixonos.com - - Situare is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as published by the Free Software Foundation. - - Situare is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Situare; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - USA. -*/ - -#ifndef LOGINDIALOG_H -#define LOGINDIALOG_H - -#include - -class QDialogButtonBox; -class QLabel; -class QLineEdit; -class QPushButton; - -/** -* @brief Custom login dialog. Email and password inserted into dialog will be forwarded to webview -* Email and password will not be saved. -* -* @author Henri Lampela -*/ -class LoginDialog : public QDialog -{ - Q_OBJECT - -public: - - /** - * @brief Default constructor - * - * @param parent Instance of parent widget - */ - LoginDialog(QWidget *parent = 0); - - /** - * @brief Gets email and password - * - * @param email Email address - * @param password Password - */ - void userInput(QString &email, QString &password); - -/******************************************************************************* - * MEMBER FUNCTIONS AND SLOTS - ******************************************************************************/ - -public slots: - - /** - * @brief Sets email address to emailEdit field - * - * @param email E-mail address to be set - */ - void setEmailField(const QString &email); - - /** - * @brief Clears line edits - * - */ - void clearTextFields(); - -/******************************************************************************* - * DATA MEMBERS - ******************************************************************************/ - -private: - - QLineEdit *m_emailEdit; ///< Pointer to email line edit - QLineEdit *m_passwordEdit; ///< Pointer to password line edit -}; - -#endif // LOGINDIALOG_H diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 0d60bb0..7bdb807 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -38,7 +38,6 @@ #include "fullscreenbutton.h" #include "indicatorbuttonpanel.h" #include "locationsearchpanel.h" -#include "logindialog.h" #include "map/mapcommon.h" #include "map/mapview.h" #include "mapscale.h" @@ -74,8 +73,6 @@ MainWindow::MainWindow(QWidget *parent) m_progressIndicatorCount(0), m_loginDialog(0), m_crosshair(0), - m_email(), ///< @todo WTF?!?!?!? - m_password(), m_fullScreenButton(0), m_indicatorButtonPanel(0), m_mapScale(0) @@ -662,7 +659,6 @@ void MainWindow::keyPressEvent(QKeyEvent* event) void MainWindow::loggedIn(bool logged) { - /// @todo OLD CODE qDebug() << __PRETTY_FUNCTION__; m_loggedIn = logged; @@ -670,30 +666,10 @@ void MainWindow::loggedIn(bool logged) if(logged) { m_loginAct->setText(tr("Logout")); } else { -// clearCookieJar(); - m_email.clear(); - m_password.clear(); - m_loginAct->setText(tr("Login")); m_userInfoPanel->showUserInfo(false); } - updateItemVisibility(); -} - -void MainWindow::loginFailed() -{ - /// @todo OLD CODE - qDebug() << __PRETTY_FUNCTION__; - -// clearCookieJar(); - startLoginProcess(); -} - -bool MainWindow::loginState() -{ - qDebug() << __PRETTY_FUNCTION__; - - return m_loggedIn; + updateItemVisibility(logged); } void MainWindow::mapCenterHorizontalShiftingChanged(int shifting) @@ -867,22 +843,6 @@ void MainWindow::startLocationSearch() queueDialog(searchDialog); } -void MainWindow::startLoginProcess() -{ - qDebug() << __PRETTY_FUNCTION__; - - LoginDialog *loginDialog = new LoginDialog(); - - emit fetchUsernameFromSettings(); - - loginDialog->clearTextFields(); - - if(!m_email.isEmpty()) - loginDialog->setEmailField(m_email); - - queueDialog(loginDialog); -} - void MainWindow::toggleFullScreen() { qDebug() << __PRETTY_FUNCTION__; @@ -913,16 +873,9 @@ void MainWindow::toggleProgressIndicator(bool value) #endif // Q_WS_MAEMO_5 } -void MainWindow::updateItemVisibility() -{ - qDebug() << __PRETTY_FUNCTION__; - - m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn); -} - -const QString MainWindow::username() +void MainWindow::updateItemVisibility(bool loggedIn) { qDebug() << __PRETTY_FUNCTION__; - return m_email; + m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn); } diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index f9a1a13..f7e508b 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -108,13 +108,6 @@ public: void loggedIn(bool logged); /** - * @brief Gets the login state (logged in/logged out) - * - * @return bool Login state - */ - bool loginState(); - - /** * @brief Reads automatic location update settings. */ void readAutomaticLocationUpdateSettings(); @@ -149,13 +142,6 @@ public: */ void showEnableAutomaticUpdateLocationDialog(const QString &text); - /** - * @brief Gets the username from member variable for saving purposes - * - * @return QString Username - */ - const QString username(); - public slots: /** * @brief Builds information box with message. @@ -171,11 +157,6 @@ public slots: void destroyLoginDialog(); /** - * @brief Slot for failed login - */ - void loginFailed(); - - /** * @brief Public slot, which open settings dialog */ void openSettingsDialog(); @@ -196,12 +177,6 @@ public slots: void showContactDialog(const QString &guid); /** - * @brief Public slot to intercept signal when old cerdentials are invalid or credentials - * doesn't exist yet - */ - void startLoginProcess(); - - /** * @brief Toggle progress indicator. * * @param state true if progress indicator should be shown, false otherwise @@ -209,10 +184,11 @@ public slots: void toggleProgressIndicator(bool state); /** - * @brief Shows / hides Situare related UI items + * @brief Shows / hides Situare related UI items based on login state * + * @param loggedIn Is the user currently logged in */ - void updateItemVisibility(); + void updateItemVisibility(bool loggedIn); private: /** @@ -402,12 +378,6 @@ signals: void autoCenteringTriggered(bool enabled); /** - * @brief Signal that indicates when user has cancelled login process - * - */ - void cancelLoginProcess(); - - /** * @brief Signal for centering to coordinates. * * @param coordinates geo coordinates to center to. @@ -453,12 +423,6 @@ signals: void error(const int context, const int error); /** - * @brief Signal for requesting username from settings - * - */ - void fetchUsernameFromSettings(); - - /** * @brief Signals when friend's profile image is ready * * @param user Friend @@ -669,9 +633,6 @@ private: QMessageBox *m_automaticUpdateLocationDialog; ///< Automatic update location dialog - QString m_email; ///< Placeholder for email - QString m_password; ///< Placeholder for password - FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel FullScreenButton *m_fullScreenButton; ///< Instance of the fullscreen toggle button IndicatorButtonPanel *m_indicatorButtonPanel; ///< Instance of direction indicator button -- 1.7.9.5