Check for duplicate accounts and make sure it doesn't interfere with credentials updates

This commit is contained in:
Maurice Parker 2020-10-29 14:05:55 -05:00
parent 3a1570f6c6
commit 515dd5f63f
6 changed files with 21 additions and 12 deletions

View File

@ -56,7 +56,7 @@ class AccountsFeedWranglerWindowController: NSWindowController {
return
}
guard !AccountManager.shared.duplicateServiceAccount(type: .feedWrangler, username: usernameTextField.stringValue) else {
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: .feedWrangler, username: usernameTextField.stringValue) else {
self.errorMessageLabel.stringValue = NSLocalizedString("There is already a FeedWrangler account with that username created.", comment: "Duplicate Error")
return
}

View File

@ -56,7 +56,7 @@ class AccountsNewsBlurWindowController: NSWindowController {
return
}
guard !AccountManager.shared.duplicateServiceAccount(type: .newsBlur, username: usernameTextField.stringValue) else {
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: .newsBlur, username: usernameTextField.stringValue) else {
self.errorMessageLabel.stringValue = NSLocalizedString("There is already a NewsBlur account with that username created.", comment: "Duplicate Error")
return
}

View File

@ -91,7 +91,7 @@ class AccountsReaderAPIWindowController: NSWindowController {
return
}
guard !AccountManager.shared.duplicateServiceAccount(type: accountType, username: usernameTextField.stringValue) else {
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: accountType, username: usernameTextField.stringValue) else {
self.errorMessageLabel.stringValue = NSLocalizedString("There is already an account of this type with that username created.", comment: "Duplicate Error")
return
}

View File

@ -80,7 +80,7 @@ class FeedWranglerAccountViewController: UITableViewController {
// When you fill in the email address via auto-complete it adds extra whitespace
let trimmedEmail = email.trimmingCharacters(in: .whitespaces)
guard !AccountManager.shared.duplicateServiceAccount(type: .feedWrangler, username: trimmedEmail) else {
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: .feedWrangler, username: trimmedEmail) else {
showError(NSLocalizedString("There is already a FeedWrangler account with that username created.", comment: "Duplicate Error"))
return
}

View File

@ -80,13 +80,19 @@ class NewsBlurAccountViewController: UITableViewController {
return
}
// When you fill in the email address via auto-complete it adds extra whitespace
let trimmedUsername = username.trimmingCharacters(in: .whitespaces)
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: .newsBlur, username: trimmedUsername) else {
showError(NSLocalizedString("There is already a NewsBlur account with that username created.", comment: "Duplicate Error"))
return
}
let password = passwordTextField.text ?? ""
startAnimatingActivityIndicator()
disableNavigation()
// When you fill in the email address via auto-complete it adds extra whitespace
let trimmedUsername = username.trimmingCharacters(in: .whitespaces)
let credentials = Credentials(type: .newsBlurBasic, username: trimmedUsername, secret: password)
Account.validateCredentials(type: .newsBlur, credentials: credentials) { result in

View File

@ -109,7 +109,7 @@ class ReaderAPIAccountViewController: UITableViewController {
}
@IBAction func action(_ sender: Any) {
guard validateDataEntry() else {
guard validateDataEntry(), let type = accountType else {
return
}
@ -117,15 +117,18 @@ class ReaderAPIAccountViewController: UITableViewController {
let password = passwordTextField.text!
let url = apiURL()!
// When you fill in the email address via auto-complete it adds extra whitespace
let trimmedUsername = username.trimmingCharacters(in: .whitespaces)
guard account != nil || !AccountManager.shared.duplicateServiceAccount(type: type, username: trimmedUsername) else {
showError(NSLocalizedString("There is already an account of that type with that username created.", comment: "Duplicate Error"))
return
}
startAnimatingActivityIndicator()
disableNavigation()
// When you fill in the email address via auto-complete it adds extra whitespace
let trimmedUsername = username.trimmingCharacters(in: .whitespaces)
let credentials = Credentials(type: .readerBasic, username: trimmedUsername, secret: password)
guard let type = accountType else {
return
}
Account.validateCredentials(type: type, credentials: credentials, endpoint: url) { result in
self.stopAnimatingActivityIndicator()