Address PR comments.

Log errors before throwing.
Remove white colour.
Remove AuthenticationCoordinatorState added during rebase.
This commit is contained in:
Doug
2022-05-03 10:55:43 +01:00
committed by Doug
parent 95d1a2a39e
commit 33eb847ba3
10 changed files with 18 additions and 52 deletions

View File

@@ -46,8 +46,6 @@ public struct ColorValues: Colors {
public let background: UIColor
public let white: UIColor
public let ems: UIColor
public let namesAndAvatars: [UIColor]

View File

@@ -64,9 +64,6 @@ public protocol Colors {
/// Background UI color
var background: ColorType { get }
/// Global color: The color white.
var white: ColorType { get }
/// Global color: The EMS brand's purple colour.
var ems: ColorType { get }

View File

@@ -47,8 +47,6 @@ public struct ColorSwiftUI: Colors {
public let background: Color
public var white: Color
public var ems: Color
public let namesAndAvatars: [Color]
@@ -66,7 +64,6 @@ public struct ColorSwiftUI: Colors {
tile = Color(values.tile)
navigation = Color(values.navigation)
background = Color(values.background)
white = Color(values.white)
ems = Color(values.ems)
namesAndAvatars = values.namesAndAvatars.map({ Color($0) })
}

View File

@@ -33,7 +33,6 @@ public class DarkColors {
tile: UIColor(rgb:0x394049),
navigation: UIColor(rgb:0x21262C),
background: UIColor(rgb:0x15191E),
white: UIColor(rgb: 0xFFFFFF),
ems: UIColor(rgb: 0x7E69FF),
namesAndAvatars: [
UIColor(rgb:0x368BD6),

View File

@@ -34,7 +34,6 @@ public class LightColors {
tile: UIColor(rgb:0xF3F8FD),
navigation: UIColor(rgb:0xF4F6FA),
background: UIColor(rgb:0xFFFFFF),
white: UIColor(rgb: 0xFFFFFF),
ems: UIColor(rgb: 0x7E69FF),
namesAndAvatars: [
UIColor(rgb:0x368BD6),

View File

@@ -114,6 +114,7 @@ final class AuthenticationCoordinator: NSObject, AuthenticationCoordinatorProtoc
// MARK: - Private
/// Presents an alert on top of the navigation router, using the supplied error's `localizedDescription`.
@MainActor func displayError(_ error: Error) {
let alert = UIAlertController(title: VectorL10n.error,
message: error.localizedDescription,

View File

@@ -1,41 +0,0 @@
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import MatrixSDK
@available(iOS 14.0, *)
struct AuthenticationCoordinatorState {
// MARK: User choices
// var serverType: ServerType = .unknown
// var signMode: SignMode = .unknown
var resetPasswordEmail: String?
/// The homeserver address as returned by the server.
var homeserverAddress: String?
/// The homeserver address as input by the user (it can differ to the well-known request).
var homeserverAddressFromUser: String?
/// For SSO session recovery
var deviceId: String?
// MARK: Network result
var loginMode: LoginMode = .unknown
/// Supported types for the login.
var loginModeSupportedTypes = [MXLoginFlow]()
var knownCustomHomeServersUrls = [String]()
var isForceLoginFallbackEnabled = false
}

View File

@@ -178,6 +178,7 @@ class AuthenticationService: NSObject {
let homeserverAddress = HomeserverAddress.sanitized(homeserverAddress)
guard var homeserverURL = URL(string: homeserverAddress) else {
MXLog.error("[AuthenticationService] Unable to create a URL from the supplied homeserver address when calling loginFlow.")
throw AuthenticationError.invalidHomeserver
}
@@ -203,7 +204,10 @@ class AuthenticationService: NSObject {
/// 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 -> LoginFlowResult {
guard let client = session.matrixRestClient else { throw AuthenticationError.missingMXRestClient }
guard let client = session.matrixRestClient else {
MXLog.error("[AuthenticationService] loginFlow called on a session that doesn't have a matrixRestClient.")
throw AuthenticationError.missingMXRestClient
}
let state = AuthenticationState(flow: .login, homeserverAddress: client.homeserver)
let loginFlow = try await getLoginFlowResult(client: session.matrixRestClient)

View File

@@ -47,6 +47,7 @@ struct RegistrationParameters: Codable {
let jsonData = try JSONEncoder().encode(self)
let object = try JSONSerialization.jsonObject(with: jsonData)
guard let dictionary = object as? [String: Any] else {
MXLog.error("[RegistrationParameters] dictionary: Unexpected type decoded \(type(of: object)). Expected a Dictionary.")
throw AuthenticationError.dictionaryError
}

View File

@@ -81,6 +81,7 @@ class RegistrationWizard {
} catch {
// Map M_FORBIDDEN into a registration error.
guard let mxError = MXError(nsError: error), mxError.errcode == kMXErrCodeStringForbidden else { throw error }
MXLog.warning("[RegistrationWizard] Registration is disabled for the selected server.")
throw RegistrationError.registrationDisabled
}
}
@@ -112,6 +113,7 @@ class RegistrationWizard {
/// - Parameter response: The response from ReCaptcha
func performReCaptcha(response: String) async throws -> RegistrationResult {
guard let session = state.currentSession else {
MXLog.error("[RegistrationWizard] performReCaptcha: Missing authentication session, createAccount hasn't been called.")
throw RegistrationError.createAccountNotCalled
}
@@ -122,6 +124,7 @@ class RegistrationWizard {
/// Perform the "m.login.terms" stage.
func acceptTerms() async throws -> RegistrationResult {
guard let session = state.currentSession else {
MXLog.error("[RegistrationWizard] acceptTerms: Missing authentication session, createAccount hasn't been called.")
throw RegistrationError.createAccountNotCalled
}
@@ -132,6 +135,7 @@ class RegistrationWizard {
/// Perform the "m.login.dummy" stage.
func dummy() async throws -> RegistrationResult {
guard let session = state.currentSession else {
MXLog.error("[RegistrationWizard] dummy: Missing authentication session, createAccount hasn't been called.")
throw RegistrationError.createAccountNotCalled
}
@@ -151,6 +155,7 @@ class RegistrationWizard {
/// Ask the homeserver to send again the current threePID (email or msisdn).
func sendAgainThreePID() async throws -> RegistrationResult {
guard let threePID = state.currentThreePIDData?.threePID else {
MXLog.error("[RegistrationWizard] sendAgainThreePID: Missing authentication session, createAccount hasn't been called.")
throw RegistrationError.createAccountNotCalled
}
return try await sendThreePID(threePID: threePID)
@@ -168,6 +173,7 @@ class RegistrationWizard {
func checkIfEmailHasBeenValidated(delay: TimeInterval) async throws -> RegistrationResult {
MXLog.failure("The delay on this method is no longer available. Move this to the object handling the polling.")
guard let parameters = state.currentThreePIDData?.registrationParameters else {
MXLog.error("[RegistrationWizard] checkIfEmailHasBeenValidated: The current 3pid data hasn't been stored in the state.")
throw RegistrationError.missingThreePIDData
}
@@ -178,10 +184,12 @@ class RegistrationWizard {
private func validateThreePid(code: String) async throws -> RegistrationResult {
guard let threePIDData = state.currentThreePIDData else {
MXLog.error("[RegistrationWizard] validateThreePid: There is no third party ID data stored in the state.")
throw RegistrationError.missingThreePIDData
}
guard let submitURL = threePIDData.registrationResponse.submitURL else {
MXLog.error("[RegistrationWizard] validateThreePid: The third party ID data doesn't contain a submitURL.")
throw RegistrationError.missingThreePIDURL
}
@@ -192,9 +200,11 @@ class RegistrationWizard {
#warning("Seems odd to pass a nil baseURL and then the url as the path, yet this is how MXK3PID works")
guard let httpClient = MXHTTPClient(baseURL: nil, andOnUnrecognizedCertificateBlock: nil) else {
MXLog.error("[RegistrationWizard] validateThreePid: Failed to create an MXHTTPClient.")
throw RegistrationError.threePIDClientFailure
}
guard try await httpClient.validateThreePIDCode(submitURL: submitURL, validationBody: validationBody) else {
MXLog.error("[RegistrationWizard] validateThreePid: Third party ID validation failed.")
throw RegistrationError.threePIDValidationFailure
}
@@ -205,6 +215,7 @@ class RegistrationWizard {
private func sendThreePID(threePID: RegisterThreePID) async throws -> RegistrationResult {
guard let session = state.currentSession else {
MXLog.error("[RegistrationWizard] sendThreePID: Missing authentication session, createAccount hasn't been called.")
throw RegistrationError.createAccountNotCalled
}