backup
[situare] / src / facebookservice / facebookauthentication.cpp
index cba99ed..02d83ec 100644 (file)
 
 #include "facebookauthentication.h"
 #include "facebookcommon.h"
-#include "../common.h"
+#include "common.h"
 #include "parser.h"
 
 FacebookAuthentication::FacebookAuthentication(QObject *parent)
     : QObject(parent),
-    m_freshLogin(false),
-    m_loginAttempts(0)
-
+    m_freshLogin(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -53,10 +51,15 @@ void FacebookAuthentication::clearAccountInformation(bool keepUsername)
     m_loginCredentials.clearCredentials();
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
 
-    if(!keepUsername)
+    if(!keepUsername) {
         settings.remove(USERNAME);
+        settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED);
+        settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL);
+    }
 
     settings.remove(COOKIES);
+    settings.remove(USER_UNSEND_MESSAGE);
+    settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
 }
 
 const QString FacebookAuthentication::loadUsername()
@@ -99,7 +102,7 @@ void FacebookAuthentication::start()
 
 bool FacebookAuthentication::updateCredentials(const QUrl &url)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__ << url.toString();
 
     bool found = false;
 
@@ -129,7 +132,8 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
                         if (!ok) {
 
                             qFatal("An error occurred during parsing");
-                            exit (1);
+                            emit error(SituareError::INVALID_JSON);
+                            found = false;
                         }
                         qDebug() << "Session Key" << result[SESSION_KEY].toString();
                         m_loginCredentials.setSessionKey(result[SESSION_KEY].toString());
@@ -162,20 +166,14 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
         else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
             qWarning() << "login failure" << endl;
             qDebug() << callbackUrl;
-            ++m_loginAttempts;
-            /* emit loginFailure for every second login attemps, since webview loads login
-               error page (loadingDone() signal is emitted) and we need to avoid that because
-               at this point we don't have new login parameters */
-            if(m_loginAttempts % 2) {
-                clearAccountInformation(true);
-                if(m_freshLogin) {
-                    emit error(LOGIN_FAILED);
-                    emit loginFailure();
-                }
-                else {
-                    m_freshLogin = true;
-                    emit error(SESSION_EXPIRED);
-                }
+            clearAccountInformation(true);
+            if(m_freshLogin) {
+                emit error(SituareError::LOGIN_FAILED);
+                emit loginFailure();
+            }
+            else {
+                m_freshLogin = true;
+                emit error(SituareError::SESSION_EXPIRED);
             }
         }
         else if(callbackUrl.indexOf(LOGIN_PAGE) == 0) {