example/FlickrAuthApp/src/loginDialog.cpp
author cgandhi
Mon, 11 Oct 2010 21:59:54 +0530
changeset 26 83d6a149c755
parent 17 106a4bfcb866
permissions -rw-r--r--
Submitting following changes - AuthApps for Last.fm and Twitter added API for checking ServiceAuthorization added for SMFCredMgrClient API added for forcefully removing credential details from SMFCredMgr Extra argument checks in SMfClient APIs APIs for service login and logout from SMFClient Redundant members removed from SmfServerSymbian DSM bug fixes Test Apps included
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     1
/**
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     2
* Copyright (c) 2010 Sasken Communication Technologies Ltd.
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     3
* All rights reserved.
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     4
* This component and the accompanying materials are made available
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     5
* under the terms of the "{License}"
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     6
* which accompanies  this distribution, and is available
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     7
* at the URL "{LicenseUrl}".
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     8
*
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
     9
* Initial Contributors:
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    10
* Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    11
*
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    12
* Contributors:
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    13
*
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    14
* Description:
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    15
* Login Dialog class of Authentication Application
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    16
*/
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    17
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    18
#include "authAppConstants.h"
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    19
#include "sessionSP.h"
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    20
#include "errorCodes.h"
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    21
#include "loginDialog.h"
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    22
#include <qdebug.h>
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    23
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    24
///////////////////////////////////////////////////////////////////////////////////////////////////
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    25
// global
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    26
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    27
static const QString kLoginURL = "http://www.flickr.com/services/auth/"; 
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    28
//static const QString kLoginURL = "http://www.flickr.com/auth-72157623913597531";
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    29
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    30
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    31
///////////////////////////////////////////////////////////////////////////////////////////////////
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    32
void FBLoginDialog::connectToGetFullToken()
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    33
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    34
	if(iGetSessionRequest == NULL ){
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    35
		
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    36
		iGetSessionRequest = FBRequest::requestWithSession(iSession);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    37
	
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    38
		connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant)));
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    39
		connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError)));
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    40
		connect(iGetSessionRequest, SIGNAL(requestFailedWithFlickrError(FBError)), this, SLOT(requestFailedWithFlickrError(FBError)));
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    41
		
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    42
	}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    43
	
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    44
	 iGetSessionRequest->callforToken();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    45
}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    46
void FBLoginDialog::connecttoGetFrob()
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    47
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    48
	qDebug()<<"Inside FBLoginDialog::connecttoGetFrob";
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    49
    iGetSessionRequest = FBRequest::requestWithSession(iSession);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    50
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    51
    connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant)));
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    52
    connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError)));
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    53
    connect(iGetSessionRequest, SIGNAL(requestFailedWithFlickrError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError)));
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    54
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    55
    Dictionary params;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    56
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    57
    iGetSessionRequest->call("flickr.auth.getFrob", params);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    58
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    59
}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    60
void FBLoginDialog::loadLoginPage()
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    61
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    62
    Dictionary getParams, postParams;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    63
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    64
    getParams["api_key"] = iSession->apiKey();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    65
    getParams["perms"] = "delete";
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    66
    getParams["frob"] = iSession->frobKey();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    67
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    68
    FBRequest* req = FBRequest::requestWithSession(iSession);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    69
    QString sig = req->generateSig(getParams);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    70
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    71
    getParams["api_sig"] = sig;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    72
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    73
    QString fullURL;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    74
    fullURL = kLoginURL /*+ "?" + "api_key=" + iSession->apiKey() + "&perms=delete&frob=" + iSession->frobKey() + "&api_sig=" + sig*/;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    75
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    76
    loadURL(fullURL,QNetworkAccessManager::GetOperation, getParams, postParams);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    77
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    78
}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    79
///////////////////////////////////////////////////////////////////////////////////////////////////
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    80
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    81
FBLoginDialog::FBLoginDialog() : FBDialog () {}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    82
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    83
FBLoginDialog::FBLoginDialog(FBSession* aSession) : FBDialog(aSession) {}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    84
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    85
///////////////////////////////////////////////////////////////////////////////////////////////////
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    86
// FBDialog
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    87
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    88
void FBLoginDialog::load()
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    89
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    90
    loadLoginPage();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    91
}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    92
///////////////////////////////////////////////////////////////////////////////////////////////////
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    93
// slots for signals from FBRequest
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    94
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    95
void FBLoginDialog::requestDidLoad(const QVariant& aResult)
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    96
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    97
	qDebug()<<"Inside FBLoginDialog::requestDidLoad";
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    98
    QVariantHash object = aResult.toHash();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
    99
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   100
    QString frob = object.value("frob").toString();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   101
    if(frob.length()){
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   102
    	iSession->SaveFrobKey(frob);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   103
    	show();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   104
    }
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   105
    qDebug()<<"frob = "<<frob;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   106
    qDebug() << "Root Object key : " << object.keys().takeFirst() << endl;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   107
    
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   108
    if(object.keys().takeFirst().compare("auth") == 0)
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   109
    {
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   110
    	
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   111
		QVariantHash childobject = object.value("auth").toHash();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   112
		qDebug() << "Child Object data : " << childobject << endl;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   113
		QString token = childobject.value("token").toString();
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   114
		qDebug() << "Read Token value : " << token << endl;
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   115
		if(token.length()){
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   116
			iSession->Savetoken(token);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   117
		}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   118
  	
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   119
    }
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   120
}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   121
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   122
void FBLoginDialog::requestFailedWithFlickrError (const FBError& aCode )
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   123
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   124
    dismissWithError(aCode);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   125
}
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   126
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   127
void FBLoginDialog::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode )
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   128
{
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   129
    dismissWithError(aCode);
106a4bfcb866 pushing the flickr auth app and gallery plugins
cgandhi
parents:
diff changeset
   130
}