Change server settings to use OAuth after an authentication failure

This commit is contained in:
cketti 2022-06-17 13:18:02 +02:00
parent 9a9c781eaa
commit 00e0d8b35a
2 changed files with 16 additions and 0 deletions

View file

@ -671,9 +671,21 @@ public class MessagingController {
}
public void handleAuthenticationFailure(Account account, boolean incoming) {
if (account.shouldMigrateToOAuth()) {
migrateAccountToOAuth(account);
}
notificationController.showAuthenticationErrorNotification(account, incoming);
}
private void migrateAccountToOAuth(Account account) {
account.setIncomingServerSettings(account.getIncomingServerSettings().newAuthenticationType(AuthType.XOAUTH2));
account.setOutgoingServerSettings(account.getOutgoingServerSettings().newAuthenticationType(AuthType.XOAUTH2));
account.setShouldMigrateToOAuth(false);
preferences.saveAccount(account);
}
public void handleException(Account account, Exception exception) {
if (exception instanceof AuthenticationFailedException) {
handleAuthenticationFailure(account, true);

View file

@ -26,4 +26,8 @@ data class ServerSettings @JvmOverloads constructor(
fun newPassword(newPassword: String?): ServerSettings {
return this.copy(password = newPassword)
}
fun newAuthenticationType(authType: AuthType): ServerSettings {
return this.copy(authenticationType = authType)
}
}