USA.
*/
+#include "parser.h"
+
#include <QtDebug>
#include <QDateTime>
#include <QSettings>
#include <QMaemo5InformationBox>
#endif // Q_WS_MAEMO_5
-#include "facebookauthentication.h"
-#include "facebookcommon.h"
#include "common.h"
-#include "parser.h"
+#include "error.h"
+#include "facebookcommon.h"
+
+#include "facebookauthentication.h"
+
+const QString REDIRECT_URI = "http://www.facebook.com/connect/login_success.html";
FacebookAuthentication::FacebookAuthentication(QObject *parent)
: QObject(parent),
settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
}
+void FacebookAuthentication::loadFinished(bool ok)
+{
+ qWarning() << __PRETTY_FUNCTION__ << ok;
+
+ ///< @todo show browsed window if url != redirect url
+}
+
const QString FacebookAuthentication::loadUsername()
{
qDebug() << __PRETTY_FUNCTION__;
return m_loginCredentials;
}
+QString FacebookAuthentication::parseAccessToken(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();
+}
+
void FacebookAuthentication::saveUsername(const QString &username)
{
qDebug() << __PRETTY_FUNCTION__;
QVariantMap result = parser.parse (jsonString, &ok).toMap();
if (!ok) {
- emit error(SituareError::INVALID_JSON);
+ emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
found = false;
} else {
qDebug() << "Session Key" << result[SESSION_KEY].toString();
emit credentialsReady(m_loginCredentials);
}
}
- }
- }
+ }
+ }
} else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0) {
qDebug() << "login failure";
qDebug() << callbackUrl;
clearAccountInformation(true);
if(m_freshLogin) {
- emit error(SituareError::LOGIN_FAILED);
+ emit error(ErrorContext::SITUARE, SituareError::LOGIN_FAILED);
} else {
m_freshLogin = true;
- emit error(SituareError::SESSION_EXPIRED);
+ 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(SituareError::LOGIN_FAILED);
+ 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(SituareError::LOGIN_FAILED);
+ 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)) {
+ ///< @todo hide browser dialog
+ qWarning() << __PRETTY_FUNCTION__ << "access_token:" << parseAccessToken(url);
+ }
+}