Login Procedure updated (login via in-app browser)
This commit is contained in:
Binary file not shown.
@@ -1018,6 +1018,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Done" : {
|
||||
|
||||
},
|
||||
"Downloads" : {
|
||||
"localizations" : {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import WebKit
|
||||
|
||||
enum V2LoginStage: LoginStage {
|
||||
case login, validate
|
||||
@@ -34,6 +35,7 @@ struct V2LoginView: View {
|
||||
|
||||
@State var loginStage: V2LoginStage = .login
|
||||
@State var loginRequest: LoginV2Request? = nil
|
||||
@State var presentBrowser = false
|
||||
|
||||
// TextField handling
|
||||
enum Field {
|
||||
@@ -84,7 +86,8 @@ struct V2LoginView: View {
|
||||
showAlert = true
|
||||
}
|
||||
if let loginRequest = loginRequest {
|
||||
await UIApplication.shared.open(URL(string: loginRequest.login)!)
|
||||
presentBrowser = true
|
||||
//await UIApplication.shared.open(URL(string: loginRequest.login)!)
|
||||
} else {
|
||||
alertMessage = "Unable to reach server. Please check your server address and internet connection."
|
||||
showAlert = true
|
||||
@@ -110,7 +113,49 @@ struct V2LoginView: View {
|
||||
// fetch login v2 response
|
||||
Task {
|
||||
let (response, error) = await fetchLoginV2Response()
|
||||
checkLogin(response: response, error: error)
|
||||
}
|
||||
} label: {
|
||||
Text("Validate")
|
||||
.foregroundColor(.white)
|
||||
.font(.headline)
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.white, lineWidth: 2)
|
||||
.foregroundColor(.clear)
|
||||
)
|
||||
}
|
||||
.disabled(loginRequest == nil ? true : false)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $presentBrowser, onDismiss: {
|
||||
Task {
|
||||
let (response, error) = await fetchLoginV2Response()
|
||||
checkLogin(response: response, error: error)
|
||||
}
|
||||
}) {
|
||||
if let loginRequest = loginRequest {
|
||||
WebViewSheet(url: loginRequest.login)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sendLoginV2Request() async -> NetworkError? {
|
||||
let (req, error) = await NextcloudApi.loginV2Request()
|
||||
self.loginRequest = req
|
||||
return error
|
||||
}
|
||||
|
||||
func fetchLoginV2Response() async -> (LoginV2Response?, NetworkError?) {
|
||||
guard let loginRequest = loginRequest else { return (nil, .parametersNil) }
|
||||
return await NextcloudApi.loginV2Response(req: loginRequest)
|
||||
}
|
||||
|
||||
func checkLogin(response: LoginV2Response?, error: NetworkError?) {
|
||||
if let error = error {
|
||||
alertMessage = "Login failed. Please login via the browser and try again. (\(error.rawValue))"
|
||||
showAlert = true
|
||||
@@ -131,33 +176,36 @@ struct V2LoginView: View {
|
||||
}
|
||||
UserSettings.shared.onboarding = false
|
||||
}
|
||||
} label: {
|
||||
Text("Validate")
|
||||
.foregroundColor(.white)
|
||||
.font(.headline)
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.white, lineWidth: 2)
|
||||
.foregroundColor(.clear)
|
||||
)
|
||||
}
|
||||
.disabled(loginRequest == nil ? true : false)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sendLoginV2Request() async -> NetworkError? {
|
||||
let (req, error) = await NextcloudApi.loginV2Request()
|
||||
self.loginRequest = req
|
||||
return error
|
||||
}
|
||||
|
||||
func fetchLoginV2Response() async -> (LoginV2Response?, NetworkError?) {
|
||||
guard let loginRequest = loginRequest else { return (nil, .parametersNil) }
|
||||
return await NextcloudApi.loginV2Response(req: loginRequest)
|
||||
|
||||
// Login WebView logic
|
||||
|
||||
struct WebViewSheet: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@State var url: String
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
WebView(url: URL(string: url)!)
|
||||
.navigationBarTitle(Text("Nextcloud Login"), displayMode: .inline)
|
||||
.navigationBarItems(trailing: Button("Done") {
|
||||
dismiss()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct WebView: UIViewRepresentable {
|
||||
let url: URL
|
||||
|
||||
func makeUIView(context: Context) -> WKWebView {
|
||||
return WKWebView()
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: WKWebView, context: Context) {
|
||||
let request = URLRequest(url: url)
|
||||
uiView.load(request)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user