Don't allow duplicate Feedly Accounts. Issue #2448

This commit is contained in:
Maurice Parker 2020-09-24 18:02:33 -05:00
parent 59d427d626
commit cc7e89215c
1 changed files with 12 additions and 1 deletions

View File

@ -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 {