1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 07:07:05 +02:00

Not all 401s are OTP needed

This commit is contained in:
Jeff Mitchell
2013-09-06 16:06:10 -04:00
parent 11681c5b35
commit f3b7fc6cae
4 changed files with 14 additions and 14 deletions

View File

@@ -280,27 +280,27 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
if ( !ok ) if ( !ok )
{ {
tLog() << Q_FUNC_INFO << "Error finding status code from auth server"; tLog() << Q_FUNC_INFO << "Error finding status code from auth server";
emit authError( "An error occurred getting the status code from the server", 0 ); emit authError( "An error occurred getting the status code from the server", 0, QVariantMap() );
return; return;
} }
const QVariantMap resp = parseReply( reply, ok ); const QVariantMap resp = parseReply( reply, ok );
if ( !ok ) if ( !ok )
{ {
tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server"; tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server";
emit authError( "An error occurred reading the reply from the authentication server", statusCode ); emit authError( "An error occurred reading the reply from the authentication server", statusCode, resp );
return; return;
} }
if ( statusCode >= 500 ) if ( statusCode >= 500 )
{ {
tLog() << Q_FUNC_INFO << "Encountered internal error from auth server, cannot continue"; tLog() << Q_FUNC_INFO << "Encountered internal error from auth server, cannot continue";
emit authError( "The authentication server reported an internal error, please try again later", statusCode ); emit authError( "The authentication server reported an internal error, please try again later", statusCode, resp );
return; return;
} }
if ( statusCode >= 400 ) if ( statusCode >= 400 )
{ {
QString errString = resp.value( "result" ).toMap().value( "errorinfo" ).toMap().value( "description" ).toString(); QString errString = resp.value( "result" ).toMap().value( "errorinfo" ).toMap().value( "description" ).toString();
tLog() << Q_FUNC_INFO << "An error was returned from the authentication server: " << errString; tLog() << Q_FUNC_INFO << "An error was returned from the authentication server: " << errString;
emit authError( errString, statusCode ); emit authError( errString, statusCode, resp );
return; return;
} }
@@ -308,7 +308,7 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
if ( nonce != m_uuid ) if ( nonce != m_uuid )
{ {
tLog() << Q_FUNC_INFO << "Auth server nonce value does not match!"; tLog() << Q_FUNC_INFO << "Auth server nonce value does not match!";
emit authError( "The nonce value was incorrect. YOUR ACCOUNT MAY BE COMPROMISED.", statusCode ); emit authError( "The nonce value was incorrect. YOUR ACCOUNT MAY BE COMPROMISED.", statusCode, resp );
return; return;
} }
@@ -342,27 +342,27 @@ HatchetAccount::onFetchAccessTokensFinished()
if ( !ok ) if ( !ok )
{ {
tLog() << Q_FUNC_INFO << "Error finding status code from auth server"; tLog() << Q_FUNC_INFO << "Error finding status code from auth server";
emit authError( "An error occurred getting the status code from the server", 0 ); emit authError( "An error occurred getting the status code from the server", 0, QVariantMap() );
return; return;
} }
const QVariantMap resp = parseReply( reply, ok ); const QVariantMap resp = parseReply( reply, ok );
if ( !ok ) if ( !ok )
{ {
tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server"; tLog() << Q_FUNC_INFO << "Error getting parsed reply from auth server";
emit authError( "An error occurred reading the reply from the authentication server", statusCode ); emit authError( "An error occurred reading the reply from the authentication server", statusCode, resp );
return; return;
} }
if ( statusCode >= 500 ) if ( statusCode >= 500 )
{ {
tLog() << Q_FUNC_INFO << "Encountered internal error from auth server, cannot continue"; tLog() << Q_FUNC_INFO << "Encountered internal error from auth server, cannot continue";
emit authError( "The authentication server reported an internal error, please try again later", statusCode ); emit authError( "The authentication server reported an internal error, please try again later", statusCode, resp );
return; return;
} }
if ( statusCode >= 400 ) if ( statusCode >= 400 )
{ {
QString errString = resp.value( "result" ).toMap().value( "errorinfo" ).toMap().value( "description" ).toString(); QString errString = resp.value( "result" ).toMap().value( "errorinfo" ).toMap().value( "description" ).toString();
tLog() << Q_FUNC_INFO << "An error was returned from the authentication server: " << errString; tLog() << Q_FUNC_INFO << "An error was returned from the authentication server: " << errString;
emit authError( errString, statusCode ); emit authError( errString, statusCode, resp );
return; return;
} }

View File

@@ -96,7 +96,7 @@ public:
QString authUrlForService( const Service& service ) const; QString authUrlForService( const Service& service ) const;
signals: signals:
void authError( QString error, int statusCode ); void authError( QString error, int statusCode, const QVariantMap );
void deauthenticated(); void deauthenticated();
void accessTokensFetched(); void accessTokensFetched();

View File

@@ -54,7 +54,7 @@ HatchetAccountConfig::HatchetAccountConfig( HatchetAccount* account )
connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( fieldsChanged() ) ); connect( m_ui->passwordEdit, SIGNAL( textChanged( QString ) ), this, SLOT( fieldsChanged() ) );
connect( m_ui->otpEdit, SIGNAL( textChanged( QString ) ), this, SLOT( fieldsChanged() ) ); connect( m_ui->otpEdit, SIGNAL( textChanged( QString ) ), this, SLOT( fieldsChanged() ) );
connect( m_account, SIGNAL( authError( QString, int ) ), this, SLOT( authError( QString, int ) ) ); connect( m_account, SIGNAL( authError( QString, int, QVariantMap ) ), this, SLOT( authError( QString, int, QVariantMap ) ) );
connect( m_account, SIGNAL( deauthenticated() ), this, SLOT( showLoggedOut() ) ); connect( m_account, SIGNAL( deauthenticated() ), this, SLOT( showLoggedOut() ) );
connect( m_account, SIGNAL( accessTokensFetched() ), this, SLOT( accountInfoUpdated() ) ); connect( m_account, SIGNAL( accessTokensFetched() ), this, SLOT( accountInfoUpdated() ) );
@@ -168,9 +168,9 @@ HatchetAccountConfig::accountInfoUpdated()
void void
HatchetAccountConfig::authError( const QString &error, int statusCode ) HatchetAccountConfig::authError( const QString &error, int statusCode, const QVariantMap& resp )
{ {
if ( statusCode == 401 ) if ( statusCode == 401 && resp["result"].toMap()["errorinfo"].toMap().contains("missingotp") )
{ {
m_ui->usernameLabel->hide(); m_ui->usernameLabel->hide();
m_ui->usernameEdit->hide(); m_ui->usernameEdit->hide();

View File

@@ -52,7 +52,7 @@ private slots:
void accountInfoUpdated(); void accountInfoUpdated();
void authError( const QString& error, int statusCode ); void authError( const QString& error, int statusCode, const QVariantMap& resp );
protected: protected:
//virtual void changeEvent( QEvent* event ); //virtual void changeEvent( QEvent* event );