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";
"Log out" = "Log out";
"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,18 @@ 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 let retryInterval : TimeInterval = 30
private var retries : Int = 0
private let numberOfRetries : Int = 3
private let busySectionMessageLabel : UILabel = UILabel()

init(loginViewController theLoginViewController: StaticLoginViewController, profile theProfile: StaticLoginProfile) {
profile = theProfile
Expand Down Expand Up @@ -157,39 +163,53 @@ 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)
let containerView : FullWidthHeaderView = FullWidthHeaderView()
let centerView : UIView = UIView()
let messageLabel : UILabel = UILabel()

containerView.translatesAutoresizingMaskIntoConstraints = false
centerView.translatesAutoresizingMaskIntoConstraints = false
messageLabel.translatesAutoresizingMaskIntoConstraints = false
busySectionMessageLabel.translatesAutoresizingMaskIntoConstraints = false
activityIndicator.translatesAutoresizingMaskIntoConstraints = false

centerView.addSubview(activityIndicator)
centerView.addSubview(messageLabel)
centerView.addSubview(busySectionMessageLabel)

containerView.addSubview(centerView)

containerView.addThemeApplier({ (_, collection, _) in
messageLabel.applyThemeCollection(collection, itemStyle: .welcomeMessage)
self.busySectionMessageLabel.applyThemeCollection(collection, itemStyle: .welcomeMessage)
})

messageLabel.text = message
busySectionMessageLabel.text = message

NSLayoutConstraint.activate([
activityIndicator.widthAnchor.constraint(equalToConstant: 30),
Expand All @@ -198,9 +218,9 @@ class StaticLoginSetupViewController : StaticLoginStepViewController {
activityIndicator.topAnchor.constraint(equalTo: centerView.topAnchor),
activityIndicator.bottomAnchor.constraint(equalTo: centerView.bottomAnchor),

messageLabel.centerYAnchor.constraint(equalTo: centerView.centerYAnchor),
messageLabel.leftAnchor.constraint(equalTo: activityIndicator.rightAnchor, constant: 20),
messageLabel.rightAnchor.constraint(equalTo: centerView.rightAnchor),
busySectionMessageLabel.centerYAnchor.constraint(equalTo: centerView.centerYAnchor),
busySectionMessageLabel.leftAnchor.constraint(equalTo: activityIndicator.rightAnchor, constant: 20),
busySectionMessageLabel.rightAnchor.constraint(equalTo: centerView.rightAnchor),

centerView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 40),
centerView.centerXAnchor.constraint(equalTo: containerView.centerXAnchor),
Expand Down Expand Up @@ -285,7 +305,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 +321,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 +464,39 @@ 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) || self.retries <= self.numberOfRetries), issue.error?.isNetworkConnectionError == true {
self.retries += 1
proceed = false
OnMainThread {
if isInitialRequest {
self.determineSupportedAuthMethod(false)
}
self.busySectionMessageLabel.text = String(format: "%@ (%ld)", "Contacting server…".localized, self.retries)
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 +576,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, issue.error?.isNetworkConnectionError == true {
self.addSection(retrySection)
}

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