1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-07 19:13:21 +08:00

Fix APIAccess spamming requests while waiting for second factor

This commit is contained in:
Bartłomiej Dach 2024-01-29 09:13:44 +01:00
parent 363fd1d54f
commit 96811a8874
No known key found for this signature in database

View File

@ -269,42 +269,44 @@ namespace osu.Game.Online.API
} }
} }
var userReq = new GetMeRequest(); if (state.Value != APIState.RequiresSecondFactorAuth)
userReq.Failure += ex =>
{ {
if (ex is APIException) var userReq = new GetMeRequest();
userReq.Failure += ex =>
{ {
LastLoginError = ex; if (ex is APIException)
log.Add($@"Login failed for username {ProvidedUsername} on user retrieval ({LastLoginError.Message})!"); {
Logout(); LastLoginError = ex;
} log.Add($@"Login failed for username {ProvidedUsername} on user retrieval ({LastLoginError.Message})!");
else if (ex is WebException webException && webException.Message == @"Unauthorized") Logout();
}
else if (ex is WebException webException && webException.Message == @"Unauthorized")
{
log.Add(@"Login no longer valid");
Logout();
}
else
{
state.Value = APIState.Failing;
}
};
userReq.Success += me =>
{ {
log.Add(@"Login no longer valid"); me.Status.Value = configStatus.Value ?? UserStatus.Online;
Logout();
} setLocalUser(me);
else
state.Value = me.SessionVerified ? APIState.Online : APIState.RequiresSecondFactorAuth;
failureCount = 0;
};
if (!handleRequest(userReq))
{ {
state.Value = APIState.Failing; state.Value = APIState.Failing;
return;
} }
};
userReq.Success += me =>
{
me.Status.Value = configStatus.Value ?? UserStatus.Online;
setLocalUser(me);
state.Value = me.SessionVerified ? APIState.Online : APIState.RequiresSecondFactorAuth;
failureCount = 0;
};
if (!handleRequest(userReq))
{
state.Value = APIState.Failing;
return;
} }
else
if (state.Value == APIState.RequiresSecondFactorAuth)
{ {
if (string.IsNullOrEmpty(SecondFactorCode)) if (string.IsNullOrEmpty(SecondFactorCode))
return; return;