Refactored fabookauthentication class and moved cookiehandler to situaraeservice fb_auth_cleanup
authorlampehe-local <henri.lampela@ixonos.com>
Tue, 11 May 2010 12:22:23 +0000 (15:22 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Tue, 11 May 2010 12:22:23 +0000 (15:22 +0300)
removed cookiehandler related unit test
Reviewed by: Ville Tiensuu

src/cookiehandler/cookiehandler.cpp [deleted file]
src/cookiehandler/cookiehandler.h [deleted file]
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/facebookservice/facebookcommon.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/src.pro
tests/cookiehandler/testcookiehandler.cpp [deleted file]
tests/cookiehandler/testcookiehandler.pro [deleted file]

diff --git a/src/cookiehandler/cookiehandler.cpp b/src/cookiehandler/cookiehandler.cpp
deleted file mode 100644 (file)
index df6df19..0000000
+++ /dev/null
@@ -1,90 +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 <QDebug>
-#include <QStringList>
-#include "cookiehandler.h"
-
-CookieHandler::CookieHandler()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-}
-
-CookieHandler::~CookieHandler()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-}
-
-QString CookieHandler::formCookie(const QString &apiKeyValue, QString expiresValue,
-                                  QString userValue, QString sessionKeyValue,
-                                  QString sessionSecretValue, const QString &signatureValue,
-                                  const QString &localeValue)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QString cookie;
-    QString apiKey;
-    QString user;
-    QString expires;
-    QString sessionKey;
-    QString sessionSecret;
-    QString locale;
-    QString variable;
-    QString signature = EQUAL_MARK;
-    QStringList variableList;
-
-    signature.append(signatureValue);
-    apiKey.append(apiKeyValue);
-    apiKey.append(UNDERLINE_MARK);
-
-    user.append(USER);
-    user.append(EQUAL_MARK);
-    expires.append(EXPIRES);
-    expires.append(EQUAL_MARK);
-    sessionKey.append(SESSION_KEY);
-    sessionKey.append(EQUAL_MARK);
-    sessionSecret.append(SESSION_SECRET);
-    sessionSecret.append(EQUAL_MARK);
-    locale.append(LOCALE);
-    locale.append(EQUAL_MARK);
-    locale.append(localeValue);
-
-    variableList.append(expires.append(expiresValue.append(BREAK_MARK)));
-    variableList.append(sessionKey.append(sessionKeyValue.append(BREAK_MARK)));
-    variableList.append(user.append(userValue).append(BREAK_MARK));
-    variableList.append(sessionSecret.append(sessionSecretValue.append(BREAK_MARK)));
-
-    cookie.append(BREAK_MARK);
-
-    foreach(variable, variableList) {
-        cookie.append(apiKey);
-        cookie.append(variable);
-    }
-    apiKey.remove(UNDERLINE_MARK);
-    cookie.append(apiKey);
-    cookie.append(signature);
-    cookie.append(BREAK_MARK);
-    cookie.append(locale);
-
-    qDebug() << cookie;
-
-    return cookie;
-}
diff --git a/src/cookiehandler/cookiehandler.h b/src/cookiehandler/cookiehandler.h
deleted file mode 100644 (file)
index afc72c1..0000000
+++ /dev/null
@@ -1,68 +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 COOKIEHANDLER_H
-#define COOKIEHANDLER_H
-
-#include <QString>
-#include "../situareservice/situarecommon.h"
-
-/**
-* @brief Class for cookie cretion.
-*
-* @author Henri Lampela
-* @class CookieHandler cookiehandler.h "cookiehandler/cookiehandler.h"
-*/
-class CookieHandler
-{
-public:
-
-    /**
-    * @brief Default constructor
-    *
-    */
-    CookieHandler();
-
-    /**
-    * @brief Destructor
-    *
-    */
-    ~CookieHandler();
-
-    /**
-    * @brief Forms a http cookie
-    *
-    * @param apiKeyValue application key
-    * @param expiresValue session expire date&time from Facebook
-    * @param userValue user id from Facebook
-    * @param sessionKeyValue session key from Facebook
-    * @param sessionSecretValue session secret from Facebook
-    * @param signatureValue md5 generated signature
-    * @param localeValue used locale
-    * @return QString formed cookie
-    */
-    QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
-                       QString sessionKeyValue, QString sessionSecretValue,
-                       const QString &signatureValue, const QString &localeValue);
-
-};
-
-#endif // COOKIEHANDLER_H
index a6aa7c8..8ca5ea5 100644 (file)
 
 #include "facebookauthentication.h"
 #include "facebookcommon.h"
