Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Login v2 #2908

Merged
merged 42 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
45454db
Enable login v2
mpivchev Apr 30, 2024
e0563bc
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 2, 2024
d8b1e53
Add external browser option
mpivchev May 2, 2024
b705120
WIP
mpivchev May 3, 2024
7315858
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 13, 2024
498882e
WIP
mpivchev May 14, 2024
dbfb2f2
WIP
mpivchev May 15, 2024
33feeaf
Remove NCLoginWeb for v2
mpivchev May 15, 2024
c1eb3b0
Cleanup
mpivchev May 15, 2024
eb75e20
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 15, 2024
90ce7e5
WIP
mpivchev May 17, 2024
1edaba3
WIP
mpivchev May 21, 2024
2fcd32a
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 21, 2024
e68f305
WIP
mpivchev May 21, 2024
4d3b6b2
WIP
mpivchev May 22, 2024
8d0e157
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 22, 2024
fbb8fb3
WIP
mpivchev May 22, 2024
e57151a
WIP
mpivchev May 22, 2024
077e5d2
WIP
mpivchev May 22, 2024
aa1d335
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 22, 2024
de1b1d2
Merge branch 'develop' of https://github.com/nextcloud/ios into ssl-cert
mpivchev May 23, 2024
99f1e2d
WIP
mpivchev May 23, 2024
768970f
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev May 28, 2024
e6e9734
WIP
mpivchev May 28, 2024
8de1a2d
WIP
mpivchev May 30, 2024
7d9ab9f
WIP
mpivchev May 30, 2024
33e6f39
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev Jun 10, 2024
6d776a5
Change design
mpivchev Jun 10, 2024
86ccf8a
Rename
mpivchev Jun 10, 2024
d560133
Remove unneeded code
mpivchev Jun 10, 2024
b86242c
Refactor
mpivchev Jun 10, 2024
e87f4a1
Fix acknowldgements
mpivchev Jun 11, 2024
b01a8bb
Remove unneeded brand flags
mpivchev Jun 12, 2024
91b5322
WIP
mpivchev Jun 13, 2024
3365b4c
Merge branch 'ssl-cert' into login-v2-enable
mpivchev Jun 14, 2024
527cb47
WIP
mpivchev Jun 17, 2024
0b68beb
WIP
mpivchev Jun 17, 2024
ce53ed7
WIP
mpivchev Jun 18, 2024
7289bf1
cleanup
mpivchev Jun 19, 2024
d3e2781
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
mpivchev Jun 24, 2024
d1be553
WIP
mpivchev Jun 24, 2024
b3dd8ba
Remove UI test
mpivchev Jun 24, 2024
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
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
}
}
}
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain ?

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
Loading