mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Allow registration on matrix.org using a custom helper URL. (#3282)
This commit is contained in:
+18
-4
@@ -19,6 +19,8 @@ struct ServerConfirmationScreenViewState: BindableState {
|
||||
var homeserverAddress: String
|
||||
/// The flow being attempted on the selected homeserver.
|
||||
let authenticationFlow: AuthenticationFlow
|
||||
/// Whether or not the homeserver supports registration.
|
||||
var homeserverSupportsRegistration = false
|
||||
/// The presentation anchor used for OIDC authentication.
|
||||
var window: UIWindow?
|
||||
|
||||
@@ -37,14 +39,26 @@ struct ServerConfirmationScreenViewState: BindableState {
|
||||
switch authenticationFlow {
|
||||
case .login:
|
||||
if homeserverAddress == "matrix.org" {
|
||||
return L10n.screenServerConfirmationMessageLoginMatrixDotOrg
|
||||
L10n.screenServerConfirmationMessageLoginMatrixDotOrg
|
||||
} else if homeserverAddress == "element.io" {
|
||||
return L10n.screenServerConfirmationMessageLoginElementDotIo
|
||||
L10n.screenServerConfirmationMessageLoginElementDotIo
|
||||
} else {
|
||||
return ""
|
||||
""
|
||||
}
|
||||
case .register:
|
||||
return L10n.screenServerConfirmationMessageRegister
|
||||
if canContinue {
|
||||
L10n.screenServerConfirmationMessageRegister
|
||||
} else {
|
||||
L10n.errorAccountCreationNotPossible
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether or not it is valid to continue the flow.
|
||||
var canContinue: Bool {
|
||||
switch authenticationFlow {
|
||||
case .login: true
|
||||
case .register: homeserverSupportsRegistration
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -18,14 +18,18 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
|
||||
}
|
||||
|
||||
init(authenticationService: AuthenticationServiceProtocol, authenticationFlow: AuthenticationFlow) {
|
||||
super.init(initialViewState: ServerConfirmationScreenViewState(homeserverAddress: authenticationService.homeserver.value.address,
|
||||
authenticationFlow: authenticationFlow))
|
||||
let homeserver = authenticationService.homeserver.value
|
||||
|
||||
super.init(initialViewState: ServerConfirmationScreenViewState(homeserverAddress: homeserver.address,
|
||||
authenticationFlow: authenticationFlow,
|
||||
homeserverSupportsRegistration: homeserver.supportsRegistration))
|
||||
|
||||
authenticationService.homeserver
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] homeserver in
|
||||
guard let self else { return }
|
||||
state.homeserverAddress = homeserver.address
|
||||
state.homeserverSupportsRegistration = homeserver.supportsRegistration
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
@@ -44,3 +48,9 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension LoginHomeserver {
|
||||
var supportsRegistration: Bool {
|
||||
loginMode == .oidc || (address == "matrix.org" && registrationHelperURL != nil)
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -5,6 +5,7 @@
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct ServerConfirmationScreen: View {
|
||||
@@ -52,6 +53,7 @@ struct ServerConfirmationScreen: View {
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
.accessibilityIdentifier(A11yIdentifiers.serverConfirmationScreen.continue)
|
||||
.disabled(!context.viewState.canContinue)
|
||||
|
||||
Button { context.send(viewAction: .changeServer) } label: {
|
||||
Text(L10n.screenServerConfirmationChangeServer)
|
||||
|
||||
Reference in New Issue
Block a user