+#include "parser.h"
 
 FacebookAuthentication::FacebookAuthentication(QWidget *parent)
-    : QMainWindow(parent)
+    : QMainWindow(parent),
+    m_email(),
+    m_loginAttempts(0),
+    m_password(),
+    m_refresh(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_refresh = false;
-    m_email.clear();
-    m_password.clear();
-    m_loginAttempts = 0;
-
-    m_loginDialog = new LoginDialog(this);
-
-    m_webView = new QWebView;
     m_mainlayout = new QHBoxLayout;
 
-    m_facebookLoginPage = formLoginPage(FACEBOOK_LOGINBASE, SITUARE_PUBLIC_FACEBOOKAPI_KEY,
-                                        INTERVAL1, SITUARE_LOGIN_SUCCESS, INTERVAL2,
-                                        SITUARE_LOGIN_FAILURE, FACEBOOK_LOGIN_ENDING);
-
-    connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
-            this, SLOT(updateCredentials(const QUrl &)));
-    connect(m_webView, SIGNAL(loadFinished(bool)),
-            this, SLOT(loadDone(bool)));
-
-    connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
-            this, SLOT(loginDialogDone(QString,QString)));
-
     connect(this, SIGNAL(loginFailure()),
             this, SLOT(loginFailed()));
 
@@ -69,32 +54,33 @@ FacebookAuthentication::~FacebookAuthentication()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if(m_webView) {
-        delete m_webView;
-        m_webView = 0;
-    }
-    if(m_mainlayout) {
-        delete m_mainlayout;
-        m_mainlayout = 0;
-    }
-    if(m_loginDialog) {
-        delete m_loginDialog;
-        m_loginDialog = 0;
-    }
+    delete m_mainlayout;
 }
 
 void FacebookAuthentication::loginDialogDone(const QString &email, const QString &password)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_email.append(email);
-    m_password.append(password);
+    m_email = email;
+    m_password = password;
 }
 
 void FacebookAuthentication::start()
 {
     qDebug() << __PRETTY_FUNCTION__;    
     if (!verifyCredentials(m_loginCredentials)){
+
+        m_webView = new QWebView(this);
+        m_loginDialog = new LoginDialog(this);
+
+        connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+                this, SLOT(updateCredentials(const QUrl &)));
+        connect(m_webView, SIGNAL(loadFinished(bool)),
+                this, SLOT(loadDone(bool)));
+
+        connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
+                this, SLOT(loginDialogDone(QString,QString)));
+
         if(m_loginDialog->exec() != QDialog::Accepted) {
             // if login dialog was canceled we need to stop processing webview            
             // stop and disconnect m_webView;
@@ -106,13 +92,21 @@ void FacebookAuthentication::start()
 
             emit quitSituare();
         }
-        m_webView->setZoomFactor(FACEBOOK_LOGINPAGE_FONT_SIZE);
-        m_webView->load(m_facebookLoginPage);
-        this->toggleProgressIndicator(true);
+        QStringList list;
+        list.append(FACEBOOK_LOGINBASE);
+        list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+        list.append(INTERVAL1);
+        list.append(SITUARE_LOGIN_SUCCESS);
+        list.append(INTERVAL2);
+        list.append(SITUARE_LOGIN_FAILURE);
+        list.append(FACEBOOK_LOGIN_ENDING);
+
+        m_webView->load(formLoginPageUrl(list));
+        toggleProgressIndicator(true);
         m_refresh = true;
         setCentralWidget(m_webView);
-        m_webView->hide();
         this->show();
