From 15f1a702126029e8c7b5f0532c304d2df5d57f94 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Wed, 26 Mar 2025 18:04:52 +0100 Subject: [PATCH 1/3] WIP Signed-off-by: Milen Pivchev --- .../xcshareddata/xcschemes/Nextcloud.xcscheme | 17 +++++++ iOSClient/Login/NCLogin.swift | 46 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/Nextcloud.xcodeproj/xcshareddata/xcschemes/Nextcloud.xcscheme b/Nextcloud.xcodeproj/xcshareddata/xcschemes/Nextcloud.xcscheme index 3bb180bac2..4229e4cf14 100755 --- a/Nextcloud.xcodeproj/xcshareddata/xcschemes/Nextcloud.xcscheme +++ b/Nextcloud.xcodeproj/xcshareddata/xcschemes/Nextcloud.xcscheme @@ -135,6 +135,23 @@ ReferencedContainer = "container:Nextcloud.xcodeproj"> + + + + + + + + diff --git a/iOSClient/Login/NCLogin.swift b/iOSClient/Login/NCLogin.swift index 946e8c6300..76b381a1f6 100644 --- a/iOSClient/Login/NCLogin.swift +++ b/iOSClient/Login/NCLogin.swift @@ -169,6 +169,52 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate { } NCNetworking.shared.certificateDelegate = self + +#if DEBUG + // Create a UIButton + let button = UIButton(type: .system) + button.setTitle("[DEBUG] Auto login", for: .normal) + button.backgroundColor = .black + button.setTitleColor(.white, for: .normal) + + // Set Button Constraints + button.translatesAutoresizingMaskIntoConstraints = false + + // Add target action + button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) + + // Add button to the view + view.addSubview(button) + + // Set Auto Layout Constraints + NSLayoutConstraint.activate([ + button.centerXAnchor.constraint(equalTo: view.centerXAnchor), + button.centerYAnchor.constraint(equalTo: qrCode.topAnchor, constant: -50), + button.widthAnchor.constraint(equalToConstant: 150), + button.heightAnchor.constraint(equalToConstant: 50) + ]) +#endif + } + + func setupAppToken(server: String, username: String, password: String) { + NextcloudKit.shared.getAppPassword(url: server, user: username, password: password) { [self] token, _, error in + + guard let token else { return } + + createAccount(urlBase: server, user: username, password: token) + } + } + + @objc func buttonTapped() { + guard let baseUrl = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_BASE_URL"], + let username = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_USERNAME"], + let password = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_PASSWORD"] else { + + let alert = UIAlertController.warning(title: "No env vars found for debug auto log in.", message: "Add DEBUG_AUTO_LOGIN_BASE_URL, DEBUG_AUTO_LOGIN_USERNAME and DEBUG_AUTO_LOGIN_PASSWORD to env vars") + present(alert, animated: true) + return + } + setupAppToken(server: baseUrl, username: username, password: password) } override func viewDidAppear(_ animated: Bool) { From b170046b5d9aa8fd5ea9b77a849f0d642ad79b46 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Thu, 27 Mar 2025 13:06:07 +0100 Subject: [PATCH 2/3] WIP Signed-off-by: Milen Pivchev --- iOSClient/Login/NCLogin.swift | 100 +++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 43 deletions(-) diff --git a/iOSClient/Login/NCLogin.swift b/iOSClient/Login/NCLogin.swift index 76b381a1f6..8cf67a64b1 100644 --- a/iOSClient/Login/NCLogin.swift +++ b/iOSClient/Login/NCLogin.swift @@ -171,52 +171,10 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate { NCNetworking.shared.certificateDelegate = self #if DEBUG - // Create a UIButton - let button = UIButton(type: .system) - button.setTitle("[DEBUG] Auto login", for: .normal) - button.backgroundColor = .black - button.setTitleColor(.white, for: .normal) - - // Set Button Constraints - button.translatesAutoresizingMaskIntoConstraints = false - - // Add target action - button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) - - // Add button to the view - view.addSubview(button) - - // Set Auto Layout Constraints - NSLayoutConstraint.activate([ - button.centerXAnchor.constraint(equalTo: view.centerXAnchor), - button.centerYAnchor.constraint(equalTo: qrCode.topAnchor, constant: -50), - button.widthAnchor.constraint(equalToConstant: 150), - button.heightAnchor.constraint(equalToConstant: 50) - ]) + addDebugAutoLogInButton() #endif } - func setupAppToken(server: String, username: String, password: String) { - NextcloudKit.shared.getAppPassword(url: server, user: username, password: password) { [self] token, _, error in - - guard let token else { return } - - createAccount(urlBase: server, user: username, password: token) - } - } - - @objc func buttonTapped() { - guard let baseUrl = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_BASE_URL"], - let username = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_USERNAME"], - let password = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_PASSWORD"] else { - - let alert = UIAlertController.warning(title: "No env vars found for debug auto log in.", message: "Add DEBUG_AUTO_LOGIN_BASE_URL, DEBUG_AUTO_LOGIN_USERNAME and DEBUG_AUTO_LOGIN_PASSWORD to env vars") - present(alert, animated: true) - return - } - setupAppToken(server: baseUrl, username: username, password: password) - } - override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) @@ -535,3 +493,59 @@ extension NCLogin: NCLoginProviderDelegate { loginButton.hideSpinnerAndShowButton() } } + +#if DEBUG +extension NCLogin { + private func addDebugAutoLogInButton() { + let button = UIButton(type: .system) + button.setTitle("[DEBUG] Auto login", for: .normal) + button.backgroundColor = .black + button.setTitleColor(.white, for: .normal) + button.translatesAutoresizingMaskIntoConstraints = false + button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside) + view.addSubview(button) + + NSLayoutConstraint.activate([ + button.centerXAnchor.constraint(equalTo: view.centerXAnchor), + button.centerYAnchor.constraint(equalTo: qrCode.topAnchor, constant: -50), + button.widthAnchor.constraint(equalToConstant: 150), + button.heightAnchor.constraint(equalToConstant: 50) + ]) + } + + private func getAppPassword(urlBase: String, user: String, password: String) { + NextcloudKit.shared.getAppPassword(url: urlBase, user: user, password: password) { token, _, error in + if error == .success, let password = token { + self.createAccount(urlBase: urlBase, user: user, password: password) + } else { + NCContentPresenter().showError(error: error) + self.dismiss(animated: true, completion: nil) + } + } + } + + private func autoLogIn(server: String, username: String, password: String) { + NextcloudKit.shared.getAppPassword(url: server, user: username, password: password) { [self] token, _, error in + guard let token, error == .success else { + present(UIAlertController.warning(message: error.error.localizedDescription), animated: true) + return + } + + createAccount(urlBase: server, user: username, password: token) + } + } + + @objc func buttonTapped() { + guard let baseUrl = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_BASE_URL"], + let username = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_USERNAME"], + let password = ProcessInfo.processInfo.environment["DEBUG_AUTO_LOGIN_PASSWORD"] else { + + let alert = UIAlertController.warning(title: "No env vars found for debug auto log in.", message: "Add DEBUG_AUTO_LOGIN_BASE_URL, DEBUG_AUTO_LOGIN_USERNAME and DEBUG_AUTO_LOGIN_PASSWORD to env vars") + present(alert, animated: true) + return + } + + autoLogIn(server: baseUrl, username: username, password: password) + } +} +#endif From 002b4d9edcbbe864281bcb2d27bdcbcaab286737 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Thu, 27 Mar 2025 15:14:20 +0100 Subject: [PATCH 3/3] Remove duplicate Signed-off-by: Milen Pivchev --- iOSClient/Login/NCLogin.swift | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/iOSClient/Login/NCLogin.swift b/iOSClient/Login/NCLogin.swift index 8cf67a64b1..2ad77c3e02 100644 --- a/iOSClient/Login/NCLogin.swift +++ b/iOSClient/Login/NCLogin.swift @@ -513,17 +513,6 @@ extension NCLogin { ]) } - private func getAppPassword(urlBase: String, user: String, password: String) { - NextcloudKit.shared.getAppPassword(url: urlBase, user: user, password: password) { token, _, error in - if error == .success, let password = token { - self.createAccount(urlBase: urlBase, user: user, password: password) - } else { - NCContentPresenter().showError(error: error) - self.dismiss(animated: true, completion: nil) - } - } - } - private func autoLogIn(server: String, username: String, password: String) { NextcloudKit.shared.getAppPassword(url: server, user: username, password: password) { [self] token, _, error in guard let token, error == .success else {