}
}
-void SituareEngine::fetchUsernameFromSettings()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_ui->setUsername(m_facebookAuthenticator->loadUsername());
-}
-
void SituareEngine::imageReady(User *user)
{
qDebug() << __PRETTY_FUNCTION__;
logout();
m_situareService->clearUserData();
} else {
- m_facebookAuthenticator->start();
+ login();
}
}
else {
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
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__;
{
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);
}
///< @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("}");
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<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) {
- emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
- found = false;
- } else {
- qDebug() << "Session Key" << result[SESSION_KEY].toString();
- m_loginCredentials.setSessionKey(result[SESSION_KEY].toString());
-
- // // commeted out until qjson parser can handle 64-bit integers
- // qDebug() << "userID" << result[USER_ID].toString();
- // m_loginCredentials.setUserID(result[USER_ID].toString().toAscii());
-
- // dirty fix, get user id from session_key
- QStringList list = result[SESSION_KEY].toString().split("-");
- m_loginCredentials.setUserID(list.at(1));
- qDebug() << m_loginCredentials.userID();
-
- qDebug() << "Expires" << result[EXPIRES].toString();
- m_loginCredentials.setExpires(result[EXPIRES].toString());
-
- qDebug() << "Session Secret" << result[SESSION_SECRET].toString();
- m_loginCredentials.setSessionSecret(result[SESSION_SECRET].toString());
-
- qDebug() << "Signature" << result[SIGNATURE].toString();
- m_loginCredentials.setSig(result[SIGNATURE].toString());
-
- found = true;
- m_freshLogin = false;
- emit saveCookiesRequest();
- emit credentialsReady(m_loginCredentials);
- }
- }
- }
- }
- } else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0) {
- qDebug() << "login failure";
- qDebug() << callbackUrl;
- clearAccountInformation(true);
- if(m_freshLogin) {
- emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
- } else {
- m_freshLogin = true;
- emit error(ErrorContext::SITUARE, SituareError::SESSION_EXPIRED);
- }
- } 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 error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
- }
- } else {
- qDebug() << " Loading of page failed invalid URL" << endl;
- // we should not get a wrong page at this point
- emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
- }
- return found;
-}
-
void FacebookAuthentication::urlChanged(const QUrl &url)
{
qWarning() << __PRETTY_FUNCTION__ << url.toString();
// if login succeeded
if (url.toString().startsWith(REDIRECT_URI)) {
- const QString accessToken = parseAccessToken(url);
- qWarning() << __PRETTY_FUNCTION__ << "parsed access token:" << accessToken;
- if (!accessToken.isEmpty())
- emit loggedIn(accessToken);
+ const QString session = parseSession(url);
+ qWarning() << __PRETTY_FUNCTION__ << "parsed session:" << session;
+ if (!session.isEmpty())
+ emit loggedIn(session);
}
}
#define FACEBOOKAUTHENTICATION_H
#include <QUrl>
-#include "facebookcredentials.h"
/**
* @brief FacebookAuthentication class takes care of parsing and handling of credentials for
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-public:
- /**
- * @brief Getter for m_loginCredentials
- *
- * @return FacebookCredentials
- */
- FacebookCredentials loginCredentials() const;
-
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:
/**
*/
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
*/
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
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=";
+++ /dev/null
-/*
- 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 <QtGlobal>
-#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;
-}
+++ /dev/null
-/*
- 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 <QString>
-
-/**
-* @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
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;
}
// qWarning() << __PRETTY_FUNCTION__ << "request url with parameters:" << url;
- if (!m_accessToken.isEmpty()) {
+ if (!m_session.isEmpty()) {
appendAccessToken(url);
sendRequest(url);
} else {
emit userDataChanged(m_user, m_friendsList);
}
-void SituareService::credentialsReady(const FacebookCredentials &credentials)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_credentials = credentials;
-}
-
QString SituareService::degreesToString(double degrees)
{
qDebug() << __PRETTY_FUNCTION__;
m_currentRequests.append(reply);
}
-void SituareService::updateAccessToken(const QString &accessToken)
+void SituareService::updateSession(const QString &session)
{
qWarning() << __PRETTY_FUNCTION__;
- m_accessToken = accessToken;
+ m_session = session;
foreach (QString request, m_requestsWaitingAccessToken) {
appendAccessToken(request);
#define SITUARESERVICE_H
#include <QObject>
-#include "../facebookservice/facebookcredentials.h"
+
#include "../user/user.h"
#include "imagefetcher.h"
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:
QList<QString> m_requestsWaitingAccessToken;
QList<User *> 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
};
engine/engine.cpp \
engine/mce.cpp \
facebookservice/facebookauthentication.cpp \
- facebookservice/facebookcredentials.cpp \
gps/gpsposition.cpp \
map/baselocationitem.cpp \
map/friendgroupitem.cpp \
error.h \
facebookservice/facebookauthentication.h \
facebookservice/facebookcommon.h \
- facebookservice/facebookcredentials.h \
gps/gpscommon.h \
gps/gpsposition.h \
map/baselocationitem.h \
readAutomaticLocationUpdateSettings();
}
-void MainWindow::setUsername(const QString &username)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_email = username;
-}
-
void MainWindow::showContactDialog(const QString &guid)
{
qDebug() << __PRETTY_FUNCTION__;
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.