13 * |
13 * |
14 * Description: |
14 * Description: |
15 * Login Dialog class of Authentication Application |
15 * Login Dialog class of Authentication Application |
16 */ |
16 */ |
17 |
17 |
|
18 #include <qdebug.h> |
|
19 |
18 #include "authAppConstants.h" |
20 #include "authAppConstants.h" |
19 #include "sessionSP.h" |
21 #include "sessionSP.h" |
20 #include "errorCodes.h" |
22 #include "errorCodes.h" |
21 #include "loginDialog.h" |
23 #include "loginDialog.h" |
22 |
24 |
27 static const QString kLoginURL = "http://www.facebook.com/login.php"; |
29 static const QString kLoginURL = "http://www.facebook.com/login.php"; |
28 |
30 |
29 /////////////////////////////////////////////////////////////////////////////////////////////////// |
31 /////////////////////////////////////////////////////////////////////////////////////////////////// |
30 void FBLoginDialog::connectToGetSession(const QString& aToken) |
32 void FBLoginDialog::connectToGetSession(const QString& aToken) |
31 { |
33 { |
|
34 qDebug()<<"Inside FBLoginDialog::connectToGetSession()"; |
32 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
35 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
33 |
36 |
34 connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
37 connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
35 connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
38 connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
36 connect(iGetSessionRequest, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError))); |
39 connect(iGetSessionRequest, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError))); |
53 } |
56 } |
54 } |
57 } |
55 |
58 |
56 void FBLoginDialog::loadLoginPage() |
59 void FBLoginDialog::loadLoginPage() |
57 { |
60 { |
|
61 qDebug()<<"Inside FBLoginDialog::loadLoginPage()"; |
58 Dictionary getParams, postParams; |
62 Dictionary getParams, postParams; |
59 |
|
60 getParams["fbconnect"] = "1"; |
|
61 |
|
62 #ifdef __WINSCW__ |
|
63 getParams["connect_display"] = "touch"; |
|
64 #else |
|
65 getParams["connect_display"] = "popup"; |
|
66 #endif |
|
67 |
|
68 getParams["api_key"] = iSession->apiKey(); |
63 getParams["api_key"] = iSession->apiKey(); |
|
64 getParams["connect_display"] = "popup"; |
|
65 getParams["v"]="1.0"; |
69 getParams["next"] = KSuccessurl; |
66 getParams["next"] = KSuccessurl; |
70 getParams["cancel_url"] = "http://www.facebook.com/connect/login_failure.html"; |
67 getParams["cancel_url"] = "http://www.facebook.com/connect/login_failure.html"; |
71 getParams["req_perms"] = "read_stream,publish_stream,offline_access"; |
68 getParams["fbconnect"] = "1"; |
|
69 getParams["return_session"]="1"; // Uncomment this to get session in the url |
|
70 getParams["session_key_only"]="1"; // Uncomment this to get session in the url |
|
71 getParams["ext_perm"/*"req_perms"*/] = "read_stream,publish_stream,offline_access,user_photos,friends_photos,user_status,friends_status,user_location,friends_location,user_activities,friends_activities,user_relationships,friends_relationships,read_requests,read_friendlists"; |
|
72 // req_perms=read_stream,publish_stream,offline_access |
72 |
73 |
73 loadURL(kLoginURL,QNetworkAccessManager::GetOperation, getParams, postParams); |
74 loadURL(kLoginURL,QNetworkAccessManager::GetOperation, getParams, postParams); |
74 |
75 |
75 } |
76 } |
76 /////////////////////////////////////////////////////////////////////////////////////////////////// |
77 /////////////////////////////////////////////////////////////////////////////////////////////////// |
82 /////////////////////////////////////////////////////////////////////////////////////////////////// |
83 /////////////////////////////////////////////////////////////////////////////////////////////////// |
83 // FBDialog |
84 // FBDialog |
84 |
85 |
85 void FBLoginDialog::load() |
86 void FBLoginDialog::load() |
86 { |
87 { |
|
88 qDebug()<<"Inside FBLoginDialog::load()"; |
87 loadLoginPage(); |
89 loadLoginPage(); |
88 } |
90 } |
89 |
91 |
90 void FBLoginDialog::dialogWillDisappear() |
92 void FBLoginDialog::dialogWillDisappear() |
91 { |
93 { |
|
94 qDebug()<<"Inside FBLoginDialog::dialogWillDisappear()"; |
92 iGetSessionRequest->cancel(); |
95 iGetSessionRequest->cancel(); |
93 |
96 |
94 if (!iSession->isConnected()) |
97 if (!iSession->isConnected()) |
95 { |
98 { |
96 iSession->cancelLogin(); |
99 iSession->cancelLogin(); |
97 } |
100 } |
98 } |
101 } |
99 |
102 |
100 void FBLoginDialog::GetSessionKey(const QUrl& aUrl) |
103 void FBLoginDialog::GetSessionKey(const QUrl& aUrl) |
101 { |
104 { |
|
105 qDebug()<<"Inside FBLoginDialog::GetSessionKey()"; |
102 const QString authToken = "auth_token="; |
106 const QString authToken = "auth_token="; |
103 const QString url ( aUrl.toString() ); |
107 const QString url ( aUrl.toString() ); |
104 |
108 |
105 int start = url.indexOf(authToken); |
109 int start = url.indexOf(authToken); |
106 if (start != -1) |
110 if (start != -1) |
118 } |
122 } |
119 |
123 |
120 connectToGetSession(token); |
124 connectToGetSession(token); |
121 } |
125 } |
122 } |
126 } |
123 |
127 void FBLoginDialog::FetchKeyFromUrl(const QUrl& aUrl) |
|
128 { |
|
129 const QString url ( aUrl.toString() ); |
|
130 QStringList varList = url.split("{"); |
|
131 QString newvar = varList[1]; |
|
132 varList.clear(); |
|
133 varList = newvar.split(","); |
|
134 QString session_key = varList[0]; |
|
135 QString uid = varList[1]; |
|
136 QString expires = varList[2]; |
|
137 QString secret = varList[3]; |
|
138 varList.clear(); |
|
139 varList = session_key.split(":"); |
|
140 session_key = varList[1]; |
|
141 session_key = session_key.mid(1,session_key.length()-2); |
|
142 varList.clear(); |
|
143 varList = uid.split(":"); |
|
144 uid = varList[1]; |
|
145 varList.clear(); |
|
146 varList = expires.split(":"); |
|
147 expires = varList[1]; |
|
148 varList.clear(); |
|
149 varList = secret.split(":"); |
|
150 secret = varList[1]; |
|
151 secret = secret.mid(1,secret.length()-2); |
|
152 varList.clear(); |
|
153 qDebug()<<"session_key"<<session_key<<"\n"; |
|
154 qDebug()<<"uid"<<uid<<"\n"; |
|
155 qDebug()<<"expires"<<expires<<"\n"; |
|
156 qDebug()<<"secret"<<secret<<"\n"; |
|
157 bool ok = false; |
|
158 uint expiry = expires.toUInt();//.toUInt(&conversionError); |
|
159 QDateTime expiration; expiration.setTime_t( expiry ); |
|
160 iSession->beginSession(session_key, secret,expiration); |
|
161 iSession->resume(); |
|
162 } |
124 /////////////////////////////////////////////////////////////////////////////////////////////////// |
163 /////////////////////////////////////////////////////////////////////////////////////////////////// |
125 // slots for signals from FBRequest |
164 // slots for signals from FBRequest |
126 |
165 |
127 void FBLoginDialog::requestDidLoad(const QVariant& aResult) |
166 void FBLoginDialog::requestDidLoad(const QVariant& aResult) |
128 { |
167 { |
|
168 qDebug()<<"Inside FBLoginDialog::requestDidLoad"; |
129 bool conversionError = false; |
169 bool conversionError = false; |
130 QVariantHash object = aResult.toHash(); |
170 QVariantHash object = aResult.toHash(); |
131 QString sessionKey = object.value("session_key").toString(); |
171 QString sessionKey = object.value("session_key").toString(); |
132 QString sessionSecret = object.value("secret").toString(); |
172 QString sessionSecret = object.value("secret").toString(); |
133 |
173 |
141 dismissWithSuccess(true, true); |
181 dismissWithSuccess(true, true); |
142 } |
182 } |
143 |
183 |
144 void FBLoginDialog::requestFailedWithFacebookError (const FBError& aCode ) |
184 void FBLoginDialog::requestFailedWithFacebookError (const FBError& aCode ) |
145 { |
185 { |
|
186 qDebug()<<"Inside FBLoginDialog::requestFailedWithFacebookError()"; |
146 dismissWithError(aCode, true); |
187 dismissWithError(aCode, true); |
147 } |
188 } |
148 |
189 |
149 void FBLoginDialog::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode ) |
190 void FBLoginDialog::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode ) |
150 { |
191 { |
|
192 qDebug()<<"Inside FBLoginDialog::requestFailedWithNetworkError()"; |
151 dismissWithError(aCode, true); |
193 dismissWithError(aCode, true); |
152 } |
194 } |