mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 00:24:43 +02:00
Disable the next button whilst loading a server.
Add tests for login screen. Self review.
This commit is contained in:
+17
-15
@@ -84,7 +84,7 @@ class AuthenticationService: NSObject {
|
||||
}
|
||||
|
||||
func startFlow(_ flow: AuthenticationFlow, for homeserverAddress: String) async throws {
|
||||
var (client, state) = try await loginFlow(for: homeserverAddress)
|
||||
var (client, homeserver) = try await loginFlow(for: homeserverAddress)
|
||||
|
||||
let loginWizard = LoginWizard(client: client)
|
||||
self.loginWizard = loginWizard
|
||||
@@ -92,18 +92,19 @@ class AuthenticationService: NSObject {
|
||||
if flow == .register {
|
||||
do {
|
||||
let registrationWizard = RegistrationWizard(client: client)
|
||||
state.homeserver.registrationFlow = try await registrationWizard.registrationFlow()
|
||||
state.flow = .register
|
||||
homeserver.registrationFlow = try await registrationWizard.registrationFlow()
|
||||
self.registrationWizard = registrationWizard
|
||||
} catch {
|
||||
guard state.homeserver.preferredLoginMode.hasSSO, error as? RegistrationError == .registrationDisabled else {
|
||||
guard homeserver.preferredLoginMode.hasSSO, error as? RegistrationError == .registrationDisabled else {
|
||||
throw error
|
||||
}
|
||||
// Continue without throwing when registration is disabled but SSO is available.
|
||||
}
|
||||
}
|
||||
|
||||
self.state = state
|
||||
// The state and client are set after trying the registration flow to
|
||||
// ensure the existing state isn't wiped out when an error occurs.
|
||||
self.state = AuthenticationState(flow: flow, homeserver: homeserver)
|
||||
self.client = client
|
||||
}
|
||||
|
||||
@@ -165,10 +166,11 @@ class AuthenticationService: NSObject {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
/// Request the supported login flows for this homeserver.
|
||||
/// Query the supported login flows for the supplied homeserver.
|
||||
/// This is the first method to call to be able to get a wizard to login or to create an account
|
||||
/// - Parameter homeserverAddress: The homeserver string entered by the user.
|
||||
private func loginFlow(for homeserverAddress: String) async throws -> (AuthenticationRestClient, AuthenticationState) {
|
||||
/// - Returns: A tuple containing the REST client for the server along with the homeserver state containing the login flows.
|
||||
private func loginFlow(for homeserverAddress: String) async throws -> (AuthenticationRestClient, AuthenticationState.Homeserver) {
|
||||
let homeserverAddress = HomeserverAddress.sanitized(homeserverAddress)
|
||||
|
||||
guard var homeserverURL = URL(string: homeserverAddress) else {
|
||||
@@ -186,16 +188,16 @@ class AuthenticationService: NSObject {
|
||||
|
||||
let loginFlow = try await getLoginFlowResult(client: client)
|
||||
|
||||
let state = AuthenticationState(flow: .login, homeserver: .init(address: loginFlow.homeserverAddress,
|
||||
addressFromUser: homeserverAddress,
|
||||
preferredLoginMode: loginFlow.loginMode))
|
||||
return (client, state)
|
||||
let homeserver = AuthenticationState.Homeserver(address: loginFlow.homeserverAddress,
|
||||
addressFromUser: homeserverAddress,
|
||||
preferredLoginMode: loginFlow.loginMode)
|
||||
return (client, homeserver)
|
||||
}
|
||||
|
||||
/// Request the supported login flows for the corresponding session.
|
||||
/// This method is used to get the flows for a server after a soft-logout.
|
||||
/// - Parameter session: The MXSession where a soft-logout has occurred.
|
||||
private func loginFlow(for session: MXSession) async throws -> (AuthenticationRestClient, AuthenticationState) {
|
||||
private func loginFlow(for session: MXSession) async throws -> (AuthenticationRestClient, AuthenticationState.Homeserver) {
|
||||
guard let client = session.matrixRestClient else {
|
||||
MXLog.error("[AuthenticationService] loginFlow called on a session that doesn't have a matrixRestClient.")
|
||||
throw AuthenticationError.missingMXRestClient
|
||||
@@ -203,9 +205,9 @@ class AuthenticationService: NSObject {
|
||||
|
||||
let loginFlow = try await getLoginFlowResult(client: session.matrixRestClient)
|
||||
|
||||
let state = AuthenticationState(flow: .login, homeserver: .init(address: loginFlow.homeserverAddress,
|
||||
preferredLoginMode: loginFlow.loginMode))
|
||||
return (client, state)
|
||||
let homeserver = AuthenticationState.Homeserver(address: loginFlow.homeserverAddress,
|
||||
preferredLoginMode: loginFlow.loginMode)
|
||||
return (client, homeserver)
|
||||
}
|
||||
|
||||
private func getLoginFlowResult(client: MXRestClient) async throws -> LoginFlowResult {
|
||||
|
||||
@@ -58,6 +58,7 @@ struct AuthenticationState {
|
||||
return url.host == "matrix.org" || url.host == "matrix-client.matrix.org"
|
||||
}
|
||||
|
||||
/// The homeserver mapped into view data that is ready for display.
|
||||
var viewData: AuthenticationHomeserverViewData {
|
||||
AuthenticationHomeserverViewData(address: displayableAddress,
|
||||
isMatrixDotOrg: isMatrixDotOrg,
|
||||
|
||||
Reference in New Issue
Block a user