Skip to content

Commit

Permalink
Enable Login v2 (#2908)
Browse files Browse the repository at this point in the history
* Enable login v2

Signed-off-by: Milen Pivchev <[email protected]>

* Add external browser option

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* Remove NCLoginWeb for v2

Signed-off-by: Milen Pivchev <[email protected]>

* Cleanup

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* Change design

Signed-off-by: Milen Pivchev <[email protected]>

* Rename

Signed-off-by: Milen Pivchev <[email protected]>

* Remove unneeded code

Signed-off-by: Milen Pivchev <[email protected]>

* Refactor

Signed-off-by: Milen Pivchev <[email protected]>

* Fix acknowldgements

Signed-off-by: Milen Pivchev <[email protected]>

* Remove unneeded brand flags

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* cleanup

Signed-off-by: Milen Pivchev <[email protected]>

* WIP

Signed-off-by: Milen Pivchev <[email protected]>

* Remove UI test

Signed-off-by: Milen Pivchev <[email protected]>

---------

Signed-off-by: Milen Pivchev <[email protected]>
  • Loading branch information
mpivchev authored Jun 24, 2024
1 parent 58b5430 commit 38c26ef
Show file tree
Hide file tree
Showing 25 changed files with 722 additions and 454 deletions.
17 changes: 17 additions & 0 deletions Brand/Intro/NCIntroViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ class NCIntroViewController: UIViewController, UICollectionViewDataSource, UICol

view.backgroundColor = NCBrandColor.shared.customer
timerAutoScroll = Timer.scheduledTimer(timeInterval: 5, target: self, selector: (#selector(NCIntroViewController.autoScroll)), userInfo: nil, repeats: true)

NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeUser), object: nil, queue: nil) { _ in
let window = UIApplication.shared.firstWindow
if window?.rootViewController is NCMainTabBarController {
self.dismiss(animated: true)
} else {
if let mainTabBarController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() as? NCMainTabBarController {
mainTabBarController.modalPresentationStyle = .fullScreen
mainTabBarController.view.alpha = 0
window?.rootViewController = mainTabBarController
window?.makeKeyAndVisible()
UIView.animate(withDuration: 0.5) {
mainTabBarController.view.alpha = 1
}
}
}
}
}