+        m_webView->hide();
     }
     else
         emit credentialsReady(m_loginCredentials);
@@ -124,13 +118,21 @@ void FacebookAuthentication::loadDone(bool done)
 
     // for the first time the login page is opened, we need to refresh it to get cookies working
     if(m_refresh) {
-        m_webView->load(m_facebookLoginPage);
+        QStringList list;
+        list.append(FACEBOOK_LOGINBASE);
+        list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+        list.append(INTERVAL1);
+        list.append(SITUARE_LOGIN_SUCCESS);
+        list.append(INTERVAL2);
+        list.append(SITUARE_LOGIN_FAILURE);
+        list.append(FACEBOOK_LOGIN_ENDING);
+
+        m_webView->load(formLoginPageUrl(list));
         m_refresh = false;
     }
 
     if (done)
     {
-        this->toggleProgressIndicator(false);
         QWebFrame* frame = m_webView->page()->currentFrame();
         if (frame!=NULL)
         {
@@ -152,9 +154,11 @@ void FacebookAuthentication::loadDone(bool done)
                 QPoint pos(element.geometry().center());
 
                 // send a mouse click event to the web page
-                QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+                QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
+                                   Qt::NoModifier);
                 QApplication::sendEvent(m_webView->page(), &event0);
-                QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+                QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
+                                   Qt::NoModifier);
                 QApplication::sendEvent(m_webView->page(), &event1);
             }
         }
@@ -168,6 +172,8 @@ void FacebookAuthentication::loginFailed()
     m_email.clear();
     m_password.clear();
 
+    toggleProgressIndicator(false);
+
 #ifdef Q_WS_MAEMO_5
     QMaemo5InformationBox::information(this, tr("Invalid E-mail address or password"),
                                        QMaemo5InformationBox::NoTimeout);
@@ -187,124 +193,80 @@ void FacebookAuthentication::loginFailed()
     }
     else {
         // re-load login page for webview
-        this->toggleProgressIndicator(true);
-        m_webView->setZoomFactor(FACEBOOK_LOGINPAGE_FONT_SIZE);
-        m_webView->load(m_facebookLoginPage);
+        toggleProgressIndicator(true);
+        QStringList list;
+        list.append(FACEBOOK_LOGINBASE);
+        list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+        list.append(INTERVAL1);
+        list.append(SITUARE_LOGIN_SUCCESS);
+        list.append(INTERVAL2);
+        list.append(SITUARE_LOGIN_FAILURE);
+        list.append(FACEBOOK_LOGIN_ENDING);
+
+        m_webView->load(formLoginPageUrl(list));
     }
 }
 
 bool FacebookAuthentication::updateCredentials(const QUrl &url)
