mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 07:07:05 +02:00
Use 401 to indicate OTP needed, much better than string parsing
This commit is contained in:
@@ -276,18 +276,25 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
|
|||||||
{
|
{
|
||||||
Q_ASSERT( reply );
|
Q_ASSERT( reply );
|
||||||
bool ok;
|
bool ok;
|
||||||
|
int statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
tLog() << Q_FUNC_INFO << "Error finding status code from auth server";
|
||||||
|
emit authError( "An error occurred getting the status code from the server", 0 );
|
||||||
|
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 server");
|
emit authError( "An error occurred reading the reply from the server", statusCode );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !resp.value( "error" ).toString().isEmpty() )
|
if ( !resp.value( "error" ).toString().isEmpty() )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
||||||
emit authError( resp.value( "error" ).toString() );
|
emit authError( resp.value( "error" ).toString(), statusCode );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +302,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." );
|
emit authError( "The nonce value was incorrect. YOUR ACCOUNT MAY BE COMPROMISED.", statusCode );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,12 +331,19 @@ HatchetAccount::onFetchAccessTokensFinished()
|
|||||||
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
||||||
Q_ASSERT( reply );
|
Q_ASSERT( reply );
|
||||||
bool ok;
|
bool ok;
|
||||||
|
int statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute ).toInt( &ok );
|
||||||
|
if ( !ok )
|
||||||
|
{
|
||||||
|
tLog() << Q_FUNC_INFO << "Error finding status code from auth server";
|
||||||
|
emit authError( "An error occurred getting the status code from the server", 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
const QVariantMap resp = parseReply( reply, ok );
|
const QVariantMap resp = parseReply( reply, ok );
|
||||||
if ( !ok || !resp.value( "error" ).toString().isEmpty() )
|
if ( !ok || !resp.value( "error" ).toString().isEmpty() )
|
||||||
{
|
{
|
||||||
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
||||||
if ( ok )
|
if ( ok )
|
||||||
emit authError( resp.value( "error" ).toString() );
|
emit authError( resp.value( "error" ).toString(), statusCode );
|
||||||
deauthenticate();
|
deauthenticate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -94,7 +94,7 @@ public:
|
|||||||
QString authUrlForService( const Service& service ) const;
|
QString authUrlForService( const Service& service ) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void authError( QString error );
|
void authError( QString error, int statusCode );
|
||||||
void deauthenticated();
|
void deauthenticated();
|
||||||
void accessTokensFetched();
|
void accessTokensFetched();
|
||||||
|
|
||||||
|
@@ -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 ) ), this, SLOT( authError( QString ) ) );
|
connect( m_account, SIGNAL( authError( QString, int ) ), this, SLOT( authError( QString, int ) ) );
|
||||||
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 )
|
HatchetAccountConfig::authError( const QString &error, int statusCode )
|
||||||
{
|
{
|
||||||
if ( error.startsWith( "At least one OTP method is configured on this account" ) )
|
if ( statusCode == 401 )
|
||||||
{
|
{
|
||||||
m_ui->usernameLabel->hide();
|
m_ui->usernameLabel->hide();
|
||||||
m_ui->usernameEdit->hide();
|
m_ui->usernameEdit->hide();
|
||||||
|
@@ -52,7 +52,7 @@ private slots:
|
|||||||
|
|
||||||
void accountInfoUpdated();
|
void accountInfoUpdated();
|
||||||
|
|
||||||
void authError( const QString& error );
|
void authError( const QString& error, int statusCode );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//virtual void changeEvent( QEvent* event );
|
//virtual void changeEvent( QEvent* event );
|
||||||
|
Reference in New Issue
Block a user