From fff256f361c0f5152e33eca08f16b652b4f88dd9 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 24 Sep 2020 18:02:33 -0500 Subject: [PATCH] Don't allow duplicate Feedly Accounts. Issue #2448 --- .../Feedly/OAuthAccountAuthorizationOperation.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Frameworks/Account/Feedly/OAuthAccountAuthorizationOperation.swift b/Frameworks/Account/Feedly/OAuthAccountAuthorizationOperation.swift index 1b78797da..7c72d34d1 100644 --- a/Frameworks/Account/Feedly/OAuthAccountAuthorizationOperation.swift +++ b/Frameworks/Account/Feedly/OAuthAccountAuthorizationOperation.swift @@ -15,6 +15,13 @@ public protocol OAuthAccountAuthorizationOperationDelegate: class { func oauthAccountAuthorizationOperation(_ operation: OAuthAccountAuthorizationOperation, didFailWith error: Error) } +public enum OAuthAccountAuthorizationOperationError: LocalizedError { + case duplicateAccount + + public var errorDescription: String? { + return NSLocalizedString("There is already a Feedly account with that username created.", comment: "Duplicate Error") + } +} @objc public final class OAuthAccountAuthorizationOperation: NSObject, MainThreadOperation, ASWebAuthenticationPresentationContextProviding { public var isCanceled: Bool = false { @@ -122,7 +129,11 @@ public protocol OAuthAccountAuthorizationOperationDelegate: class { } private func saveAccount(for grant: OAuthAuthorizationGrant) { - // TODO: Find an already existing account for this username? + guard !AccountManager.shared.duplicateServiceAccount(type: .feedly, username: grant.accessToken.username) else { + didFinish(OAuthAccountAuthorizationOperationError.duplicateAccount) + return + } + let account = AccountManager.shared.createAccount(type: .feedly) do {