-{    
+{
     qDebug() << __PRETTY_FUNCTION__;
 
-    bool foundSessionKey = FALSE;
-    bool foundUserID = FALSE;
-    bool foundExpires = FALSE;
-    bool foundSessionSecret = FALSE;
-    bool foundSig = FALSE;
+    bool found = false;
 
     if (url.isValid()){
-         qDebug() << "url is valid" << endl;
+         qDebug() << "url is valid";
 
         QString callbackUrl = url.toString();
-        QString urlEdit(callbackUrl);
-        qDebug() << "callbackUrl:  " << endl << callbackUrl.toAscii() << endl;
+        qDebug() << "callbackUrl:  " << callbackUrl.toAscii();
 
-        if ( callbackUrl.indexOf(LOGIN_SUCCESS_REPLY) == 0 ){
-            qDebug() << "login success" << endl;
+        if (callbackUrl.indexOf(LOGIN_SUCCESS_REPLY) == 0) {
+            qDebug() << "login success";
 
             disconnect(m_webView, SIGNAL(loadFinished(bool)),
                        this, SLOT(loadDone(bool)));
             disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
                        this, SLOT(updateCredentials(const QUrl &)));
 
-            // let's find out session key            
-            int indexOfCredential = callbackUrl.indexOf(SESSION_KEY);
+            // let's find out session credentials
+            if(callbackUrl.contains(SESSION_KEY)) {
 
-            if (indexOfCredential != -1){
-                foundSessionKey = TRUE;
+                QJson::Parser parser;
+                bool ok;
 
-                indexOfCredential += 14; //lenght of SESSION_KEY
-                urlEdit.remove(0,indexOfCredential);
-                indexOfCredential = urlEdit.indexOf(USER_ID);
-                urlEdit.remove(indexOfCredential, urlEdit.length());
-                urlEdit.remove("\",\"");
+                // split string into string part and json part
+                QStringList list = url.toString().split("=");
 
-                qDebug() << "Session Key" << endl << urlEdit.toAscii() << endl;
-                m_loginCredentials.setSessionKey(urlEdit);
-            }
+                for(int i=0;i<list.count();i++) {
+                    // if string starts with json item
+                    if(list.at(i).startsWith("{")) {
+                        QByteArray jsonString = list.at(i).toAscii();
+                        QVariantMap result = parser.parse (jsonString, &ok).toMap();
+                        if (!ok) {
 
-            // let's find out uid            
-            urlEdit = callbackUrl;
-            indexOfCredential = callbackUrl.indexOf(USER_ID);
+                            qFatal("An error occurred during parsing");
+                            exit (1);
+                        }
+                        qDebug() << "Session Key" << result[SESSION_KEY].toString();
+                        m_loginCredentials.setSessionKey(result[SESSION_KEY].toString());
 
-            if (indexOfCredential != -1){
-                foundUserID = TRUE;
+                        qDebug() << "userID" << result[USER_ID].toString();
+                        m_loginCredentials.setUserID(result[USER_ID].toString());
 
-                indexOfCredential += 5; //length of USER_ID:
-                urlEdit.remove(0,indexOfCredential);
-                indexOfCredential = urlEdit.indexOf(EXPIRES);
-                urlEdit.remove(indexOfCredential, urlEdit.length());
-                urlEdit.remove(",\"");
-
-                qDebug() << "userID" << endl << urlEdit.toAscii() << endl;
-                m_loginCredentials.setUserID(urlEdit);
-            }
+                        qDebug() << "Expires" << result[EXPIRES].toString();
+                        m_loginCredentials.setExpires(result[EXPIRES].toString());
 
-            // let's find out expires           
-            urlEdit = callbackUrl;
-            indexOfCredential = callbackUrl.indexOf(EXPIRES);
+                        qDebug() << "Session Secret" << result[SESSION_SECRET].toString();
+                        m_loginCredentials.setSessionSecret(result[SESSION_SECRET].toString());
 
-            if (indexOfCredential != -1){
-                foundExpires = TRUE;
-
-                indexOfCredential += 9; //length of EXPIRES
-                urlEdit.remove(0,indexOfCredential);
-                indexOfCredential = urlEdit.indexOf(SESSION_SECRET);
-                urlEdit.remove(indexOfCredential, urlEdit.length());
-                urlEdit.remove(",\"");
-
-                qDebug() << "Expires" << endl << urlEdit.toAscii() << endl;
-                m_loginCredentials.setExpires(urlEdit);
-            }
-
-            // let's find out sessionsecret            
-            urlEdit = callbackUrl;
-            indexOfCredential = callbackUrl.indexOf(SESSION_SECRET);
-
-            if (indexOfCredential != -1){
-                foundSessionSecret = TRUE;
-
-                indexOfCredential += 9; //" length of SESSION_SECRET
-                urlEdit.remove(0,indexOfCredential);
-                indexOfCredential = urlEdit.indexOf(SIGNATURE);
-                urlEdit.remove(indexOfCredential, urlEdit.length());
-                urlEdit.remove("\",\"");
-
-                qDebug() << "Session Secret" << endl << urlEdit.toAscii() << endl;
-                m_loginCredentials.setSessionSecret(urlEdit);
-            }
-
-            // let's find out sig            
-            urlEdit = callbackUrl;
-            indexOfCredential = callbackUrl.indexOf(SIGNATURE);
-
-            if (indexOfCredential != -1){
-                foundSig = TRUE;
-
-                indexOfCredential += 6; //" length of SIGNATURE
-                urlEdit.remove(0,indexOfCredential);
-                urlEdit.remove("\"}");
-
-                qDebug() << "Signature" << endl << urlEdit.toAscii() << endl;
-                m_loginCredentials.setSig(urlEdit);
+                        qDebug() << "Signature" << result[SIGNATURE].toString();
+                        m_loginCredentials.setSig(result[SIGNATURE].toString());
+                    }
+                }
+                found = true;
             }
-
-            m_webView->hide();
             writeCredentials(m_loginCredentials);
             emit credentialsReady(m_loginCredentials);
         }
-
         else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
             qWarning() << "login failure" << endl;
             qDebug() << callbackUrl;
@@ -316,26 +278,22 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
                 emit loginFailure();
             }
         }
-
-        else if ( callbackUrl.indexOf(LOGIN_PAGE) == 0){
+        else if(callbackUrl.indexOf(LOGIN_PAGE) == 0) {
             qDebug() << "correct loginPage";
         }
-
         else {
             qDebug() << "totally wrong webPage";
             // we should not get a wrong page at this point
             emit loginFailure();
         }
     }
-
     else {
         qDebug() << " Loading of page failed invalid URL" << endl;
         // we should not get a wrong page at this point
         emit loginFailure();
-        return FALSE;
+        return false;
     }
-
-    return (foundSessionKey && foundUserID && foundExpires && foundSessionSecret && foundSig);
+    return found;
 }
 
 void FacebookAuthentication::writeCredentials(const FacebookCredentials &credentials)
@@ -343,11 +301,11 @@ void FacebookAuthentication::writeCredentials(const FacebookCredentials &credent
     qDebug() << __PRETTY_FUNCTION__;
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    settings.setValue("Session Key", credentials.sessionKey());
-    settings.setValue("User ID", credentials.userID());
-    settings.setValue("Expires", credentials.expires());
-    settings.setValue("Session Secret", credentials.sessionSecret());
-    settings.setValue("Sig", credentials.sig());
+    settings.setValue(SESSION_KEY, credentials.sessionKey());
+    settings.setValue(USER_ID, credentials.userID());
+    settings.setValue(EXPIRES, credentials.expires());
+    settings.setValue(SESSION_SECRET, credentials.sessionSecret());
+    settings.setValue(SIGNATURE, credentials.sig());
 }
 
 void FacebookAuthentication::readCredentials(FacebookCredentials &credentialsFromFile)
@@ -356,11 +314,11 @@ void FacebookAuthentication::readCredentials(FacebookCredentials &credentialsFro
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    credentialsFromFile.setSessionKey(settings.value("Session Key", "Error").toString());
-    credentialsFromFile.setUserID(settings.value("User ID", "Error").toString());
-    credentialsFromFile.setExpires(settings.value("Expires", "Error").toString());
-    credentialsFromFile.setSessionSecret(settings.value("Session Secret", "Error").toString());
-    credentialsFromFile.setSig(settings.value("Sig", "Error").toString());
+    credentialsFromFile.setSessionKey(settings.value(SESSION_KEY, ERROR).toString());
+    credentialsFromFile.setUserID(settings.value(USER_ID, ERROR).toString());
+    credentialsFromFile.setExpires(settings.value(EXPIRES, ERROR).toString());
+    credentialsFromFile.setSessionSecret(settings.value(SESSION_SECRET, ERROR).toString());
+    credentialsFromFile.setSig(settings.value(SIGNATURE, ERROR).toString());
 }
 
  FacebookCredentials FacebookAuthentication::loginCredentials() const
@@ -378,37 +336,27 @@ void FacebookAuthentication::readCredentials(FacebookCredentials &credentialsFro
          return true;
      }
      else {
+         const QString dateTimeFormat = "dd.MM.yyyy  hh:mm:ss";
          QString expires = credentials.expires();
          QDateTime expireTime;
          expireTime.setTime_t(expires.toInt());
-         QString expiresString = expireTime.toString("dd.MM.yyyy  hh:mm:ss");
+         QString expiresString = expireTime.toString(dateTimeFormat);
          qDebug() << expiresString.toAscii();
 
          QDateTime currentTime;
          currentTime = QDateTime::currentDateTime();
-         QString currentTimeString = currentTime.toString("dd.MM.yyyy  hh:mm:ss");
+         QString currentTimeString = currentTime.toString(dateTimeFormat);
          qDebug() << currentTimeString.toAscii();
 
          return currentTime < expireTime;
      }
  }
 
