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..2ad77c3e02 100644 --- a/iOSClient/Login/NCLogin.swift +++ b/iOSClient/Login/NCLogin.swift @@ -169,6 +169,10 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate { } NCNetworking.shared.certificateDelegate = self + +#if DEBUG + addDebugAutoLogInButton() +#endif } override func viewDidAppear(_ animated: Bool) { @@ -489,3 +493,48 @@ 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 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