Skip to content

Commit

Permalink
Merge pull request #1184 from HedvigInsurance/feature/remove-zignSec
Browse files Browse the repository at this point in the history
GEN-1705: Feature/remove zign sec
  • Loading branch information
sladan-hedvig authored Jan 19, 2024
2 parents d5ad9d6 + b160e66 commit 6a19750
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 344 deletions.
21 changes: 15 additions & 6 deletions Projects/App/Sources/Journeys/LoginJourney.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension AppJourney {
if case .bankIdQrResultAction(.loggedIn) = action {
loginCompleted
} else if case .bankIdQrResultAction(action: .emailLogin) = action {
otp(style: .detented(.large, modally: false))
otpEmail(style: .detented(.large, modally: false))
} else if case .bankIdQrResultAction(action: .close) = action {
DismissJourney()
} else if case let .loginFailure(message) = action {
Expand Down Expand Up @@ -72,8 +72,19 @@ extension AppJourney {
.mapJourneyDismissToCancel
}

fileprivate static func otp(style: PresentationStyle = .detented(.large)) -> some JourneyPresentation {
OTPAuthJourney.login { next in
fileprivate static func otpEmail(style: PresentationStyle = .detented(.large)) -> some JourneyPresentation {
OTPAuthJourney.loginEmail { next in
switch next {
case .success:
loginCompleted
}
}
.setStyle(style)
.withDismissButton
}

fileprivate static func otpSSN(style: PresentationStyle = .detented(.large)) -> some JourneyPresentation {
OTPAuthJourney.loginSSN { next in
switch next {
case .success:
loginCompleted
Expand All @@ -90,9 +101,7 @@ extension AppJourney {
case .sweden:
bankIDSweden
case .norway, .denmark:
ZignsecAuthJourney.login {
loginCompleted
}
otpSSN()
}
}
.onDismiss {
Expand Down
26 changes: 25 additions & 1 deletion Projects/Authentication/Sources/OTP/OTPAuthJourney.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum OTPAuthJourneyNext {
}

public struct OTPAuthJourney {
public static func login<Next: JourneyPresentation>(
public static func loginEmail<Next: JourneyPresentation>(
@JourneyBuilder _ next: @escaping (_ next: OTPAuthJourneyNext) -> Next
) -> some JourneyPresentation {
HostingJourney(
Expand All @@ -33,4 +33,28 @@ public struct OTPAuthJourney {
store.send(.otpStateAction(action: .reset))
}
}

public static func loginSSN<Next: JourneyPresentation>(
@JourneyBuilder _ next: @escaping (_ next: OTPAuthJourneyNext) -> Next
) -> some JourneyPresentation {
HostingJourney(
AuthenticationStore.self,
rootView: OTPSSNEntry()
) { action in
if case .navigationAction(action: .otpCode) = action {
HostingJourney(
AuthenticationStore.self,
rootView: OTPCodeEntry()
) { action in
if case .navigationAction(action: .authSuccess) = action {
next(.success).hidesBackButton
}
}
}
}
.onPresent {
let store: AuthenticationStore = globalPresentableStoreContainer.get()
store.send(.otpStateAction(action: .reset))
}
}
}
2 changes: 1 addition & 1 deletion Projects/Authentication/Sources/OTP/OTPCodeEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct OTPCodeEntry: View {
.frame(maxWidth: .infinity, alignment: .leading)
ReadOTPState { state in
hText(
L10n.Login.Subtitle.verificationCodeEmail(state.email),
L10n.Login.Subtitle.verificationCodeEmail(state.email ?? L10n.authOtpYourEmail),
style: .body
)
}
Expand Down
96 changes: 91 additions & 5 deletions Projects/Authentication/Sources/OTP/OTPEmailEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public struct OTPEmailEntry: View {
}

func onSubmit() {
guard emailMasking.isValid(text: store.state.otpState.email) else {
guard emailMasking.isValid(text: store.state.otpState.email ?? "") else {
return
}

self.focusEmailField = false
store.send(.otpStateAction(action: .setLoading(isLoading: true)))
store.send(.otpStateAction(action: .submitEmail))
store.send(.otpStateAction(action: .submitOtpData))
}

public var body: some View {
Expand All @@ -38,7 +38,7 @@ public struct OTPEmailEntry: View {
value: Binding(
AuthenticationStore.self,
getter: { state in
state.otpState.email
state.otpState.email ?? ""
},
setter: { email in
.otpStateAction(action: .setEmail(email: email))
Expand All @@ -48,7 +48,7 @@ public struct OTPEmailEntry: View {
.focused($focusEmailField, equals: true) {
onSubmit()
}
.hTextFieldError(state.emailErrorMessage)
.hTextFieldError(state.otpInputErrorMessage)
}
.presentableStoreLensAnimation(.default)
}
Expand All @@ -64,7 +64,7 @@ public struct OTPEmailEntry: View {
}
.hButtonIsLoading(state.isLoading)
}
.disabled(!emailMasking.isValid(text: state.email))
.disabled(!emailMasking.isValid(text: state.email ?? ""))
}
.presentableStoreLensAnimation(.default)
}
Expand All @@ -74,3 +74,89 @@ public struct OTPEmailEntry: View {
}
}
}

public struct OTPSSNEntry: View {
public init() {}

@PresentableStore var store: AuthenticationStore
@hTextFieldFocusState var focusPersonalNumberField = true

var masking: Masking {
switch Localization.Locale.currentLocale.market {
case .dk:
return Masking(type: .danishPersonalNumber)
case .no:
return Masking(type: .norwegianPersonalNumber)
default:
return Masking(type: .none)
}
}

func onSubmit() {
guard masking.isValid(text: store.state.otpState.personalNumber ?? "") else {
return
}

store.send(.cancel)

self.focusPersonalNumberField = false
store.send(.otpStateAction(action: .setLoading(isLoading: true)))
store.send(.otpStateAction(action: .submitOtpData))
}

public var body: some View {
hForm {
hSection {
VStack(spacing: 50) {
hText(
L10n.zignsecLoginScreenTitle,
style: .title1
)
.frame(maxWidth: .infinity, alignment: .leading)

ReadOTPState { state in
hTextField(
masking: masking,
value: Binding(
AuthenticationStore.self,
getter: { state in
state.otpState.personalNumber ?? ""
},
setter: { personalNumber in
.otpStateAction(action: .setPersonalNumber(personalNumber: personalNumber))
}
)
)
.focused($focusPersonalNumberField, equals: true) {
onSubmit()
}
.hTextFieldError(state.otpInputErrorMessage)
}
.presentableStoreLensAnimation(.default)
}
}
}
.hFormAttachToBottom {
ReadOTPState { state in
hSection {
hButton.LargeButton(type: .primary) {
onSubmit()
} content: {
hText(L10n.Login.continueButton)
}
.hButtonIsLoading(state.isLoading)
}
.disabled(!masking.isValid(text: state.personalNumber ?? ""))
}
.presentableStoreLensAnimation(.default)
}
.sectionContainerStyle(.transparent)
.onAppear {
self.focusPersonalNumberField = true
}
}
}

#Preview{
OTPSSNEntry()
}
16 changes: 3 additions & 13 deletions Projects/Authentication/Sources/Store/AuthenticationAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ public enum OTPStateAction: ActionProtocol {
case verifyCode
case setLoading(isLoading: Bool)
case setCodeError(message: String?)
case setEmailError(message: String?)
case setEmail(email: String)
case setPersonalNumber(personalNumber: String)
case setOtpInputError(message: String?)
case startSession(verifyUrl: URL, resendUrl: URL)
case submitEmail
case submitOtpData
case reset
case resendCode
case showResentToast
Expand Down Expand Up @@ -40,21 +41,11 @@ public enum SEBankIDStateAction: ActionProtocol {
case updateWith(autoStartToken: String)
}

public enum ZignsecStateAction: ActionProtocol {
case reset
case setIsLoading(isLoading: Bool)
case setPersonalNumber(personalNumber: String)
case setWebviewUrl(url: URL)
case startSession(personalNumber: String)
case setCredentialError(error: Bool)
}

enum LoginError: Error {
case failed
}

public enum AuthenticationAction: ActionProtocol {
case setStatus(text: String?)
case exchange(code: String)
case impersonate(code: String)
case cancel
Expand All @@ -65,7 +56,6 @@ public enum AuthenticationAction: ActionProtocol {
case observeLoginStatus(url: URL)
case otpStateAction(action: OTPStateAction)
case seBankIDStateAction(action: SEBankIDStateAction)
case zignsecStateAction(action: ZignsecStateAction)
case navigationAction(action: AuthenticationNavigationAction)
case bankIdQrResultAction(action: BankIDLoginQRResult)
}
16 changes: 3 additions & 13 deletions Projects/Authentication/Sources/Store/AuthenticationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ struct OTPState: StateProtocol {
var verifyUrl: URL? = nil
var code: String = ""
var codeErrorMessage: String? = nil
var emailErrorMessage: String? = nil
var email: String = ""
var otpInputErrorMessage: String? = nil
var email: String? = nil
var personalNumber: String? = nil
var canResendAt: Date? = nil

public init() {}
Expand All @@ -21,20 +22,9 @@ struct SEBankIDState: StateProtocol {
public init() {}
}

struct ZignsecState: StateProtocol {
var isLoading: Bool = false
var personalNumber: String = ""
var webviewUrl: URL? = nil
var credentialError: Bool = false

public init() {}
}

public struct AuthenticationState: StateProtocol {
var statusText: String? = nil
var otpState = OTPState()
@Transient(defaultValue: SEBankIDState()) var seBankIDState
var zignsecState = ZignsecState()
@Transient(defaultValue: false) var loginHasFailed: Bool

public init() {}
Expand Down
Loading

0 comments on commit 6a19750

Please sign in to comment.