- QString FacebookAuthentication::formLoginPage(const QString & part1, const QString & part2,
-                                 const QString & part3, const QString & part4,
-                                 const QString & part5, const QString & part6,
-                                 const QString & part7) const
+ QUrl FacebookAuthentication::formLoginPageUrl(const QStringList &urlParts) const
  {
-     QString loginPage;
-     loginPage.append(part1);
-     loginPage.append(part2);
-     loginPage.append(part3);
-     loginPage.append(part4);
-     loginPage.append(part5);
-     loginPage.append(part5);
-     loginPage.append(part6);
-     loginPage.append(part7);
-
-     return loginPage;
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return QUrl(urlParts.join(EMPTY));
  }
 
  void FacebookAuthentication::toggleProgressIndicator(bool value)
index c7d1a10..5d17f5c 100644 (file)
@@ -65,6 +65,10 @@ public:
     */
     ~FacebookAuthentication();
 
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+
     /**
     * @brief Getter for m_loginCredentials
     *
@@ -99,20 +103,12 @@ public slots:
 private: 
 
     /**
-    * @brief  Appends given parts to returned string. Method is used to form facebook login page
-              from given parts.
+    * @brief Creates login url with given parameters
     *
-    * @param  part1 first part of the formed string
-    * @param  part2 second part of the formed string
-    * @param  part3 third part of the formed string
-    * @param  part4 fouth part of the formed string
-    * @param  part5 fifth part of the formed string
-    * @param  part6 sixth part of the formed string
-    * @param  part7 sevents part of the formed string
+    * @param urlParts Url parts
+    * @return QUrl Login page url
     */
