Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/branding-login-retry] Retry Section for Branded Login Error #1047

Merged
merged 10 commits into from
Nov 12, 2021
1 change: 1 addition & 0 deletions ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"Manage Storage" = "Manage Storage";
"Access Files" = "Access Files";
"Logout" = "Logout";
"Retry" = "Retry";

/* Bookmark Info */
"Bookmark Metadata" = "Bookmark Metadata";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
var profile : StaticLoginProfile
var bookmark : OCBookmark?
var busySection : StaticTableViewSection?
var retrySection : StaticTableViewSection?

private var urlString : String?
private var username : String?
private var password : String?
private var passwordRow : StaticTableViewRow?
private var isAuthenticating = false
private var retryTimeout : Date?
private var retryInterval : TimeInterval = 10

init(loginViewController theLoginViewController: StaticLoginViewController, profile theProfile: StaticLoginProfile) {
profile = theProfile
Expand Down Expand Up @@ -157,17 +160,32 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
tokenMaskSection.addStaticHeader(title: profile.welcome!, message: profile.promptForTokenAuth)

if VendorServices.shared.canAddAccount, OCBookmarkManager.shared.bookmarks.count > 0 {
let (proceedButton, cancelButton) = tokenMaskSection.addButtonFooter(proceedLabel: "Continue", cancelLabel: "Cancel")
let (proceedButton, cancelButton) = tokenMaskSection.addButtonFooter(proceedLabel: "Continue".localized, cancelLabel: "Cancel".localized)
proceedButton?.addTarget(self, action: #selector(self.startAuthentication), for: .touchUpInside)
cancelButton?.addTarget(self, action: #selector(self.cancel(_:)), for: .touchUpInside)
} else {
let (proceedButton, _) = tokenMaskSection.addButtonFooter(proceedLabel: "Continue", proceedItemStyle: .welcome, cancelLabel: nil)
let (proceedButton, _) = tokenMaskSection.addButtonFooter(proceedLabel: "Continue".localized, proceedItemStyle: .welcome, cancelLabel: nil)
proceedButton?.addTarget(self, action: #selector(self.startAuthentication), for: .touchUpInside)
}

return tokenMaskSection
}

func retrySection(issues: DisplayIssues) -> StaticTableViewSection {
let retrySection : StaticTableViewSection = StaticTableViewSection(headerTitle: nil, identifier: "retrySection")

for issue in issues.displayIssues {
if let title = issue.localizedTitle, let localizedDescription = issue.localizedDescription {
retrySection.add(row: StaticTableViewRow(message: localizedDescription, title: title))
}
}

let (proceedButton, _) = retrySection.addButtonFooter(proceedLabel: "Retry".localized, proceedItemStyle: .welcome, cancelLabel: nil)
proceedButton?.addTarget(self, action: #selector(proceedWithLogin), for: .touchUpInside)

return retrySection
}

func busySection(message: String) -> StaticTableViewSection {
let busySection : StaticTableViewSection = StaticTableViewSection(headerTitle: nil, identifier: "busySection")
let activityIndicator : UIActivityIndicatorView = UIActivityIndicatorView(style: Theme.shared.activeCollection.activityIndicatorViewStyle)
Expand Down Expand Up @@ -285,7 +303,7 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
}
}

func proceedWithLogin() {
@objc func proceedWithLogin() {
guard self.bookmark != nil else {
let alertController = ThemedAlertController(title: "Missing Profile URL".localized, message: String(format: "The Profile '%@' does not have a URL configured.\nPlease provide a URL via configuration or MDM.".localized, profile.name ?? ""), preferredStyle: .alert)

Expand All @@ -301,6 +319,9 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
if let onboardingSection = self.sectionForIdentifier("onboardingSection") {
self.removeSection(onboardingSection)
}
if let retrySection = self.sectionForIdentifier("retrySection") {
self.removeSection(retrySection)
}

if busySection == nil {
busySection = self.busySection(message: "Contacting server…".localized)
Expand Down Expand Up @@ -441,27 +462,37 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
var proceed : Bool = true

if let issue = connectionIssue {
proceed = self.show(issue: issue, proceed: { () in
if self.retryTimeout == nil {
self.retryTimeout = Date().addingTimeInterval(self.retryInterval)
}
if let retryDate = self.retryTimeout, Date() < retryDate {
hosy marked this conversation as resolved.
Show resolved Hide resolved
proceed = false
OnMainThread {
if isInitialRequest {
self.determineSupportedAuthMethod(false)
}
self.determineSupportedAuthMethod(false)
}
}, cancel: { () in
OnMainThread {
if self.profile.canConfigureURL {
if let busySection = self.busySection, busySection.attached {
self.removeSection(busySection)
} else {
proceed = self.show(issue: issue, proceed: { () in
OnMainThread {
if isInitialRequest {
self.determineSupportedAuthMethod(false)
}
self.addSection(self.urlSection())
if OCBookmarkManager.shared.bookmarks.count == 0, self.profile.isOnboardingEnabled, self.sectionForIdentifier("onboardingSection") == nil {
self.addSection(self.onboardingSection())
}
}, cancel: { () in
OnMainThread {
if self.profile.canConfigureURL {
if let busySection = self.busySection, busySection.attached {
self.removeSection(busySection)
}
self.addSection(self.urlSection())
if OCBookmarkManager.shared.bookmarks.count == 0, self.profile.isOnboardingEnabled, self.sectionForIdentifier("onboardingSection") == nil {
self.addSection(self.onboardingSection())
}
} else {
self.cancel(nil)
}
} else {
self.cancel(nil)
}
}
})
})
}
}

if proceed {
Expand Down Expand Up @@ -541,6 +572,10 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
if let busySection = self.busySection, busySection.attached {
self.removeSection(busySection)
}
self.retrySection = self.retrySection(issues: displayIssues)
if let retrySection = self.retrySection {
self.addSection(retrySection)
}

IssuesCardViewController.present(on: loginViewController, issue: issue, displayIssues: displayIssues, completion: { [weak issue] (response) in
switch response {
Expand Down