Skip to content

Commit

Permalink
Revert "WIP"
Browse files Browse the repository at this point in the history
This reverts commit bd92b2a.
  • Loading branch information
mpivchev committed Dec 23, 2024
1 parent ab11100 commit 5142d4a
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 244 deletions.
1 change: 0 additions & 1 deletion Brand/NCBrand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ let userAgent: String = {
var doNotAskPasscodeAtStartup: Bool = false
var disable_source_code_in_settings: Bool = false
var enforce_passcode_lock = false
var use_in_app_browser_for_login = true

// (name: "Name 1", url: "https://cloud.nextcloud.com"),(name: "Name 2", url: "https://cloud.nextcloud.com")
var enforce_servers: [(name: String, url: String)] = []
Expand Down
18 changes: 1 addition & 17 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
F314F1142A30E2DE00BC7FAB /* View+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7E8A390295DC5E0006CB2D0 /* View+Extension.swift */; };
F321DA8A2B71205A00DDA0E6 /* NCTrashSelectTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F321DA892B71205A00DDA0E6 /* NCTrashSelectTabBar.swift */; };
F32FADA92D1176E3007035E2 /* UIButton+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F32FADA82D1176DE007035E2 /* UIButton+Extension.swift */; };
F33918C42C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F33918C32C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift */; };
F33918C52C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F33918C32C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift */; };
F33918C62C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F33918C32C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift */; };
Expand Down Expand Up @@ -169,7 +168,6 @@
F3BB464D2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3BB464C2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib */; };
F3BB46522A39EC4900461F6E /* NCMoreAppSuggestionsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB46512A39EC4900461F6E /* NCMoreAppSuggestionsCell.swift */; };
F3BB46542A3A1E9D00461F6E /* CCCellMore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB46532A3A1E9D00461F6E /* CCCellMore.swift */; };
F3CA33842D10726E00672333 /* NCLoginPollModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3CA33832D10726E00672333 /* NCLoginPollModel.swift */; };
F3E173B02C9AF637006D177A /* ScreenAwakeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E173AF2C9AF637006D177A /* ScreenAwakeManager.swift */; };
F3E173C02C9B1067006D177A /* AwakeMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E173BF2C9B1067006D177A /* AwakeMode.swift */; };
F3E173C12C9B1067006D177A /* AwakeMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E173BF2C9B1067006D177A /* AwakeMode.swift */; };
Expand Down Expand Up @@ -1203,7 +1201,6 @@
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCViewerMedia+VisionKit.swift"; sourceTree = "<group>"; };
F321DA892B71205A00DDA0E6 /* NCTrashSelectTabBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCTrashSelectTabBar.swift; sourceTree = "<group>"; };
F32FADA82D1176DE007035E2 /* UIButton+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIButton+Extension.swift"; sourceTree = "<group>"; };
F33918C32C7CD8F2002D9AA1 /* FileNameValidator+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileNameValidator+Extensions.swift"; sourceTree = "<group>"; };
F33EE6F12BF4C9B200CA1A51 /* PKCS12.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCS12.swift; sourceTree = "<group>"; };
F343A4B22A1E01FF00DDA874 /* PHAsset+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PHAsset+Extension.swift"; sourceTree = "<group>"; };
Expand All @@ -1226,7 +1223,6 @@
F3BB464C2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMoreAppSuggestionsCell.xib; sourceTree = "<group>"; };
F3BB46512A39EC4900461F6E /* NCMoreAppSuggestionsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMoreAppSuggestionsCell.swift; sourceTree = "<group>"; };
F3BB46532A3A1E9D00461F6E /* CCCellMore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCCellMore.swift; sourceTree = "<group>"; };
F3CA33832D10726E00672333 /* NCLoginPollModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginPollModel.swift; sourceTree = "<group>"; };
F3E173AF2C9AF637006D177A /* ScreenAwakeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenAwakeManager.swift; sourceTree = "<group>"; };
F3E173BF2C9B1067006D177A /* AwakeMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AwakeMode.swift; sourceTree = "<group>"; };
F3EF2E0B2BFCF3810025EF46 /* NCLoginPoll.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginPoll.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2042,15 +2038,6 @@
path = Cells;
sourceTree = "<group>";
};
F3CA33802D106FF900672333 /* Poll */ = {
isa = PBXGroup;
children = (
F3EF2E0B2BFCF3810025EF46 /* NCLoginPoll.swift */,
F3CA33832D10726E00672333 /* NCLoginPollModel.swift */,
);
path = Poll;
sourceTree = "<group>";
};
F3E173BE2C9B1057006D177A /* ScreenAwakeManager */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2635,7 +2622,6 @@
F7A0D14E259229FA008F8A13 /* Extensions */ = {
isa = PBXGroup;
children = (
F32FADA82D1176DE007035E2 /* UIButton+Extension.swift */,
F7AC1CAF28AB94490032D99F /* Array+Extension.swift */,
F7817CF729801A3500FFBC65 /* Data+Extension.swift */,
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */,
Expand Down Expand Up @@ -2747,14 +2733,14 @@
F7BFFA621A24D7300044ED85 /* Login */ = {
isa = PBXGroup;
children = (
F3CA33802D106FF900672333 /* Poll */,
F702F2F025EE5CDA008F8E80 /* NCLogin.storyboard */,
F702F2F625EE5CEC008F8E80 /* NCLogin.swift */,
F738D48F2756740100CD1D38 /* NCLoginNavigationController.swift */,
F745B252222D88AE00346520 /* NCLoginQRCode.swift */,
F7AE00F4230D5F9E007ACF8A /* NCLoginProvider.swift */,
F7BC287D26663F6C004D46C5 /* NCViewCertificateDetails.storyboard */,
F7BC287F26663F85004D46C5 /* NCViewCertificateDetails.swift */,
F3EF2E0B2BFCF3810025EF46 /* NCLoginPoll.swift */,
);
path = Login;
sourceTree = "<group>";
Expand Down Expand Up @@ -4301,10 +4287,8 @@
F7AE00F8230E81CB007ACF8A /* NCBrowserWeb.swift in Sources */,
F77DD6A82C5CC093009448FB /* NCSession.swift in Sources */,
F702F30825EE5D47008F8E80 /* NCPopupViewController.swift in Sources */,
F3CA33842D10726E00672333 /* NCLoginPollModel.swift in Sources */,
F733598125C1C188002ABA72 /* NCAskAuthorization.swift in Sources */,
370D26AF248A3D7A00121797 /* NCCellProtocol.swift in Sources */,
F32FADA92D1176E3007035E2 /* UIButton+Extension.swift in Sources */,
F768822C2C0DD1E7001CF441 /* NCKeychain.swift in Sources */,
F7BFFD282C8846020029A201 /* NCHud.swift in Sources */,
F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */,
Expand Down
40 changes: 0 additions & 40 deletions iOSClient/Extensions/UIButton+Extension.swift

This file was deleted.

112 changes: 18 additions & 94 deletions iOSClient/Login/NCLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import UIKit
import NextcloudKit
import SwiftEntryKit
import SwiftUI
import SafariServices

class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
@IBOutlet weak var imageBrand: UIImageView!
Expand All @@ -47,6 +46,10 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {

private var shareAccounts: [NKShareAccounts.DataAccounts]?

var loginFlowV2Token = ""
var loginFlowV2Endpoint = ""
var loginFlowV2Login = ""

/// The URL that will show up on the URL field when this screen appears
var urlBase = ""

Expand All @@ -59,12 +62,6 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
private var p12Data: Data?
private var p12Password: String?

var pollTimer: DispatchSourceTimer?

var ncLoginPollModel = NCLoginPollModel()

var loginFlowInProgress = false

// MARK: - View Life Cycle

override func viewDidLoad() {
Expand Down Expand Up @@ -185,11 +182,11 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
enforceServersButton.menu = .init(title: NSLocalizedString("_servers_", comment: ""), children: actions)
enforceServersButton.showsMenuAsPrimaryAction = true
enforceServersButton.configuration?.titleTextAttributesTransformer =
UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 13)
return outgoing
}
UIConfigurationTextAttributesTransformer { incoming in
var outgoing = incoming
outgoing.font = UIFont.systemFont(ofSize: 13)
return outgoing
}
}
}

Expand Down Expand Up @@ -286,6 +283,7 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
}