-    QString formLoginPage(const QString & part1, const QString & part2, const QString & part3,
-                          const QString & part4, const QString & part5, const QString & part6,
-                          const QString & part7) const;
+    QUrl formLoginPageUrl(const QStringList & urlParts) const;
 
     /**
     * @brief Reads previous stored credentials from file.
@@ -162,6 +158,10 @@ private slots:
     */
     void loginFailed();
 
+/*******************************************************************************
+ * SIGNALS
+ ******************************************************************************/
+
 signals:
 
     /**
@@ -185,6 +185,10 @@ signals:
     */
     void quitSituare();
 
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+
 private:
 
     /**
@@ -196,7 +200,6 @@ private:
     FacebookCredentials m_loginCredentials;
 
     QString m_email; ///< Placeholder for email
-    QString m_facebookLoginPage; ///< String that contantains URL of facebook loginpage.
     int m_loginAttempts; ///< Indicates login attempts
     LoginDialog *m_loginDialog; ///< Login dialog
     QHBoxLayout *m_mainlayout; ///< Lays out m_webView in window.
index d638fb0..fd2ee1f 100644 (file)
@@ -34,6 +34,9 @@ const QString INTERVAL2 = "&cancel_url=";
 const QString SITUARE_LOGIN_FAILURE = "http://www.facebook.com/connect/login_failure.html";
 const QString FACEBOOK_LOGIN_ENDING = "&fbconnect=true&return_session=true&";
 
+const QString EMPTY = "";
+const QString ERROR = "Error";
+
 // Facebook webView font size
 const double FACEBOOK_LOGINPAGE_FONT_SIZE = 1.2;
 
index 6563f59..c9080a8 100644 (file)
@@ -27,7 +27,6 @@
 #include <QNetworkReply>
 #include "situareservice.h"
 #include "situarecommon.h"
-#include "../cookiehandler/cookiehandler.h"
 #include "parser.h"
 
 SituareService::SituareService(QObject *parent)
@@ -68,11 +67,9 @@ void SituareService::fetchLocations()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    CookieHandler cookieHandler;
-
-    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
-                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                              m_credentials.sig(), EN_LOCALE);
+    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
+                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                m_credentials.sig(), EN_LOCALE);
 
     QUrl url = formUrl(SITUARE_URL, GET_LOCATIONS);
     sendRequest(url, COOKIE, cookie);
@@ -82,11 +79,9 @@ void SituareService::reverseGeo(const QPointF &coordinates)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    CookieHandler cookieHandler;
-
-    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
-                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                              m_credentials.sig(), EN_LOCALE);
+    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
+                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                m_credentials.sig(), EN_LOCALE);
 
     QString urlParameters = formUrlParameters(coordinates);
     QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
@@ -99,11 +94,9 @@ void SituareService::updateLocation(const QPointF &coordinates, const QString &s
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    CookieHandler cookieHandler;
-
-    QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
-                                              m_credentials.sessionKey(), m_credentials.sessionSecret(),
-                                              m_credentials.sig(), EN_LOCALE);
+    QString cookie = formCookie(API_KEY, m_credentials.expires(),m_credentials.userID(),
+                                m_credentials.sessionKey(), m_credentials.sessionSecret(),
+                                m_credentials.sig(), EN_LOCALE);
 
 
     QString publishValue;
@@ -119,7 +112,64 @@ void SituareService::updateLocation(const QPointF &coordinates, const QString &s
     sendRequest(url, COOKIE, cookie);
 }
 
-QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters)
+QString SituareService::formCookie(const QString &apiKeyValue, QString expiresValue,
+                                   QString userValue, QString sessionKeyValue,
+                                   QString sessionSecretValue, const QString &signatureValue,
+                                   const QString &localeValue)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString cookie;
+    QString apiKey;
+    QString user;
+    QString expires;
+    QString sessionKey;
+    QString sessionSecret;
+    QString locale;
+    QString variable;
+    QString signature = EQUAL_MARK;
+    QStringList variableList;
+
+    signature.append(signatureValue);
+    apiKey.append(apiKeyValue);
+    apiKey.append(UNDERLINE_MARK);
+
+    user.append(USER);
+    user.append(EQUAL_MARK);
+    expires.append(EXPIRES);
+    expires.append(EQUAL_MARK);
+    sessionKey.append(SESSION_KEY);
+    sessionKey.append(EQUAL_MARK);
+    sessionSecret.append(SESSION_SECRET);
+    sessionSecret.append(EQUAL_MARK);
+    locale.append(LOCALE);
+    locale.append(EQUAL_MARK);
+    locale.append(localeValue);
+
+    variableList.append(expires.append(expiresValue.append(BREAK_MARK)));
+    variableList.append(sessionKey.append(sessionKeyValue.append(BREAK_MARK)));
+    variableList.append(user.append(userValue).append(BREAK_MARK));
+    variableList.append(sessionSecret.append(sessionSecretValue.append(BREAK_MARK)));
+
+    cookie.append(BREAK_MARK);
+
+    foreach(variable, variableList) {
+        cookie.append(apiKey);
+        cookie.append(variable);
+    }
+    apiKey.remove(UNDERLINE_MARK);
+    cookie.append(apiKey);
+    cookie.append(signature);
+    cookie.append(BREAK_MARK);
+    cookie.append(locale);
+
+    qDebug() << cookie;
+
+    return cookie;
+}
+
+QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript,
+                             QString urlParameters)
 {
     qDebug() << __PRETTY_FUNCTION__;
     QString urlString;
@@ -136,7 +186,8 @@ QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript, Q
     return url;
 }
 
-QString SituareService::formUrlParameters(const QPointF &coordinates, QString status, QString publish)
+QString SituareService::formUrlParameters(const QPointF &coordinates, QString status,
+                                          QString publish)
 {
     QString parameters;
 
@@ -299,9 +350,12 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
           m_defaultImage = true;
       }
 
-      User *user = new User(friendMap["address"].toString(), coordinates, friendMap["name"].toString(),
-                            friendMap["note"].toString(), imageUrl, friendMap["timestamp"].toString(),
-                            false, friendMap["uid"].toString(), distanceMap["units"].toString(),
+      User *user = new User(friendMap["address"].toString(), coordinates,
+                            friendMap["name"].toString(),
+                            friendMap["note"].toString(), imageUrl,
+                            friendMap["timestamp"].toString(),
+                            false, friendMap["uid"].toString(),
+                            distanceMap["units"].toString(),
                             distanceMap["value"].toDouble());
 
       m_friendsList.append(user);
index 605dfe9..821921b 100644 (file)
@@ -104,6 +104,22 @@ public slots:
 private:
 
     /**
+    * @brief Forms a http cookie
+    *
+    * @param apiKeyValue application key
+    * @param expiresValue session expire date&time from Facebook
+    * @param userValue user id from Facebook
+    * @param sessionKeyValue session key from Facebook
+    * @param sessionSecretValue session secret from Facebook
+    * @param signatureValue md5 generated signature
+    * @param localeValue used locale
+    * @return QString formed cookie
+    */
+    QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
+                       QString sessionKeyValue, QString sessionSecretValue,
+                       const QString &signatureValue, const QString &localeValue);
+
+    /**
     * @brief Forms a http url
     *
     * @param baseUrl Server url
index 9f7f6e2..730afaa 100644 (file)
@@ -11,7 +11,6 @@ SOURCES += main.cpp \
     ui/mapviewscreen.cpp \
     situareservice/situareservice.cpp \
     situareservice/imagefetcher.cpp \
-    cookiehandler/cookiehandler.cpp \
     facebookservice/facebookcredentials.cpp \
     facebookservice/facebookauthentication.cpp \
     map/mapengine.cpp \
@@ -59,7 +58,6 @@ HEADERS += ui/mainwindow.h \
     situareservice/situareservice.h \
     situareservice/situarecommon.h \
     situareservice/imagefetcher.h \
-    cookiehandler/cookiehandler.h \
     facebookservice/facebookcredentials.h \
     facebookservice/facebookauthentication.h \
     facebookservice/facebookcommon.h \
diff --git a/tests/cookiehandler/testcookiehandler.cpp b/tests/cookiehandler/testcookiehandler.cpp
deleted file mode 100644 (file)
index e38a036..0000000
+++ /dev/null
@@ -1,58 +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 <QtTest/QtTest>
-#include <QtCore>
-
-
-#include "../../src/cookiehandler/cookiehandler.h"
-#include "../../src/situareservice/situarecommon.h"
-
-
-class testCookieHandler : public QObject
-{
-    Q_OBJECT
-private:
-    CookieHandler *cookieHandler;
-
-private slots:
-
-    void testFormCookie();
-
-};
-
-void testCookieHandler::testFormCookie()
-{
-    const QString apiKey = "1";
-    const QString expires = "2";
-    const QString sessionKey = "3";
-    const QString user = "4";
-    const QString sessionSecret = "5";
-    const QString signature = "6";
-    const QString locale = "7";
-
-    QString cookie = cookieHandler->formCookie(apiKey, expires, user, sessionKey, sessionSecret, signature, locale);
-
-    QCOMPARE(QString(";1_expires=2;1_session_key=3;1_user=4;1_ss=5;1=6;locale=7"), cookie);
-}
-
-QTEST_MAIN(testCookieHandler)
-#include "testcookiehandler.moc"
diff --git a/tests/cookiehandler/testcookiehandler.pro b/tests/cookiehandler/testcookiehandler.pro
deleted file mode 100644 (file)
index 6bd6b77..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-######################################################################
-# Automatically generated by qmake (2.01a) Fri Apr 9 13:34:34 2010
-######################################################################
-
-CONFIG += qtestlib
-TEMPLATE = app
-TARGET = 
-DEPENDPATH += .
-INCLUDEPATH += .
-
-# Input
-HEADERS += ../../src/cookiehandler/cookiehandler.h \
-           ../../src/situareservice/situarecommon.h
-SOURCES += testcookiehandler.cpp \
-           ../../src/cookiehandler/cookiehandler.cpp