From 42735b2449481c8fc98b884a8c7cc70bc1e35e03 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Mon, 27 Sep 2010 14:27:44 +0300 Subject: [PATCH] Cleaning out old login code ongoing - Removed FacebookCredentials class - Removed saving of the user name - Renaming access token -> session, as the session is required, not only the access token --- src/engine/engine.cpp | 9 +- src/engine/engine.h | 6 - src/facebookservice/facebookauthentication.cpp | 155 +--------------------- src/facebookservice/facebookauthentication.h | 76 +---------- src/facebookservice/facebookcommon.h | 4 +- src/facebookservice/facebookcredentials.cpp | 98 -------------- src/facebookservice/facebookcredentials.h | 164 ------------------------ src/situareservice/situareservice.cpp | 15 +-- src/situareservice/situareservice.h | 14 +- src/src.pro | 2 - src/ui/mainwindow.cpp | 7 - src/ui/mainwindow.h | 7 - 12 files changed, 18 insertions(+), 539 deletions(-) delete mode 100644 src/facebookservice/facebookcredentials.cpp delete mode 100644 src/facebookservice/facebookcredentials.h diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index befe8d6..5525ca6 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -308,13 +308,6 @@ void SituareEngine::error(const int context, const int error) } } -void SituareEngine::fetchUsernameFromSettings() -{ - qDebug() << __PRETTY_FUNCTION__; - - m_ui->setUsername(m_facebookAuthenticator->loadUsername()); -} - void SituareEngine::imageReady(User *user) { qDebug() << __PRETTY_FUNCTION__; @@ -411,7 +404,7 @@ void SituareEngine::loginActionPressed() logout(); m_situareService->clearUserData(); } else { - m_facebookAuthenticator->start(); + login(); } } else { diff --git a/src/engine/engine.h b/src/engine/engine.h index 54ea087..145e3f2 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -83,12 +83,6 @@ public slots: void error(const int context, const int error); /** - * @brief Slot to intercept signal when username is fetched from settings - * - */ - void fetchUsernameFromSettings(); - - /** * @brief Slot to intercept signal when location search is issued * * @param location QString location diff --git a/src/facebookservice/facebookauthentication.cpp b/src/facebookservice/facebookauthentication.cpp index 3670712..df51d8d 100644 --- a/src/facebookservice/facebookauthentication.cpp +++ b/src/facebookservice/facebookauthentication.cpp @@ -42,8 +42,7 @@ const QString REDIRECT_URI = "http://www.facebook.com/connect/login_success.html"; FacebookAuthentication::FacebookAuthentication(QObject *parent) - : QObject(parent), - m_freshLogin(false) + : QObject(parent) { qDebug() << __PRETTY_FUNCTION__; @@ -53,11 +52,10 @@ void FacebookAuthentication::clearAccountInformation(bool keepUsername) { qDebug() << __PRETTY_FUNCTION__; - m_loginCredentials.clearCredentials(); + ///< @todo (HIGH) clear session from SituareService QSettings settings(DIRECTORY_NAME, FILE_NAME); if(!keepUsername) { - settings.remove(USERNAME); settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED); settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL); } @@ -74,37 +72,10 @@ void FacebookAuthentication::loadFinished(bool ok) ///< @todo show browsed window if url != redirect url } -const QString FacebookAuthentication::loadUsername() -{ - qDebug() << __PRETTY_FUNCTION__; - - QSettings settings(DIRECTORY_NAME, FILE_NAME); - return settings.value(USERNAME, EMPTY).toString(); -} - -FacebookCredentials FacebookAuthentication::loginCredentials() const -{ - qDebug() << __PRETTY_FUNCTION__; - return m_loginCredentials; -} - -QString FacebookAuthentication::parseAccessToken(const QUrl &url) +QString FacebookAuthentication::parseSession(const QUrl &url) { qWarning() << __PRETTY_FUNCTION__; -// const QString ACCESS_TOKEN_PARAMETER("#access_token="); -// const QString EXPIRATION_PARAMETER("&expires_in="); - -// QString urlString = url.toString(); - -// int begin = urlString.indexOf(ACCESS_TOKEN_PARAMETER) + ACCESS_TOKEN_PARAMETER.length(); -// int end = urlString.indexOf(EXPIRATION_PARAMETER); - -// if ((begin > -1) && (end > begin)) -// return urlString.mid(begin, end - begin); -// else -// return QString(); - const QString BEGIN("session={"); const QString END("}"); @@ -119,127 +90,15 @@ QString FacebookAuthentication::parseAccessToken(const QUrl &url) return QString(); } -void FacebookAuthentication::saveUsername(const QString &username) -{ - qDebug() << __PRETTY_FUNCTION__; - - QSettings settings(DIRECTORY_NAME, FILE_NAME); - settings.setValue(USERNAME, username); -} - -void FacebookAuthentication::start() -{ - qDebug() << __PRETTY_FUNCTION__; - - QSettings settings(DIRECTORY_NAME, FILE_NAME); - - QStringList cookies = settings.value(COOKIES).toStringList(); - if(!cookies.isEmpty()) { - emit loginUsingCookies(); - } - else { - m_freshLogin = true; - emit newLoginRequest(); - } -} - -bool FacebookAuthentication::updateCredentials(const QUrl &url) -{ - qDebug() << __PRETTY_FUNCTION__ << url.toString(); - - bool found = false; - - if (url.isValid()) { - qDebug() << "url is valid"; - - QString callbackUrl = url.toString(); - qDebug() << "callbackUrl: " << callbackUrl.toAscii(); - - if (callbackUrl.indexOf(LOGIN_SUCCESS_REPLY) == 0) { - qDebug() << "login success"; - - // let's find out session credentials - if(callbackUrl.contains(SESSION_KEY)) { - - QJson::Parser parser; - bool ok; - - // split string into string part and json part - QStringList list = url.toString().split("="); - - for(int i=0;i -#include "facebookcredentials.h" /** * @brief FacebookAuthentication class takes care of parsing and handling of credentials for @@ -51,14 +50,6 @@ public: /******************************************************************************* * MEMBER FUNCTIONS AND SLOTS ******************************************************************************/ -public: - /** - * @brief Getter for m_loginCredentials - * - * @return FacebookCredentials - */ - FacebookCredentials loginCredentials() const; - public slots: /** @@ -68,50 +59,18 @@ public slots: */ void clearAccountInformation(bool keepUsername = false); - /** - * @brief Loads username from settings - * - * @return QString Loaded username - */ - const QString loadUsername(); - - /** - * @brief Saves username to settings - * - * @param username Username to be saved - */ - void saveUsername(const QString &username); - - /** - * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage - * variable. Specifies font size for the page. - * - */ - void start(); - private: - QString parseAccessToken(const QUrl &url); + QString parseSession(const QUrl &url); private slots: void loadFinished(bool ok); - /** - * @brief Search credentials from URL that is given as parameter. - * If credentials are found thay are stored to loginCredentials variable. - * - * @param url URL where this method tries to find credentials. - * @return bool if credentials are found returns true, - * if credentials are not found returns false. - */ - bool updateCredentials(const QUrl & url); - void urlChanged(const QUrl &url); /******************************************************************************* * SIGNALS ******************************************************************************/ - signals: /** @@ -122,23 +81,7 @@ signals: */ void error(const int context, const int error); - /** - * @brief This signal is emitted if updateCredentials method finds credentials from URL. - * Signal is also emitted at the beginning of the program if there is valid credentials - * in the file. - * - * @param credentials New credentials - */ - void credentialsReady(const FacebookCredentials &credentials); - - void loggedIn(const QString accessToken); - - /** - * @brief This signal is emitted always when login is called. At first the application tries - * to login using saved cookies - * - */ - void loginUsingCookies(); + void loggedIn(const QString session); /** * @brief Signals when credentials are invalid new login is needed @@ -146,27 +89,12 @@ signals: */ void newLoginRequest(); - /** - * @brief This signal is emitted when new cookies need to be saved. - * - */ - void saveCookiesRequest(); - /******************************************************************************* * DATA MEMBERS ******************************************************************************/ - private: - bool m_freshLogin; ///< Flag for fresh login - /** - * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five - * QStrings and setters and getters. - * - * @var m_loginCredentials - */ - FacebookCredentials m_loginCredentials; }; #endif // FACEBOOKAUTHENTICATION_H diff --git a/src/facebookservice/facebookcommon.h b/src/facebookservice/facebookcommon.h index c2af8a2..4f5e927 100644 --- a/src/facebookservice/facebookcommon.h +++ b/src/facebookservice/facebookcommon.h @@ -27,15 +27,13 @@ const QString ERROR = "Error"; // Facebook callback url indentifiers and setting items +///< @todo remove const QString SESSION_KEY = "session_key"; const QString USER_ID = "uid"; const QString EXPIRES = "expires"; const QString SESSION_SECRET = "secret"; const QString SIGNATURE = "sig"; -// Login setting items -const QString USERNAME = "username"; - const QString LOGIN_SUCCESS_REPLY = "http://www.facebook.com/connect/login_success.html"; const QString LOGIN_FAILURE_REPLY = "https://login.facebook.com/login.php?login_attempt="; const QString LOGIN_PAGE = "http://www.facebook.com/login.php?api_key="; diff --git a/src/facebookservice/facebookcredentials.cpp b/src/facebookservice/facebookcredentials.cpp deleted file mode 100644 index 9e4d225..0000000 --- a/src/facebookservice/facebookcredentials.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Ville Tiensuu - ville.tiensuu@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 "facebookcredentials.h" - -FacebookCredentials::FacebookCredentials() -{ -} - -void FacebookCredentials::clearCredentials() -{ - m_expires.clear(); - m_sessionKey.clear(); - m_sessionSecret.clear(); - m_sig.clear(); - m_userID.clear(); -} - -void FacebookCredentials::setSessionKey(const QString & sessionKeyParameter) -{ - m_sessionKey = sessionKeyParameter; -} - -void FacebookCredentials::setSessionSecret(const QString & sessionSecretParameter) -{ - m_sessionSecret = sessionSecretParameter; -} - - -void FacebookCredentials::setExpires (const QString & expiresParameter) -{ - m_expires = expiresParameter; -} - -void FacebookCredentials::setUserID (const QString & userIDParameter) -{ - m_userID = userIDParameter; -} - -void FacebookCredentials::setSig(const QString & sigParameter) -{ - m_sig = sigParameter; -} - -QString FacebookCredentials::sessionKey() const -{ - return m_sessionKey; -} - -QString FacebookCredentials::sessionSecret() const -{ - return m_sessionSecret; -} - -QString FacebookCredentials::expires() const -{ - return m_expires; -} - -QString FacebookCredentials::userID() const -{ - return m_userID; -} - -QString FacebookCredentials::sig() const -{ - return m_sig; -} - -bool FacebookCredentials::operator==(const FacebookCredentials &credentials) -{ - bool expireBool = (m_expires == credentials.expires()); - bool sessionKeyBool = (m_sessionKey == credentials.sessionKey()); - bool sessionSecretBool = (m_sessionSecret == credentials.sessionSecret()); - bool sigBool = (m_sig == credentials.sig()); - bool userIdBool = (m_userID == credentials.userID()); - - return expireBool && sessionKeyBool && sessionSecretBool && sigBool && userIdBool; -} diff --git a/src/facebookservice/facebookcredentials.h b/src/facebookservice/facebookcredentials.h deleted file mode 100644 index b93378d..0000000 --- a/src/facebookservice/facebookcredentials.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - Situare - A location system for Facebook - Copyright (C) 2010 Ixonos Plc. Authors: - - Ville Tiensuu - ville.tiensuu@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 FACEBOOKCREDENTIALS_H -#define FACEBOOKCREDENTIALS_H - -#include - -/** -* @brief Class is used to integrate facebook credentials together. -* -* @author Ville Tiensuu -* @class FacebookCredentials facebookcredentials.h "situare/src/facebookservice/facebookcredentials.h" -*/ -class FacebookCredentials -{ -public: - /** - * @brief Default constructor - * - */ - FacebookCredentials(); - - /** - * @brief Clears credentials - * - */ - void clearCredentials(); - - /** - * @brief Set funtion for m_expires member - * - * @param expiresParameter value of parameter is set to m_expires member - */ - void setExpires (const QString & expiresParameter); - - /** - * @brief Set function for m_sessionKey member - * - * @param sessionKeyParameter value of parameter is set to m_sessionKey member - */ - void setSessionKey(const QString & sessionKeyParameter); - - /** - * @brief Set function for m_sessionSecret member - * - * @param sessionSecretParameter value of parameter is set to m_sessionSecret member - */ - void setSessionSecret(const QString & sessionSecretParameter); - - /** - * @brief Set funtion for m_sig member - * - * @param sigParameter value of parameter is set to m_sig member - */ - void setSig(const QString & sigParameter); - - /** - * @brief Set function for m_userID member - * - * @param userIDParameter value of parameter is set to m_userID member - */ - void setUserID(const QString & userIDParameter); - - /** - * @brief Get function for m_expires member - * - * @return QString m_expires - */ - QString expires() const; - - /** - * @brief Get function for m_sessionKey member - * - * @return QString m_sessionKey - */ - QString sessionKey() const; - - /** - * @brief Get funtion for m_sessionSecret member - * - * @return QString m_sessionSecret - */ - QString sessionSecret() const; - - /** - * @brief Get function for m_sig member - * - * @return QString m_sig - */ - QString sig() const; - - /** - * @brief Get function for m_userID member - * - * @return QString m_userID - */ - QString userID() const; - - /** - * @brief Overloaded operator == is used to compare two FacebookCredentials. - * - * @param credentials to be checked - * @return bool returns true if all members are same, else returns false - */ - bool operator==(const FacebookCredentials& credentials); - -private: - - /** - * @brief String for storing expires - * - * @var m_expires - */ - QString m_expires; - - /** - * @brief String for storing sessionKey - * - * @var m_sessionKey - */ - QString m_sessionKey; - - /** - * @brief String for storing sessionSecret - * - * @var m_sessionSecret - */ - QString m_sessionSecret; - - /** - * @brief String for storing sig - * - * @var m_sig - */ - QString m_sig; - - /** - * @brief String for storing userID - * - * @var m_userID - */ - QString m_userID; -}; - -#endif // FACEBOOKCREDENTIALS_H diff --git a/src/situareservice/situareservice.cpp b/src/situareservice/situareservice.cpp index b14b8f7..a125334 100644 --- a/src/situareservice/situareservice.cpp +++ b/src/situareservice/situareservice.cpp @@ -81,7 +81,7 @@ void SituareService::appendAccessToken(QString &requestUrl) qWarning() << __PRETTY_FUNCTION__; // requestUrl.append("access_token="); - requestUrl.append(m_accessToken); + requestUrl.append(m_session); // qWarning() << __PRETTY_FUNCTION__ << "request url with parameters and access token:" << requestUrl; } @@ -108,7 +108,7 @@ void SituareService::buildRequest(const QString &script, const QHash -#include "../facebookservice/facebookcredentials.h" + #include "../user/user.h" #include "imagefetcher.h" @@ -94,20 +94,13 @@ public slots: void clearUserData(); /** - * @brief Public slot, which indicates when facebook credentials are ready - * - * @param credentials New credentials - */ - void credentialsReady(const FacebookCredentials &credentials); - - /** * @brief Public slot, which indicates when http request has been completed * * @param reply storage for http reply */ void requestFinished(QNetworkReply *reply); - void updateAccessToken(const QString &accessToken); + void updateSession(const QString &session); private: @@ -253,11 +246,10 @@ private: QList m_requestsWaitingAccessToken; QList m_friendsList; ///< List of friends(User) - QString m_accessToken; + QString m_session; NetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager - FacebookCredentials m_credentials; ///< handle for FacebookCredentials ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher User *m_user; ///< Pointer to User }; diff --git a/src/src.pro b/src/src.pro index 1571280..a3f992e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -16,7 +16,6 @@ SOURCES += main.cpp \ engine/engine.cpp \ engine/mce.cpp \ facebookservice/facebookauthentication.cpp \ - facebookservice/facebookcredentials.cpp \ gps/gpsposition.cpp \ map/baselocationitem.cpp \ map/friendgroupitem.cpp \ @@ -98,7 +97,6 @@ HEADERS += application.h \ error.h \ facebookservice/facebookauthentication.h \ facebookservice/facebookcommon.h \ - facebookservice/facebookcredentials.h \ gps/gpscommon.h \ gps/gpsposition.h \ map/baselocationitem.h \ diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index bdd2bad..0ed3202 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -977,13 +977,6 @@ void MainWindow::settingsDialogAccepted() readAutomaticLocationUpdateSettings(); } -void MainWindow::setUsername(const QString &username) -{ - qDebug() << __PRETTY_FUNCTION__; - - m_email = username; -} - void MainWindow::showContactDialog(const QString &guid) { qDebug() << __PRETTY_FUNCTION__; diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 840ad23..70070e5 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -191,13 +191,6 @@ public slots: void setCrosshairVisibility(bool visible); /** - * @brief Sets username to member variable for login dialog - * - * @param username Username to be set - */ - void setUsername(const QString &username); - - /** * @brief Shows contact dialog. * * Shows contact dialog with contact's information. -- 1.7.9.5