mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +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 );
|
||||
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 );
|
||||
if ( !ok )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if ( !resp.value( "error" ).toString().isEmpty() )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
||||
emit authError( resp.value( "error" ).toString() );
|
||||
emit authError( resp.value( "error" ).toString(), statusCode );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -295,7 +302,7 @@ HatchetAccount::onPasswordLoginFinished( QNetworkReply* reply, const QString& us
|
||||
if ( nonce != m_uuid )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -324,12 +331,19 @@ HatchetAccount::onFetchAccessTokensFinished()
|
||||
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
||||
Q_ASSERT( reply );
|
||||
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 );
|
||||
if ( !ok || !resp.value( "error" ).toString().isEmpty() )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Auth server returned an error";
|
||||
if ( ok )
|
||||
emit authError( resp.value( "error" ).toString() );
|
||||
emit authError( resp.value( "error" ).toString(), statusCode );
|
||||
deauthenticate();
|
||||
return;
|
||||
}
|
||||
|
@@ -94,7 +94,7 @@ public:
|
||||
QString authUrlForService( const Service& service ) const;
|
||||
|
||||
signals:
|
||||
void authError( QString error );
|
||||
void authError( QString error, int statusCode );
|
||||
void deauthenticated();
|
||||
void accessTokensFetched();
|
||||
|
||||
|
@@ -54,7 +54,7 @@ HatchetAccountConfig::HatchetAccountConfig( HatchetAccount* account )
|
||||
connect( m_ui->passwordEdit, 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( accessTokensFetched() ), this, SLOT( accountInfoUpdated() ) );
|
||||
|
||||
@@ -168,9 +168,9 @@ HatchetAccountConfig::accountInfoUpdated()
|
||||
|
||||
|
||||
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->usernameEdit->hide();
|
||||
|
@@ -52,7 +52,7 @@ private slots:
|
||||
|
||||
void accountInfoUpdated();
|
||||
|
||||
void authError( const QString& error );
|
||||
void authError( const QString& error, int statusCode );
|
||||
|
||||
protected:
|
||||
//virtual void changeEvent( QEvent* event );
|
||||
|
Reference in New Issue
Block a user