1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 22:26:32 +02:00

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.

This commit is contained in:
Jeff Mitchell
2011-05-19 18:08:29 -04:00
parent 8c29aeecfe
commit bf765dfc2e
3 changed files with 38 additions and 33 deletions

View File

@@ -458,7 +458,6 @@ LastFmPlugin::onAuthenticated()
{ {
qDebug() << "Error from authenticating with Last.fm service:" << lfm.text(); qDebug() << "Error from authenticating with Last.fm service:" << lfm.text();
TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() ); TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() );
} }
else else
{ {

View File

@@ -61,7 +61,6 @@ SettingsDialog::SettingsDialog( QWidget *parent )
, ui( new Ui_StackedSettingsDialog ) , ui( new Ui_StackedSettingsDialog )
, m_proxySettings( this ) , m_proxySettings( this )
, m_rejected( false ) , m_rejected( false )
, m_testLastFmQuery( 0 )
, m_sipModel( 0 ) , m_sipModel( 0 )
, m_resolversModel( 0 ) , m_resolversModel( 0 )
{ {
@@ -334,16 +333,16 @@ SettingsDialog::testLastFmLogin()
ui->pushButtonTestLastfmLogin->setEnabled( false ); ui->pushButtonTestLastfmLogin->setEnabled( false );
ui->pushButtonTestLastfmLogin->setText( "Testing..." ); 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 // now authenticate w/ last.fm and get our session key
QMap<QString, QString> query; QMap<QString, QString> query;
query[ "method" ] = "auth.getMobileSession"; query[ "method" ] = "auth.getMobileSession";
query[ "username" ] = ui->lineEditLastfmUsername->text(); query[ "username" ] = ui->lineEditLastfmUsername->text().toLower();
query[ "authToken" ] = authToken; 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 #endif
} }
@@ -352,12 +351,16 @@ void
SettingsDialog::onLastFmFinished() SettingsDialog::onLastFmFinished()
{ {
#ifdef LIBLASTFM_FOUND #ifdef LIBLASTFM_FOUND
lastfm::XmlQuery lfm = lastfm::XmlQuery( m_testLastFmQuery->readAll() ); QNetworkReply* authJob = dynamic_cast<QNetworkReply*>( sender() );
if( !authJob )
switch( m_testLastFmQuery->error() )
{ {
case QNetworkReply::NoError: qDebug() << Q_FUNC_INFO << "No auth job returned!";
qDebug() << "NoError in getting lastfm auth check result"; return;
}
if( authJob->error() == QNetworkReply::NoError )
{
lastfm::XmlQuery lfm = lastfm::XmlQuery( authJob->readAll() );
if( lfm.children( "error" ).size() > 0 ) if( lfm.children( "error" ).size() > 0 )
{ {
qDebug() << "ERROR from last.fm:" << lfm.text(); qDebug() << "ERROR from last.fm:" << lfm.text();
@@ -369,8 +372,11 @@ SettingsDialog::onLastFmFinished()
ui->pushButtonTestLastfmLogin->setText( tr( "Success" ) ); ui->pushButtonTestLastfmLogin->setText( tr( "Success" ) );
ui->pushButtonTestLastfmLogin->setEnabled( false ); ui->pushButtonTestLastfmLogin->setEnabled( false );
} }
break; }
else
{
switch( authJob->error() )
{
case QNetworkReply::ContentOperationNotPermittedError: case QNetworkReply::ContentOperationNotPermittedError:
case QNetworkReply::AuthenticationRequiredError: case QNetworkReply::AuthenticationRequiredError:
ui->pushButtonTestLastfmLogin->setText( tr( "Failed" ) ); ui->pushButtonTestLastfmLogin->setText( tr( "Failed" ) );
@@ -383,6 +389,7 @@ SettingsDialog::onLastFmFinished()
ui->pushButtonTestLastfmLogin->setEnabled( true ); ui->pushButtonTestLastfmLogin->setEnabled( true );
return; return;
} }
}
#endif #endif
} }

View File

@@ -101,7 +101,6 @@ private:
ProxyDialog m_proxySettings; ProxyDialog m_proxySettings;
bool m_rejected; bool m_rejected;
QNetworkReply* m_testLastFmQuery;
SipModel* m_sipModel; SipModel* m_sipModel;
ResolversModel* m_resolversModel; ResolversModel* m_resolversModel;
}; };