|
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 #include <qdebug.h> |
|
23 |
|
24 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 // global |
|
26 |
|
27 static const QString kLoginURL = "http://www.flickr.com/services/auth/"; |
|
28 //static const QString kLoginURL = "http://www.flickr.com/auth-72157623913597531"; |
|
29 |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 void FBLoginDialog::connectToGetFullToken() |
|
33 { |
|
34 if(iGetSessionRequest == NULL ){ |
|
35 |
|
36 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
|
37 |
|
38 connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
|
39 connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
|
40 connect(iGetSessionRequest, SIGNAL(requestFailedWithFlickrError(FBError)), this, SLOT(requestFailedWithFlickrError(FBError))); |
|
41 |
|
42 } |
|
43 |
|
44 iGetSessionRequest->callforToken(); |
|
45 } |
|
46 void FBLoginDialog::connecttoGetFrob() |
|
47 { |
|
48 qDebug()<<"Inside FBLoginDialog::connecttoGetFrob"; |
|
49 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
|
50 |
|
51 connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
|
52 connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
|
53 connect(iGetSessionRequest, SIGNAL(requestFailedWithFlickrError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError))); |
|
54 |
|
55 Dictionary params; |
|
56 |
|
57 iGetSessionRequest->call("flickr.auth.getFrob", params); |
|
58 |
|
59 } |
|
60 void FBLoginDialog::loadLoginPage() |
|
61 { |
|
62 Dictionary getParams, postParams; |
|
63 |
|
64 getParams["api_key"] = iSession->apiKey(); |
|
65 getParams["perms"] = "delete"; |
|
66 getParams["frob"] = iSession->frobKey(); |
|
67 |
|
68 FBRequest* req = FBRequest::requestWithSession(iSession); |
|
69 QString sig = req->generateSig(getParams); |
|
70 |
|
71 getParams["api_sig"] = sig; |
|
72 |
|
73 QString fullURL; |
|
74 fullURL = kLoginURL /*+ "?" + "api_key=" + iSession->apiKey() + "&perms=delete&frob=" + iSession->frobKey() + "&api_sig=" + sig*/; |
|
75 |
|
76 loadURL(fullURL,QNetworkAccessManager::GetOperation, getParams, postParams); |
|
77 |
|
78 } |
|
79 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
|
81 FBLoginDialog::FBLoginDialog() : FBDialog () {} |
|
82 |
|
83 FBLoginDialog::FBLoginDialog(FBSession* aSession) : FBDialog(aSession) {} |
|
84 |
|
85 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 // FBDialog |
|
87 |
|
88 void FBLoginDialog::load() |
|
89 { |
|
90 loadLoginPage(); |
|
91 } |
|
92 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 // slots for signals from FBRequest |
|
94 |
|
95 void FBLoginDialog::requestDidLoad(const QVariant& aResult) |
|
96 { |
|
97 qDebug()<<"Inside FBLoginDialog::requestDidLoad"; |
|
98 bool conversionError = false; |
|
99 QVariantHash object = aResult.toHash(); |
|
100 |
|
101 QString frob = object.value("frob").toString(); |
|
102 if(frob.length()){ |
|
103 iSession->SaveFrobKey(frob); |
|
104 show(); |
|
105 } |
|
106 qDebug()<<"frob = "<<frob; |
|
107 qDebug() << "Root Object key : " << object.keys().takeFirst() << endl; |
|
108 |
|
109 if(object.keys().takeFirst().compare("auth") == 0) |
|
110 { |
|
111 |
|
112 QVariantHash childobject = object.value("auth").toHash(); |
|
113 qDebug() << "Child Object data : " << childobject << endl; |
|
114 QString token = childobject.value("token").toString(); |
|
115 qDebug() << "Read Token value : " << token << endl; |
|
116 if(token.length()){ |
|
117 iSession->Savetoken(token); |
|
118 } |
|
119 |
|
120 } |
|
121 } |
|
122 |
|
123 void FBLoginDialog::requestFailedWithFlickrError (const FBError& aCode ) |
|
124 { |
|
125 dismissWithError(aCode); |
|
126 } |
|
127 |
|
128 void FBLoginDialog::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode ) |
|
129 { |
|
130 dismissWithError(aCode); |
|
131 } |