Allow registration on matrix.org using a custom helper URL. (#3282)

This commit is contained in:
Doug
2024-09-16 13:05:22 +01:00
committed by GitHub
parent 6cfe09b96d
commit 6efbf6117f
15 changed files with 129 additions and 42 deletions
@@ -77,7 +77,8 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
// MARK: - Private
private func showStartScreen() {
let coordinator = AuthenticationStartScreenCoordinator()
let parameters = AuthenticationStartScreenParameters(webRegistrationEnabled: appSettings.webRegistrationEnabled)
let coordinator = AuthenticationStartScreenCoordinator(parameters: parameters)
coordinator.actions
.sink { [weak self] action in
@@ -85,9 +86,11 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
switch action {
case .loginManually:
Task { await self.startAuthentication() }
Task { await self.startAuthentication(flow: .login) }
case .loginWithQR:
startQRCodeLogin()
case .register:
Task { await self.startAuthentication(flow: .register) }
case .reportProblem:
showReportProblemScreen()
}
@@ -110,7 +113,7 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
switch action {
case .signInManually:
navigationStackCoordinator.setSheetCoordinator(nil)
Task { await self.startAuthentication() }
Task { await self.startAuthentication(flow: .login) }
case .cancel:
navigationStackCoordinator.setSheetCoordinator(nil)
case .done(let userSession):
@@ -134,20 +137,20 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
bugReportFlowCoordinator?.start()
}
private func startAuthentication() async {
private func startAuthentication(flow: AuthenticationFlow) async {
startLoading()
switch await authenticationService.configure(for: appSettings.defaultHomeserverAddress) {
case .success:
stopLoading()
showServerConfirmationScreen()
showServerConfirmationScreen(authenticationFlow: flow)
case .failure:
stopLoading()
showServerSelectionScreen(isModallyPresented: false)
showServerSelectionScreen(authenticationFlow: flow, isModallyPresented: false)
}
}
private func showServerSelectionScreen(isModallyPresented: Bool) {
private func showServerSelectionScreen(authenticationFlow: AuthenticationFlow, isModallyPresented: Bool) {
let navigationCoordinator = NavigationStackCoordinator()
let parameters = ServerSelectionScreenCoordinatorParameters(authenticationService: authenticationService,
@@ -166,13 +169,18 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
} else {
// We are here because the default server failed to respond.
if authenticationService.homeserver.value.loginMode == .password {
// Add the password login screen directly to the flow, its fine.
showLoginScreen()
if authenticationFlow == .login {
// Add the password login screen directly to the flow, its fine.
showLoginScreen()
} else {
// Add the web registration screen directly to the flow, its fine.
showWebRegistration()
}
} else {
// OIDC is presented from the confirmation screen so replace the
// server selection screen which was inserted to handle the failure.
navigationStackCoordinator.pop()
showServerConfirmationScreen()
showServerConfirmationScreen(authenticationFlow: authenticationFlow)
}
}
case .dismiss:
@@ -189,9 +197,9 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
}
}
private func showServerConfirmationScreen() {
private func showServerConfirmationScreen(authenticationFlow: AuthenticationFlow) {
let parameters = ServerConfirmationScreenCoordinatorParameters(authenticationService: authenticationService,
authenticationFlow: .login)
authenticationFlow: authenticationFlow)
let coordinator = ServerConfirmationScreenCoordinator(parameters: parameters)
coordinator.actions.sink { [weak self] action in
@@ -201,11 +209,13 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
case .continue(let window):
if authenticationService.homeserver.value.loginMode == .oidc, let window {
showOIDCAuthentication(presentationAnchor: window)
} else if authenticationFlow == .register {
showWebRegistration()
} else {
showLoginScreen()
}
case .changeServer:
showServerSelectionScreen(isModallyPresented: true)
showServerSelectionScreen(authenticationFlow: authenticationFlow, isModallyPresented: true)
}
}
.store(in: &cancellables)
@@ -213,6 +223,26 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
navigationStackCoordinator.push(coordinator)
}
private func showWebRegistration() {
let parameters = WebRegistrationScreenCoordinatorParameters(authenticationService: authenticationService,
userIndicatorController: userIndicatorController)
let coordinator = WebRegistrationScreenCoordinator(parameters: parameters)
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .cancel:
navigationStackCoordinator.setSheetCoordinator(nil)
case .signedIn(let userSession):
userHasSignedIn(userSession: userSession)
}
}
.store(in: &cancellables)
navigationStackCoordinator.setSheetCoordinator(coordinator)
}
private func showOIDCAuthentication(presentationAnchor: UIWindow) {
startLoading()