override var preferredStatusBarStyle: UIStatusBarStyle {
Expand Down
19 changes: 2 additions & 17 deletions Brand/NCBrand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ let userAgent: String = {
var sourceCode: String = "https://github.com/nextcloud/ios"
var mobileconfig: String = "/remote.php/dav/provisioning/apple-provisioning.mobileconfig"

// Personalized
var webCloseViewProtocolPersonalized: String = "" // example "abc://change/plan" Don't touch me !!
var folderBrandAutoUpload: String = "" // example "_auto_upload_folder_" Don't touch me !!

// Auto Upload default folder
var folderDefaultAutoUpload: String = "Photos"

Expand All @@ -59,16 +55,10 @@ let userAgent: String = {
var capabilitiesGroupApps: String = "group.com.nextcloud.apps"

// BRAND ONLY
var use_login_web_personalized: Bool = false // Don't touch me !!
var use_AppConfig: Bool = false // Don't touch me !!
var use_GroupApps: Bool = true // Don't touch me !!
@objc public var use_AppConfig: Bool = false // Don't touch me !!

// Options
var use_default_auto_upload: Bool = false
var use_themingColor: Bool = true
var use_themingLogo: Bool = false
var use_storeLocalAutoUploadAll: Bool = false
var use_loginflowv2: Bool = false // Don't touch me !!
@objc public var use_themingColor: Bool = true

var disable_intro: Bool = false
var disable_request_login_url: Bool = false
Expand Down Expand Up @@ -99,11 +89,6 @@ let userAgent: String = {
}

override init() {

if folderBrandAutoUpload != "" {
folderDefaultAutoUpload = folderBrandAutoUpload
}

// wrapper AppConfig
if let configurationManaged = UserDefaults.standard.dictionary(forKey: "com.apple.configuration.managed"), use_AppConfig {

Expand Down
123 changes: 110 additions & 13 deletions Nextcloud.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1540"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1540"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1540"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
2 changes: 1 addition & 1 deletion Nextcloud.xcodeproj/xcshareddata/xcschemes/Share.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1540"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
2 changes: 1 addition & 1 deletion Nextcloud.xcodeproj/xcshareddata/xcschemes/Widget.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1540"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
75 changes: 0 additions & 75 deletions Tests/NextcloudUITests/LoginUITests.swift

This file was deleted.

93 changes: 70 additions & 23 deletions iOSClient/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Firebase
import WidgetKit
import Queuer
import EasyTipView
import SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, NCUserBaseUrl {
Expand All @@ -42,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var tipView: EasyTipView?
var backgroundSessionCompletionHandler: (() -> Void)?
var activeLogin: NCLogin?
var activeLoginWeb: NCLoginWeb?
var activeLoginWeb: NCLoginProvider?
var timerErrorNetworking: Timer?
var timerErrorNetworkingDisabled: Bool = false
var taskAutoUploadDate: Date = Date()
Expand All @@ -51,6 +52,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}
var notificationSettings: UNNotificationSettings?

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

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if isUiTestingEnabled {
deleteAllAccounts()
Expand Down Expand Up @@ -361,45 +366,59 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}

// [WEBPersonalized] [AppConfig]
if NCBrandOptions.shared.use_login_web_personalized || NCBrandOptions.shared.use_AppConfig {
if activeLoginWeb?.view.window == nil {
activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
activeLoginWeb?.urlBase = NCBrandOptions.shared.loginBaseUrl
showLoginViewController(activeLoginWeb)
if NCBrandOptions.shared.use_AppConfig {
if activeLogin?.view.window == nil {
urlBase = NCBrandOptions.shared.loginBaseUrl

NextcloudKit.shared.getLoginFlowV2(serverUrl: urlBase) { token, endpoint, login, _, error in

// Login Flow V2
if error == .success, let token, let endpoint, let login {
let vc = UIHostingController(rootView: NCLoginPoll(loginFlowV2Token: token, loginFlowV2Endpoint: endpoint, loginFlowV2Login: login, cancelButtonDisabled: NCManageDatabase.shared.getAccounts().isEmptyOrNil))

UIApplication.shared.firstWindow?.rootViewController?.present(vc, animated: true)
}
}

return
}
return
}

// Nextcloud standard login
if selector == NCGlobal.shared.introSignup {
if activeLoginWeb?.view.window == nil {
activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
if activeLogin?.view.window == nil {
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin

if selector == NCGlobal.shared.introSignup {
activeLoginWeb?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
activeLogin?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
let web = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginProvider") as? NCLoginProvider
web?.urlBase = NCBrandOptions.shared.linkloginPreferredProviders
showLoginViewController(web)
} else {
activeLoginWeb?.urlBase = self.urlBase
activeLogin?.urlBase = self.urlBase
showLoginViewController(activeLogin)
}
showLoginViewController(activeLoginWeb)
}

} else if NCBrandOptions.shared.disable_intro && NCBrandOptions.shared.disable_request_login_url {
if activeLoginWeb?.view.window == nil {
activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
activeLoginWeb?.urlBase = NCBrandOptions.shared.loginBaseUrl
showLoginViewController(activeLoginWeb)
if activeLogin?.view.window == nil {
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
activeLogin?.urlBase = NCBrandOptions.shared.loginBaseUrl
showLoginViewController(activeLogin)
}

} else if openLoginWeb {
// Used also for reinsert the account (change passwd)
if activeLoginWeb?.view.window == nil {
activeLoginWeb = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLoginWeb") as? NCLoginWeb
activeLoginWeb?.urlBase = urlBase
activeLoginWeb?.user = user
showLoginViewController(activeLoginWeb)
if activeLogin?.view.window == nil {
activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
activeLogin?.urlBase = urlBase
activeLogin?.disableUrlField = true
activeLogin?.disableCloseButton = true
showLoginViewController(activeLogin)
}

} else {
if activeLogin?.view.window == nil {
activeLogin?.disableCloseButton = true

activeLogin = UIStoryboard(name: "NCLogin", bundle: nil).instantiateViewController(withIdentifier: "NCLogin") as? NCLogin
showLoginViewController(activeLogin)
}
Expand Down Expand Up @@ -457,6 +476,34 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

// MARK: - Account

func createAccount(server: String, username: String, password: String, completion: @escaping (_ error: NKError) -> Void) {
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 { _, userProfile, _, error in

if error == .success, let userProfile {

NCManageDatabase.shared.deleteAccount(account)
NCManageDatabase.shared.addAccount(account, urlBase: urlBase, user: user, userId: userProfile.userId, password: password)

NCKeychain().setClientCertificate(account: account, p12Data: NCNetworking.shared.p12Data, p12Password: NCNetworking.shared.p12Password)

self.changeAccount(account, userProfile: userProfile)
} else {

let alertController = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: error.errorDescription, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: { _ in }))
UIApplication.shared.firstWindow?.rootViewController?.present(alertController, animated: true)
}

completion(error)
}
}

func changeAccount(_ account: String, userProfile: NKUserProfile?) {

NCNetworking.shared.cancelAllQueue()
Expand Down
9 changes: 0 additions & 9 deletions iOSClient/Data/NCManageDatabase+Account.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ extension NCManageDatabase {

addObject.account = account

// Brand
if NCBrandOptions.shared.use_default_auto_upload {

addObject.autoUpload = true
addObject.autoUploadImage = true
addObject.autoUploadVideo = true
addObject.autoUploadWWAnVideo = true
}

NCKeychain().setPassword(account: account, password: password)

addObject.urlBase = urlBase
Expand Down
25 changes: 25 additions & 0 deletions iOSClient/Extensions/View+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,29 @@ extension View {
self
}
}

func onFirstAppear(perform action: @escaping () -> Void) -> some View {
modifier(ViewFirstAppearModifier(perform: action))
}
}

struct ViewFirstAppearModifier: ViewModifier {
@State private var didAppearBefore = false
private let action: () -> Void

init(perform action: @escaping () -> Void) {
self.action = action
}

func body(content: Content) -> some View {
content.onAppear {
guard !didAppearBefore else { return }
didAppearBefore = true
action()
}
}
}

var isRunningForPreviews: Bool {
return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
}
8 changes: 4 additions & 4 deletions iOSClient/Login/NCLogin.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21225" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21207"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down Expand Up @@ -118,10 +118,10 @@
</objects>
<point key="canvasLocation" x="4498.5507246376819" y="-1211.3839285714284"/>
</scene>
<!--Login Web-->
<!--Login Provider-->
<scene sceneID="3Rv-vf-u17">
<objects>
<viewController storyboardIdentifier="NCLoginWeb" id="yEb-Ky-35s" customClass="NCLoginWeb" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="NCLoginProvider" id="yEb-Ky-35s" customClass="NCLoginProvider" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="UX5-cJ-bY6">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
Loading

0 comments on commit 38c26ef

Please sign in to comment.