@IBAction func actionQRCode(_ sender: Any) {

let qrCode = NCLoginQRCode(delegate: self)
qrCode.scan()
}
Expand Down Expand Up @@ -318,7 +316,6 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
guard var url = baseUrlTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) else { return }
if url.hasSuffix("/") { url = String(url.dropLast()) }
if url.isEmpty { return }

// Check whether baseUrl contain protocol. If not add https:// by default.
if url.hasPrefix("https") == false && url.hasPrefix("http") == false {
url = "https://" + url
Expand All @@ -329,41 +326,26 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {

func isUrlValid(url: String, user: String? = nil) {
loginButton.isEnabled = false
loginButton.hideButtonAndShowSpinner()

NextcloudKit.shared.getServerStatus(serverUrl: url) { [self] _, serverInfoResult in
NextcloudKit.shared.getServerStatus(serverUrl: url) { _, serverInfoResult in
switch serverInfoResult {
case .success(let serverInfo):
if let host = URL(string: url)?.host {
NCNetworking.shared.writeCertificate(host: host)
}
NextcloudKit.shared.getLoginFlowV2(serverUrl: url) { [self] token, endpoint, login, _, error in
NextcloudKit.shared.getLoginFlowV2(serverUrl: url) { token, endpoint, login, _, error in
self.loginButton.isEnabled = true
// Login Flow V2
if error == .success, let token, let endpoint, let login {
guard let url = URL(string: login) else { return }
let vc: UIViewController

poll(loginFlowV2Token: token, loginFlowV2Endpoint: endpoint, loginFlowV2Login: login)

if NCBrandOptions.shared.use_in_app_browser_for_login {
let safariVC = SFSafariViewController(url: url)
safariVC.delegate = self
vc = safariVC
} else {
vc = UIHostingController(rootView: NCLoginPoll(loginFlowV2Login: login, model: ncLoginPollModel))
}

present(vc, animated: true)
let vc = UIHostingController(rootView: NCLoginPoll(loginFlowV2Token: token, loginFlowV2Endpoint: endpoint, loginFlowV2Login: login))
self.present(vc, animated: true)
} else if serverInfo.versionMajor < NCGlobal.shared.nextcloudVersion12 { // No login flow available
let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_webflow_not_available_", comment: ""), preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
present(alertController, animated: true, completion: { })
self.present(alertController, animated: true, completion: { })
}
}
case .failure(let error):
loginButton.hideSpinnerAndShowButton()
loginButton.isEnabled = true

self.loginButton.isEnabled = true
if error.errorCode == NSURLErrorServerCertificateUntrusted {
let alertController = UIAlertController(title: NSLocalizedString("_ssl_certificate_untrusted_", comment: ""), message: NSLocalizedString("_connect_server_anyway_", comment: ""), preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { _ in
Expand Down Expand Up @@ -491,6 +473,7 @@ extension NCLogin: ClientCertificateDelegate, UIDocumentPickerDelegate {
let alertEnterPassword = UIAlertController(title: NSLocalizedString("_client_cert_enter_password_", comment: ""), message: "", preferredStyle: .alert)
alertEnterPassword.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: nil))
alertEnterPassword.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in
// let documentProviderMenu = UIDocumentPickerViewController(forOpeningContentTypes: [UTType.pkcs12])
NCNetworking.shared.p12Data = try? Data(contentsOf: urls[0])
NCNetworking.shared.p12Password = alertEnterPassword.textFields?[0].text
self.login()
Expand All @@ -508,63 +491,4 @@ extension NCLogin: ClientCertificateDelegate, UIDocumentPickerDelegate {
alertWrongPassword.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default))
present(alertWrongPassword, animated: true)
}

func poll(loginFlowV2Token: String, loginFlowV2Endpoint: String, loginFlowV2Login: String) {
let queue = DispatchQueue.global(qos: .background)
pollTimer = DispatchSource.makeTimerSource(queue: queue)

guard let timer = pollTimer else { return }

timer.schedule(deadline: .now(), repeating: .seconds(1), leeway: .seconds(1))
timer.setEventHandler(handler: {
DispatchQueue.main.async {
let controller = UIApplication.shared.firstWindow?.rootViewController as? NCMainTabBarController
NextcloudKit.shared.getLoginFlowV2Poll(token: loginFlowV2Token, endpoint: loginFlowV2Endpoint) { [self] server, loginName, appPassword, _, error in
if error == .success, let urlBase = server, let user = loginName, let appPassword {
loginFlowInProgress = true
ncLoginPollModel.isLoading = true

NCAccount().createAccount(urlBase: urlBase, user: user, password: appPassword, controller: controller) { account, error in

if error == .success {
let window = UIApplication.shared.firstWindow
if let controller = window?.rootViewController as? NCMainTabBarController {
controller.account = account
controller.dismiss(animated: true, completion: nil)
} else {
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController {
controller.account = account
controller.modalPresentationStyle = .fullScreen
controller.view.alpha = 0

window?.rootViewController = controller
window?.makeKeyAndVisible()

if let scene = window?.windowScene {
SceneManager.shared.register(scene: scene, withRootViewController: controller)
}

UIView.animate(withDuration: 0.5) {
controller.view.alpha = 1
}
}
}
}
}
}
}
}
})

timer.resume()
}
}

extension NCLogin: SFSafariViewControllerDelegate {
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
if !loginFlowInProgress {
loginButton.isEnabled = true
loginButton.hideSpinnerAndShowButton()
}
}
}
Loading

0 comments on commit 5142d4a

Please sign in to comment.