|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "{License}" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "{LicenseUrl}". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Login Dialog class of Authentication Application |
|
16 */ |
|
17 |
|
18 #include "authAppConstants.h" |
|
19 #include "sessionSP.h" |
|
20 #include "errorCodes.h" |
|
21 #include "loginDialog.h" |
|
22 |
|
23 |
|
24 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 // global |
|
26 |
|
27 static const QString kLoginURL = "http://www.facebook.com/login.php"; |
|
28 |
|
29 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
30 void FBLoginDialog::connectToGetSession(const QString& aToken) |
|
31 { |
|
32 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
|
33 |
|
34 connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
|
35 connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
|
36 connect(iGetSessionRequest, SIGNAL(requestFailedWithFacebookError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError))); |
|
37 |
|
38 Dictionary params; |
|
39 params["auth_token"] = aToken; |
|
40 |
|
41 if (iSession->apiSecret().length()) |
|
42 { |
|
43 params["generate_session_secret"]="1"; |
|
44 } |
|
45 |
|
46 if (iSession->getSessionProxy().length()) |
|
47 { |
|
48 iGetSessionRequest->post(iSession->getSessionProxy(),params); |
|
49 } |
|
50 else |
|
51 { |
|
52 iGetSessionRequest->call("facebook.auth.getSession", params); |
|
53 } |
|
54 } |
|
55 |
|
56 void FBLoginDialog::loadLoginPage() |
|
57 { |
|
58 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(); |
|
69 getParams["next"] = KSuccessurl; |
|
70 getParams["cancel_url"] = "http://www.facebook.com/connect/login_failure.html"; |
|
71 getParams["req_perms"] = "read_stream,publish_stream,offline_access"; |
|
72 |
|
73 loadURL(kLoginURL,QNetworkAccessManager::GetOperation, getParams, postParams); |
|
74 |
|
75 } |
|
76 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
78 FBLoginDialog::FBLoginDialog() : FBDialog () {} |
|
79 |
|
80 FBLoginDialog::FBLoginDialog(FBSession* aSession) : FBDialog(aSession) {} |
|
81 |
|
82 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 // FBDialog |
|
84 |
|
85 void FBLoginDialog::load() |
|
86 { |
|
87 loadLoginPage(); |
|
88 } |
|
89 |
|
90 void FBLoginDialog::dialogWillDisappear() |
|
91 { |
|
92 iGetSessionRequest->cancel(); |
|
93 |
|
94 if (!iSession->isConnected()) |
|
95 { |
|
96 iSession->cancelLogin(); |
|
97 } |
|
98 } |
|
99 |
|
100 void FBLoginDialog::GetSessionKey(const QUrl& aUrl) |
|
101 { |
|
102 const QString authToken = "auth_token="; |
|
103 const QString url ( aUrl.toString() ); |
|
104 |
|
105 int start = url.indexOf(authToken); |
|
106 if (start != -1) |
|
107 { |
|
108 QString token; |
|
109 int end = url.indexOf("&", start); |
|
110 int delta = start + authToken.size() + 1; |
|
111 if (end != -1) |
|
112 { |
|
113 token = url.mid(delta, end - delta ); |
|
114 } |
|
115 else |
|
116 { |
|
117 token = url.right(url.size() - delta + 1); |
|
118 } |
|
119 |
|
120 connectToGetSession(token); |
|
121 } |
|
122 } |
|
123 |
|
124 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 // slots for signals from FBRequest |
|
126 |
|
127 void FBLoginDialog::requestDidLoad(const QVariant& aResult) |
|
128 { |
|
129 bool conversionError = false; |
|
130 QVariantHash object = aResult.toHash(); |
|
131 QString sessionKey = object.value("session_key").toString(); |
|
132 QString sessionSecret = object.value("secret").toString(); |
|
133 |
|
134 QVariant ex = object.value("expires"); |
|
135 uint expires = object.value("expires").toUInt(&conversionError); |
|
136 QDateTime expiration; expiration.setTime_t( expires ); |
|
137 |
|
138 iSession->beginSession(sessionKey, sessionSecret,expiration); |
|
139 iSession->resume(); |
|
140 |
|
141 dismissWithSuccess(true, true); |
|
142 } |
|
143 |
|
144 void FBLoginDialog::requestFailedWithFacebookError (const FBError& aCode ) |
|
145 { |
|
146 dismissWithError(aCode, true); |
|
147 } |
|
148 |
|
149 void FBLoginDialog::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode ) |
|
150 { |
|
151 dismissWithError(aCode, true); |
|
152 } |