From bf765dfc2e58e97628a5173e204042fdb8b3d9b9 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 19 May 2011 18:08:29 -0400 Subject: [PATCH] Possibly fix jherskowitz's problem testing authentication for last.fm. It seems that the info plugin was using toLower() to sanitize user names but the config dialog wasn't. Also some code cleanup/sync. --- .../infosystem/infoplugins/lastfmplugin.cpp | 1 - src/settingsdialog.cpp | 69 ++++++++++--------- src/settingsdialog.h | 1 - 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/libtomahawk/infosystem/infoplugins/lastfmplugin.cpp b/src/libtomahawk/infosystem/infoplugins/lastfmplugin.cpp index a373c4889..92dbfaafa 100644 --- a/src/libtomahawk/infosystem/infoplugins/lastfmplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/lastfmplugin.cpp @@ -458,7 +458,6 @@ LastFmPlugin::onAuthenticated() { qDebug() << "Error from authenticating with Last.fm service:" << lfm.text(); TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() ); - } else { diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index eae96e5e7..0d8310518 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -61,7 +61,6 @@ SettingsDialog::SettingsDialog( QWidget *parent ) , ui( new Ui_StackedSettingsDialog ) , m_proxySettings( this ) , m_rejected( false ) - , m_testLastFmQuery( 0 ) , m_sipModel( 0 ) , m_resolversModel( 0 ) { @@ -334,16 +333,16 @@ SettingsDialog::testLastFmLogin() ui->pushButtonTestLastfmLogin->setEnabled( false ); ui->pushButtonTestLastfmLogin->setText( "Testing..." ); - QString authToken = md5( ( ui->lineEditLastfmUsername->text() + md5( ui->lineEditLastfmPassword->text().toUtf8() ) ).toUtf8() ); + QString authToken = md5( ( ui->lineEditLastfmUsername->text().toLower() + md5( ui->lineEditLastfmPassword->text().toUtf8() ) ).toUtf8() ); // now authenticate w/ last.fm and get our session key QMap query; query[ "method" ] = "auth.getMobileSession"; - query[ "username" ] = ui->lineEditLastfmUsername->text(); + query[ "username" ] = ui->lineEditLastfmUsername->text().toLower(); query[ "authToken" ] = authToken; - m_testLastFmQuery = lastfm::ws::post( query ); + QNetworkReply* authJob = lastfm::ws::post( query ); - connect( m_testLastFmQuery, SIGNAL( finished() ), SLOT( onLastFmFinished() ) ); + connect( authJob, SIGNAL( finished() ), SLOT( onLastFmFinished() ) ); #endif } @@ -352,36 +351,44 @@ void SettingsDialog::onLastFmFinished() { #ifdef LIBLASTFM_FOUND - lastfm::XmlQuery lfm = lastfm::XmlQuery( m_testLastFmQuery->readAll() ); - - switch( m_testLastFmQuery->error() ) + QNetworkReply* authJob = dynamic_cast( sender() ); + if( !authJob ) { - case QNetworkReply::NoError: - qDebug() << "NoError in getting lastfm auth check result"; - if( lfm.children( "error" ).size() > 0 ) - { - qDebug() << "ERROR from last.fm:" << lfm.text(); - ui->pushButtonTestLastfmLogin->setText( tr( "Failed" ) ); - ui->pushButtonTestLastfmLogin->setEnabled( true ); - } - else - { - ui->pushButtonTestLastfmLogin->setText( tr( "Success" ) ); - ui->pushButtonTestLastfmLogin->setEnabled( false ); - } - break; + qDebug() << Q_FUNC_INFO << "No auth job returned!"; + return; + } + if( authJob->error() == QNetworkReply::NoError ) + { + lastfm::XmlQuery lfm = lastfm::XmlQuery( authJob->readAll() ); - case QNetworkReply::ContentOperationNotPermittedError: - case QNetworkReply::AuthenticationRequiredError: + if( lfm.children( "error" ).size() > 0 ) + { + qDebug() << "ERROR from last.fm:" << lfm.text(); ui->pushButtonTestLastfmLogin->setText( tr( "Failed" ) ); ui->pushButtonTestLastfmLogin->setEnabled( true ); - break; - - default: - qDebug() << "Couldn't get last.fm auth result"; - ui->pushButtonTestLastfmLogin->setText( tr( "Could not contact server" ) ); - ui->pushButtonTestLastfmLogin->setEnabled( true ); - return; + } + else + { + ui->pushButtonTestLastfmLogin->setText( tr( "Success" ) ); + ui->pushButtonTestLastfmLogin->setEnabled( false ); + } + } + else + { + switch( authJob->error() ) + { + case QNetworkReply::ContentOperationNotPermittedError: + case QNetworkReply::AuthenticationRequiredError: + ui->pushButtonTestLastfmLogin->setText( tr( "Failed" ) ); + ui->pushButtonTestLastfmLogin->setEnabled( true ); + break; + + default: + qDebug() << "Couldn't get last.fm auth result"; + ui->pushButtonTestLastfmLogin->setText( tr( "Could not contact server" ) ); + ui->pushButtonTestLastfmLogin->setEnabled( true ); + return; + } } #endif } diff --git a/src/settingsdialog.h b/src/settingsdialog.h index f6269daa9..8d0d20259 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -101,7 +101,6 @@ private: ProxyDialog m_proxySettings; bool m_rejected; - QNetworkReply* m_testLastFmQuery; SipModel* m_sipModel; ResolversModel* m_resolversModel; };