Fix PR remarks

This commit is contained in:
ismailgulek
2022-06-09 11:43:12 +03:00
parent 90bd009226
commit 0a53cc4ac7
8 changed files with 33 additions and 28 deletions

View File

@@ -266,13 +266,7 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc
coordinator.start()
add(childCoordinator: coordinator)
if navigationRouter.modules.isEmpty {
navigationRouter.setRootModule(coordinator, popCompletion: nil)
} else {
navigationRouter.push(coordinator, animated: true) { [weak self] in
self?.remove(childCoordinator: coordinator)
}
}
navigationRouter.setRootModule(coordinator, popCompletion: nil)
}
/// Displays the next view in the flow based on the result from the registration screen.

View File

@@ -53,8 +53,13 @@ class LoginWizard {
/// - password: The password of the account.
/// - initialDeviceName: The initial device name.
/// - deviceID: The device ID, optional. If not provided or nil, the server will generate one.
/// - removeOtherAccounts: If set to true, existing accounts with different user identifiers will be removed.
/// - Returns: An `MXSession` if the login is successful.
func login(login: String, password: String, initialDeviceName: String, deviceID: String? = nil, resetOthers: Bool = false) async throws -> MXSession {
func login(login: String,
password: String,
initialDeviceName: String,
deviceID: String? = nil,
removeOtherAccounts: Bool = false) async throws -> MXSession {
let parameters: LoginPasswordParameters
if MXTools.isEmailAddress(login) {
@@ -70,16 +75,22 @@ class LoginWizard {
}
let credentials = try await client.login(parameters: parameters)
return sessionCreator.createSession(credentials: credentials, client: client, resetOthers: resetOthers)
return sessionCreator.createSession(credentials: credentials,
client: client,
removeOtherAccounts: removeOtherAccounts)
}
/// Exchange a login token to an access token.
/// - Parameter loginToken: A login token, obtained when login has happened in a WebView, using SSO.
/// - Parameters:
/// - token: A login token, obtained when login has happened in a WebView, using SSO.
/// - removeOtherAccounts: If set to true, existing accounts with different user identifiers will be removed.
/// - Returns: An `MXSession` if the login is successful.
func login(with token: String, resetOthers: Bool = false) async throws -> MXSession {
func login(with token: String, removeOtherAccounts: Bool = false) async throws -> MXSession {
let parameters = LoginTokenParameters(token: token)
let credentials = try await client.login(parameters: parameters)
return sessionCreator.createSession(credentials: credentials, client: client, resetOthers: resetOthers)
return sessionCreator.createSession(credentials: credentials,
client: client,
removeOtherAccounts: removeOtherAccounts)
}
// /// Login to the homeserver by sending a custom JsonDict.

View File

@@ -255,7 +255,7 @@ class RegistrationWizard {
do {
let response = try await client.register(parameters: parameters)
let credentials = MXCredentials(loginResponse: response, andDefaultCredentials: client.credentials)
return .success(sessionCreator.createSession(credentials: credentials, client: client, resetOthers: false))
return .success(sessionCreator.createSession(credentials: credentials, client: client, removeOtherAccounts: false))
} catch {
let nsError = error as NSError

View File

@@ -21,9 +21,9 @@ protocol SessionCreatorProtocol {
/// - Parameters:
/// - credentials: The `MXCredentials` for the account.
/// - client: The client that completed the authentication.
/// - resetOthers: Flag to reset other accounts.
/// - removeOtherAccounts: Flag to remove other accounts than the account specified with the `credentials.userId`.
/// - Returns: A new `MXSession` for the account.
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, resetOthers: Bool) -> MXSession
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession
}
/// A struct that provides common functionality to create a new session.
@@ -35,20 +35,23 @@ struct SessionCreator: SessionCreatorProtocol {
self.accountManager = accountManager
}
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, resetOthers: Bool) -> MXSession {
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession {
// Use identity server provided in the client
if credentials.identityServer == nil {
credentials.identityServer = client.identityServer
}
if removeOtherAccounts {
let otherAccounts = accountManager.accounts.filter({ $0.mxCredentials.userId != credentials.userId })
for account in otherAccounts {
accountManager.removeAccount(account, completion: nil)
}
}
if let account = accountManager.account(forUserId: credentials.userId) {
accountManager.hydrateAccount(account, with: credentials)
return account.mxSession
} else {
if resetOthers {
accountManager.logout(completion: nil)
}
let account = MXKAccount(credentials: credentials)
// set identity server of the new account

View File

@@ -181,7 +181,7 @@ final class AuthenticationSoftLogoutCoordinator: Coordinator, Presentable {
password: password,
initialDeviceName: UIDevice.current.initialDisplayName,
deviceID: deviceId,
resetOthers: true)
removeOtherAccounts: true)
guard !Task.isCancelled else { return }
callback?(.success(session: session, password: password))

View File

@@ -23,8 +23,6 @@ struct AuthenticationSoftLogoutScreen: View {
// MARK: Private
@Environment(\.theme) private var theme
@State private var isEditingTextField = false
// MARK: Public
@@ -67,7 +65,7 @@ struct AuthenticationSoftLogoutScreen: View {
Text(VectorL10n.authSoftlogoutSignIn)
.font(theme.fonts.title2B)
.multilineTextAlignment(.center)
.multilineTextAlignment(.leading)
.foregroundColor(theme.colors.primaryContent)
.accessibilityIdentifier("titleLabel")
@@ -152,7 +150,6 @@ struct AuthenticationSoftLogoutScreen: View {
var passwordTextField: some View {
RoundedBorderTextField(placeHolder: VectorL10n.loginPasswordPlaceholder,
text: $viewModel.password,
isFirstResponder: isEditingTextField,
configuration: UIKitTextInputConfiguration(returnKeyType: .done,
isSecureTextEntry: true),
onCommit: login)

View File

@@ -20,7 +20,7 @@ import Foundation
struct MockSessionCreator: SessionCreatorProtocol {
/// Returns a basic session created from the supplied credentials. This prevents the app from setting up the account during tests.
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, resetOthers: Bool) -> MXSession {
func createSession(credentials: MXCredentials, client: AuthenticationRestClient, removeOtherAccounts: Bool) -> MXSession {
let client = MXRestClient(credentials: credentials,
unauthenticatedHandler: { _,_,_,_ in }) // The handler is expected if credentials are set.
return MXSession(matrixRestClient: client)

View File

@@ -29,7 +29,7 @@ class SessionCreatorTests: XCTestCase {
accessToken: "mock_access_token")
let client = MXRestClient(credentials: credentials)
client.identityServer = mockIS
let session = sessionCreator.createSession(credentials: credentials, client: client, resetOthers: false)
let session = sessionCreator.createSession(credentials: credentials, client: client, removeOtherAccounts: false)
XCTAssertEqual(credentials.identityServer, mockIS)
XCTAssertEqual(session.credentials.identityServer, mockIS)