Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; };
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; };
AFCE353927E5DE0500FEA6C2 /* NCShare+Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */; };
B54315302DA647A400981E7E /* NCLoginWeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = B543152F2DA647A400981E7E /* NCLoginWeb.swift */; };
C04E2F232A17BB4D001BAD85 /* FilesIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04E2F222A17BB4D001BAD85 /* FilesIntegrationTests.swift */; };
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
Expand Down Expand Up @@ -1330,6 +1333,8 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* NCShare+Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCShare+Helper.swift"; sourceTree = "<group>"; };
B543152F2DA647A400981E7E /* NCLoginWeb.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginWeb.swift; sourceTree = "<group>"; };
C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2969,6 +2974,8 @@
F7BFFA621A24D7300044ED85 /* Login */ = {
isa = PBXGroup;
children = (
B543152F2DA647A400981E7E /* NCLoginWeb.swift */,
F3CA33802D106FF900672333 /* Poll */,
F702F2F025EE5CDA008F8E80 /* NCLogin.storyboard */,
F702F2F625EE5CEC008F8E80 /* NCLogin.swift */,
F738D48F2756740100CD1D38 /* NCLoginNavigationController.swift */,
Expand Down Expand Up @@ -4850,6 +4857,7 @@
F77BB748289985270090FC19 /* UITabBarController+Extension.swift in Sources */,
F763D29D2A249C4500A3C901 /* NCManageDatabase+Capabilities.swift in Sources */,
F76882252C0DD1E7001CF441 /* NCSettingsAdvancedModel.swift in Sources */,
B54315302DA647A400981E7E /* NCLoginWeb.swift in Sources */,
F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */,
F758B45E212C569D00515F55 /* NCScanCell.swift in Sources */,
F78B87E72B62527100C65ADC /* NCMediaDataSource.swift in Sources */,
Expand Down
15 changes: 15 additions & 0 deletions iOSClient/Login/NCLogin.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@
</objects>
<point key="canvasLocation" x="5421.739130434783" y="-1210.0446428571429"/>
</scene>
<!--Login Web-->
<scene sceneID="j8o-Lk-HsF">
<objects>
<viewController storyboardIdentifier="NCLoginWeb" id="hFi-DN-BXw" customClass="NCLoginWeb" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Npw-WL-mzw">
<rect key="frame" x="0.0" y="0.0" width="440" height="956"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="763-qA-dBR"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="fJz-iW-pCF" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="6145" y="-1212"/>
</scene>
</scenes>
<resources>
<image name="arrow.right" catalog="system" width="128" height="95"/>
Expand Down
30 changes: 21 additions & 9 deletions iOSClient/Login/NCLogin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
baseUrlTextField.isUserInteractionEnabled = false
baseUrlTextField.alpha = 0.5
}

// qrcode
qrCode.setImage(UIImage(named: "qrcode")?.image(color: textColor, size: 100), for: .normal)

// certificate
certificate.setImage(UIImage(named: "certificate")?.image(color: textColor, size: 100), for: .normal)
Expand Down Expand Up @@ -315,16 +318,25 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
if let host = URL(string: url)?.host {
NCNetworking.shared.writeCertificate(host: host)
}
let loginOptions = NKRequestOptions(customUserAgent: userAgent)
NextcloudKit.shared.getLoginFlowV2(serverUrl: url, options: loginOptions) { [self] token, endpoint, login, _, error in
NextcloudKit.shared.getLoginFlowV2(serverUrl: url) { [self] token, endpoint, login, _, error in
// Login Flow V2
if error == .success, let token, let endpoint, let login {
let safariVC = NCLoginProvider()
safariVC.urlBase = login
safariVC.uiColor = textColor
safariVC.delegate = self
safariVC.poll(loginFlowV2Token: token, loginFlowV2Endpoint: endpoint, loginFlowV2Login: login)
navigationController?.pushViewController(safariVC, animated: true)
if error == .success && NCBrandOptions.shared.use_loginflowv2 && token != nil && endpoint != nil && login != nil {

if let loginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb {

loginWeb.urlBase = url
loginWeb.user = user
loginWeb.loginFlowV2Available = true
loginWeb.loginFlowV2Token = token!
loginWeb.loginFlowV2Endpoint = endpoint!
loginWeb.loginFlowV2Login = login!

self.navigationController?.pushViewController(loginWeb, 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: { })
}
}
case .failure(let error):
Expand Down
94 changes: 82 additions & 12 deletions iOSClient/Login/NCLoginProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later

import UIKit
@preconcurrency import WebKit
import WebKit
import NextcloudKit
import FloatingPanel

class NCLoginProvider: UIViewController {
var webView: WKWebView?
let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
let utility = NCUtility()
var titleView: String = ""
var urlBase = ""
Expand Down Expand Up @@ -54,22 +55,41 @@ class NCLoginProvider: UIViewController {
NCContentPresenter().showError(error: error, priority: .max)
}

if let host = URL(string: urlBase)?.host {
titleView = host
if let activeTableAccount = NCManageDatabase.shared.getActiveTableAccount(), NCKeychain().getPassword(account: activeTableAccount.account).isEmpty {
titleView = NSLocalizedString("_user_", comment: "") + " " + activeTableAccount.userId + " " + NSLocalizedString("_in_", comment: "") + " " + host
if #available(iOS 13, *) {
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow}).first
let statusBar = UIView(frame: (keyWindow?.windowScene?.statusBarManager?.statusBarFrame)!)
statusBar.backgroundColor = NCBrandColor.shared.customer
keyWindow?.addSubview(statusBar)
} else {
if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView {
statusBar.backgroundColor = NCBrandColor.shared.customer
}
}
self.navigationController?.navigationBar.backgroundColor = NCBrandColor.shared.customer
}

self.title = titleView
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Stop timer error network
// appDelegate.timerErrorNetworkingDisabled = true
if let account = NCManageDatabase.shared.getActiveTableAccount(), NCKeychain().getPassword(account: account.account).isEmpty {

let message = "\n" + NSLocalizedString("_password_not_present_", comment: "")
let alertController = UIAlertController(title: titleView, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
present(alertController, animated: true)
}
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
NCActivityIndicator.shared.stop()

pollTimer?.cancel()
pollTimer = nil
// appDelegate.timerErrorNetworkingDisabled = false
}

func loadWebPage(webView: WKWebView, url: URL) {
Expand Down Expand Up @@ -255,8 +275,58 @@ extension NCLoginProvider: WKNavigationDelegate {
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
NCActivityIndicator.shared.stop()
}
}

protocol NCLoginProviderDelegate: AnyObject {
func onBack()
// MARK: -

func createAccount(server: String, username: String, password: String) {
var urlBase = server
if urlBase.last == "/" { urlBase = String(urlBase.dropLast()) }
let account: String = "\(username) \(urlBase)"
let user = username

// NextcloudKit.shared.setup(account: account, user: user, userId: user, password: password, urlBase: urlBase)
NextcloudKit.shared.getUserProfile(account: account) { _, userProfile, _, error in
if error == .success, let userProfile {
NextcloudKit.shared.appendSession(account: account,
urlBase: urlBase,
user: user,
userId: user,
password: password,
userAgent: userAgent,
nextcloudVersion: NCCapabilities.shared.getCapabilities(account: account).capabilityServerVersionMajor,
httpMaximumConnectionsPerHost: NCBrandOptions.shared.httpMaximumConnectionsPerHost,
httpMaximumConnectionsPerHostInDownload: NCBrandOptions.shared.httpMaximumConnectionsPerHostInDownload,
httpMaximumConnectionsPerHostInUpload: NCBrandOptions.shared.httpMaximumConnectionsPerHostInUpload,
groupIdentifier: NCBrandOptions.shared.capabilitiesGroup)
NCSession.shared.appendSession(account: account, urlBase: urlBase, user: user, userId: userProfile.userId)
NCAccount().deleteAccount(account)
NCManageDatabase.shared.addAccount(account, urlBase: urlBase, user: user, userId: userProfile.userId, password: password)
NCAccount().changeAccount(account, userProfile: userProfile, controller: nil) { }
let window = UIApplication.shared.firstWindow
if window?.rootViewController is NCMainTabBarController {
self.dismiss(animated: true)
} else {
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController {
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
}
}
}
} else {
let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: error.errorDescription, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
self.present(alertController, animated: true)
}
}
}
}
Loading