diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index d30598320..e3766c7b0 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -121,7 +121,7 @@ "onboarding_congratulations_title" = "Congratulations!"; /* The placeholder string contains the user's matrix ID */ -"onboarding_congratulations_message" = "Your account %@ has been created."; +"onboarding_congratulations_message" = "Your account %@ has been created"; "onboarding_congratulations_personalize_button" = "Personalise profile"; "onboarding_congratulations_home_button" = "Take me home"; @@ -139,7 +139,7 @@ "onboarding_avatar_accessibility_label" = "Profile picture"; "onboarding_celebration_title" = "Looking good!"; -"onboarding_celebration_message" = "Head to settings anytime to update your profile."; +"onboarding_celebration_message" = "Head to settings anytime to update your profile"; "onboarding_celebration_button" = "Let's go"; // MARK: Authentication diff --git a/Riot/Generated/Strings.swift b/Riot/Generated/Strings.swift index 86b87d7dc..f3bed0f26 100644 --- a/Riot/Generated/Strings.swift +++ b/Riot/Generated/Strings.swift @@ -4127,7 +4127,7 @@ public class VectorL10n: NSObject { public static var onboardingCelebrationButton: String { return VectorL10n.tr("Vector", "onboarding_celebration_button") } - /// Head to settings anytime to update your profile. + /// Head to settings anytime to update your profile public static var onboardingCelebrationMessage: String { return VectorL10n.tr("Vector", "onboarding_celebration_message") } @@ -4139,7 +4139,7 @@ public class VectorL10n: NSObject { public static var onboardingCongratulationsHomeButton: String { return VectorL10n.tr("Vector", "onboarding_congratulations_home_button") } - /// Your account %@ has been created. + /// Your account %@ has been created public static func onboardingCongratulationsMessage(_ p1: String) -> String { return VectorL10n.tr("Vector", "onboarding_congratulations_message", p1) } diff --git a/Riot/Modules/Onboarding/OnboardingCoordinator.swift b/Riot/Modules/Onboarding/OnboardingCoordinator.swift index ce40cd3c5..3d89c3579 100644 --- a/Riot/Modules/Onboarding/OnboardingCoordinator.swift +++ b/Riot/Modules/Onboarding/OnboardingCoordinator.swift @@ -566,6 +566,9 @@ final class OnboardingCoordinator: NSObject, OnboardingCoordinatorProtocol { trackSignup() completion?() + + // Reset the authentication service back to using matrix.org + authenticationService.reset(useDefaultServer: true) } /// Sends a signup event to the Analytics class if onboarding has completed via the register flow. diff --git a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/AuthenticationService.swift b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/AuthenticationService.swift index 695da631b..0ef46245d 100644 --- a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/AuthenticationService.swift +++ b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/AuthenticationService.swift @@ -174,13 +174,14 @@ class AuthenticationService: NSObject { } /// Reset the service to a fresh state. - func reset() { + /// - Parameter useDefaultServer: Pass `true` to revert back to the one in `BuildSettings`, otherwise the current homeserver will be kept. + func reset(useDefaultServer: Bool = false) { loginWizard = nil registrationWizard = nil softLogoutCredentials = nil // The previously used homeserver is re-used as `startFlow` will be called again a replace it anyway. - let address = state.homeserver.addressFromUser ?? state.homeserver.address + let address = useDefaultServer ? BuildSettings.serverConfigDefaultHomeserverUrlString : state.homeserver.addressFromUser ?? state.homeserver.address let identityServer = state.identityServer self.state = AuthenticationState(flow: .login, homeserverAddress: address, @@ -196,27 +197,6 @@ class AuthenticationService: NSObject { delegate?.authenticationService(self, didReceive: token, with: transactionID) ?? false } -// /// Perform a well-known request, using the domain from the matrixId -// func getWellKnownData(matrixId: String, -// homeServerConnectionConfig: HomeServerConnectionConfig?) async -> WellknownResult { -// -// } -// -// /// Authenticate with a matrixId and a password -// /// Usually call this after a successful call to getWellKnownData() -// /// - Parameter homeServerConnectionConfig the information about the homeserver and other configuration -// /// - Parameter matrixId the matrixId of the user -// /// - Parameter password the password of the account -// /// - Parameter initialDeviceName the initial device name -// /// - Parameter deviceId the device id, optional. If not provided or null, the server will generate one. -// func directAuthentication(homeServerConnectionConfig: HomeServerConnectionConfig, -// matrixId: String, -// password: String, -// initialDeviceName: String, -// deviceId: String? = nil) async -> MXSession { -// -// } - // MARK: - Private /// Query the supported login flows for the supplied homeserver. diff --git a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift index 3871e720f..f56319f37 100644 --- a/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift +++ b/RiotSwiftUI/Modules/Authentication/Common/Service/MatrixSDK/LoginWizard.swift @@ -15,6 +15,7 @@ // import Foundation +import libPhoneNumber_iOS /// Set of methods to be able to login to an existing account on a homeserver. /// @@ -42,11 +43,6 @@ class LoginWizard { self.state = State() } -// /// Get some information about a matrixId: displayName and avatar url -// func profileInfo(for matrixID: String) async -> LoginProfileInfo { -// -// } - /// Login to the homeserver. /// - Parameters: /// - login: The login field. Can be a user name, or a msisdn (email or phone number) associated to the account. @@ -67,6 +63,13 @@ class LoginWizard { password: password, deviceDisplayName: initialDeviceName, deviceID: deviceID) + } else if let number = try? NBPhoneNumberUtil.sharedInstance().parse(login, defaultRegion: nil), + NBPhoneNumberUtil.sharedInstance().isValidNumber(number) { + let msisdn = login.replacingOccurrences(of: "+", with: "") + parameters = LoginPasswordParameters(id: .thirdParty(medium: .msisdn, address: msisdn), + password: password, + deviceDisplayName: initialDeviceName, + deviceID: deviceID) } else { parameters = LoginPasswordParameters(id: .user(login), password: password, @@ -92,12 +95,6 @@ class LoginWizard { client: client, removeOtherAccounts: removeOtherAccounts) } - -// /// Login to the homeserver by sending a custom JsonDict. -// /// The data should contain at least one entry `type` with a String value. -// func loginCustom(data: Codable) async -> MXSession { -// -// } /// Ask the homeserver to reset the user password. The password will not be /// reset until `resetPasswordMailConfirmed` is successfully called. diff --git a/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift b/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift index 97d3a42ca..080917097 100644 --- a/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift +++ b/RiotSwiftUI/Modules/Authentication/Login/Coordinator/AuthenticationLoginCoordinator.swift @@ -195,8 +195,8 @@ final class AuthenticationLoginCoordinator: Coordinator, Presentable { @MainActor private func parseUsername(_ username: String) { guard MXTools.isMatrixUserIdentifier(username) else { return } - let domain = username.split(separator: ":")[1] - let homeserverAddress = HomeserverAddress.sanitized(String(domain)) + let domain = username.components(separatedBy: ":")[1] + let homeserverAddress = HomeserverAddress.sanitized(domain) startLoading(isInteractionBlocking: false) diff --git a/RiotSwiftUI/Modules/Authentication/Login/Test/Unit/AuthenticationLoginViewModelTests.swift b/RiotSwiftUI/Modules/Authentication/Login/Test/Unit/AuthenticationLoginViewModelTests.swift index 013eb0ec7..dde66c2fb 100644 --- a/RiotSwiftUI/Modules/Authentication/Login/Test/Unit/AuthenticationLoginViewModelTests.swift +++ b/RiotSwiftUI/Modules/Authentication/Login/Test/Unit/AuthenticationLoginViewModelTests.swift @@ -96,6 +96,7 @@ class AuthenticationLoginViewModelTests: XCTestCase { context.username = "bob" context.password = "12345678" XCTAssertTrue(context.viewState.hasValidCredentials, "The credentials should be valid.") + XCTAssertTrue(context.viewState.canSubmit, "The form should be valid to submit.") XCTAssertFalse(context.viewState.isLoading, "The view shouldn't start in a loading state.") // When updating the view model whilst loading a homeserver. @@ -103,12 +104,14 @@ class AuthenticationLoginViewModelTests: XCTestCase { // Then the view state should reflect that the homeserver is loading. XCTAssertTrue(context.viewState.isLoading, "The view should now be in a loading state.") + XCTAssertFalse(context.viewState.canSubmit, "The form should be blocked from submission.") // When updating the view model after loading a homeserver. viewModel.update(isLoading: false) // Then the view state should reflect that the homeserver is now loaded. XCTAssertFalse(context.viewState.isLoading, "The view should be back in a loaded state.") + XCTAssertTrue(context.viewState.canSubmit, "The form should once again be valid to submit.") } @MainActor func testFallbackServer() { diff --git a/RiotSwiftUI/Modules/Authentication/ReCaptcha/View/AuthenticationReCaptchaWebView.swift b/RiotSwiftUI/Modules/Authentication/ReCaptcha/View/AuthenticationReCaptchaWebView.swift index f4a895738..fbd000cb5 100644 --- a/RiotSwiftUI/Modules/Authentication/ReCaptcha/View/AuthenticationReCaptchaWebView.swift +++ b/RiotSwiftUI/Modules/Authentication/ReCaptcha/View/AuthenticationReCaptchaWebView.swift @@ -92,7 +92,7 @@ struct AuthenticationRecaptchaWebView: UIViewRepresentable { """ - +