Skip to content

Commit

Permalink
Merge branch 'develop' into feat/text_and_icons_adjustment_project
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanStepanok committed Mar 26, 2024
2 parents a71c8a4 + 513a883 commit de503fd
Show file tree
Hide file tree
Showing 115 changed files with 6,629 additions and 2,625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,45 @@ public enum AuthMethod: Equatable {
public var analyticsValue: String {
switch self {
case .password:
"Password"
"password"
case .socailAuth(let socialAuthMethod):
socialAuthMethod.rawValue
}
}
}

public enum SocialAuthMethod: String {
case facebook = "Facebook"
case google = "Google"
case microsoft = "Microsoft"
case apple = "Apple"
case facebook = "facebook"
case google = "google"
case microsoft = "microsoft"
case apple = "apple"
}

//sourcery: AutoMockable
public protocol AuthorizationAnalytics {
func identify(id: String, username: String, email: String)
func userLogin(method: AuthMethod)
func signUpClicked()
func registerClicked()
func signInClicked()
func userSignInClicked()
func createAccountClicked()
func registrationSuccess()
func registrationSuccess(method: String)
func forgotPasswordClicked()
func resetPasswordClicked(success: Bool)
func resetPasswordClicked()
func resetPassword(success: Bool)
}

#if DEBUG
class AuthorizationAnalyticsMock: AuthorizationAnalytics {
func identify(id: String, username: String, email: String) {}
public func userLogin(method: AuthMethod) {}
public func signUpClicked() {}
public func registerClicked() {}
public func signInClicked() {}
public func userSignInClicked() {}
public func createAccountClicked() {}
public func registrationSuccess() {}
public func registrationSuccess(method: String) {}
public func forgotPasswordClicked() {}
public func resetPasswordClicked(success: Bool) {}
public func resetPasswordClicked() {}
public func resetPassword(success: Bool) {}
}
#endif
205 changes: 104 additions & 101 deletions Authorization/Authorization/Presentation/Login/SignInView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,117 +56,120 @@ public struct SignInView: View {
.padding(.bottom, isHorizontal ? 10 : 40)
.accessibilityIdentifier("logo_image")

ScrollView {
VStack {
VStack(alignment: .leading) {
Text(AuthLocalization.SignIn.logInTitle)
.font(Theme.Fonts.displaySmall)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.bottom, 4)
.accessibilityIdentifier("signin_text")
Text(AuthLocalization.SignIn.welcomeBack)
.font(Theme.Fonts.titleSmall)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.bottom, 20)
.accessibilityIdentifier("welcome_back_text")

Text(AuthLocalization.SignIn.emailOrUsername)
.font(Theme.Fonts.labelLarge)
.foregroundColor(Theme.Colors.textPrimary)
.accessibilityIdentifier("username_text")
TextField(AuthLocalization.SignIn.emailOrUsername, text: $email)
.font(Theme.Fonts.bodyLarge)
.foregroundColor(Theme.Colors.textPrimary)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
.autocapitalization(.none)
.autocorrectionDisabled()
.padding(.all, 14)
.background(
Theme.Shapes.textInputShape
.fill(Theme.Colors.textInputBackground)
)
.overlay(
Theme.Shapes.textInputShape
.stroke(lineWidth: 1)
.fill(Theme.Colors.textInputStroke)
)
.accessibilityIdentifier("username_textfield")

Text(AuthLocalization.SignIn.password)
.font(Theme.Fonts.labelLarge)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.top, 18)
.accessibilityIdentifier("password_text")
SecureField(AuthLocalization.SignIn.password, text: $password)
.font(Theme.Fonts.bodyLarge)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.all, 14)
.background(
Theme.Shapes.textInputShape
.fill(Theme.Colors.textInputBackground)
)
.overlay(
Theme.Shapes.textInputShape
.stroke(lineWidth: 1)
.fill(Theme.Colors.textInputStroke)
)
.accessibilityIdentifier("password_textfield")
HStack {
if !viewModel.config.features.startupScreenEnabled {
Button(CoreLocalization.SignIn.registerBtn) {
viewModel.router.showRegisterScreen(sourceScreen: viewModel.sourceScreen)
GeometryReader { proxy in
ScrollView {
VStack {
VStack(alignment: .leading) {
Text(AuthLocalization.SignIn.logInTitle)
.font(Theme.Fonts.displaySmall)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.bottom, 4)
.accessibilityIdentifier("signin_text")
Text(AuthLocalization.SignIn.welcomeBack)
.font(Theme.Fonts.titleSmall)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.bottom, 20)
.accessibilityIdentifier("welcome_back_text")

Text(AuthLocalization.SignIn.emailOrUsername)
.font(Theme.Fonts.labelLarge)
.foregroundColor(Theme.Colors.textPrimary)
.accessibilityIdentifier("username_text")
TextField(AuthLocalization.SignIn.emailOrUsername, text: $email)
.font(Theme.Fonts.bodyLarge)
.foregroundColor(Theme.Colors.textPrimary)
.keyboardType(.emailAddress)
.textContentType(.emailAddress)
.autocapitalization(.none)
.autocorrectionDisabled()
.padding(.all, 14)
.background(
Theme.Shapes.textInputShape
.fill(Theme.Colors.textInputBackground)
)
.overlay(
Theme.Shapes.textInputShape
.stroke(lineWidth: 1)
.fill(Theme.Colors.textInputStroke)
)
.accessibilityIdentifier("username_textfield")

Text(AuthLocalization.SignIn.password)
.font(Theme.Fonts.labelLarge)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.top, 18)
.accessibilityIdentifier("password_text")
SecureField(AuthLocalization.SignIn.password, text: $password)
.font(Theme.Fonts.bodyLarge)
.foregroundColor(Theme.Colors.textPrimary)
.padding(.all, 14)
.background(
Theme.Shapes.textInputShape
.fill(Theme.Colors.textInputBackground)
)
.overlay(
Theme.Shapes.textInputShape
.stroke(lineWidth: 1)
.fill(Theme.Colors.textInputStroke)
)
.accessibilityIdentifier("password_textfield")
HStack {
if !viewModel.config.features.startupScreenEnabled {
Button(CoreLocalization.SignIn.registerBtn) {
viewModel.router.showRegisterScreen(sourceScreen: viewModel.sourceScreen)
}
.foregroundColor(Theme.Colors.accentColor)
.accessibilityIdentifier("register_button")

Spacer()
}
.foregroundColor(Theme.Colors.accentColor)
.accessibilityIdentifier("register_button")

Spacer()
Button(AuthLocalization.SignIn.forgotPassBtn) {
viewModel.trackForgotPasswordClicked()
viewModel.router.showForgotPasswordScreen()
}
.font(Theme.Fonts.bodyLarge)
.foregroundColor(Theme.Colors.accentXColor)
.padding(.top, 0)
.accessibilityIdentifier("forgot_password_button")
}

Button(AuthLocalization.SignIn.forgotPassBtn) {
viewModel.trackForgotPasswordClicked()
viewModel.router.showForgotPasswordScreen()

if viewModel.isShowProgress {
HStack(alignment: .center) {
ProgressBar(size: 40, lineWidth: 8)
.padding(20)
.accessibilityIdentifier("progressbar")
}.frame(maxWidth: .infinity)
} else {
StyledButton(CoreLocalization.SignIn.logInBtn) {
Task {
await viewModel.login(username: email, password: password)
}
}
.frame(maxWidth: .infinity)
.padding(.top, 40)
.accessibilityIdentifier("signin_button")
}
.font(Theme.Fonts.bodyLarge)
.foregroundColor(Theme.Colors.accentXColor)
.padding(.top, 0)
.accessibilityIdentifier("forgot_password_button")
}

if viewModel.isShowProgress {
HStack(alignment: .center) {
ProgressBar(size: 40, lineWidth: 8)
.padding(20)
.accessibilityIdentifier("progressbar")
}.frame(maxWidth: .infinity)
} else {
StyledButton(CoreLocalization.SignIn.logInBtn) {
Task {
await viewModel.login(username: email, password: password)
if viewModel.socialAuthEnabled {
SocialAuthView(
viewModel: .init(
config: viewModel.config
) { result in
Task { await viewModel.login(with: result) }
}
}
.frame(maxWidth: .infinity)
.padding(.top, 40)
.accessibilityIdentifier("signin_button")
)
}
agreements
Spacer()
}
if viewModel.socialAuthEnabled {
SocialAuthView(
viewModel: .init(
config: viewModel.config
) { result in
Task { await viewModel.login(with: result) }
}
)
}
agreements
Spacer()
.padding(.horizontal, 24)
.padding(.top, 50)
.frameLimit(width: proxy.size.width)
}
.padding(.horizontal, 24)
.padding(.top, 50)
}.roundedBackground(Theme.Colors.loginBackground)
.roundedBackground(Theme.Colors.loginBackground)
.scrollAvoidKeyboard(dismissKeyboardByTap: true)

}
}

// MARK: - Alert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class SignInViewModel: ObservableObject {
errorMessage = AuthLocalization.Error.invalidPasswordLenght
return
}

analytics.userSignInClicked()
isShowProgress = true
do {
let user = try await interactor.login(username: username, password: password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public struct SignUpView: View {
StyledButton(AuthLocalization.SignUp.createAccountBtn) {
viewModel.thirdPartyAuthSuccess = false
Task {
await viewModel.registerUser()
await viewModel.registerUser(authMetod: viewModel.authMethod)
}
viewModel.trackCreateAccountClicked()
}
Expand All @@ -163,7 +163,7 @@ public struct SignUpView: View {
}
.padding(.horizontal, 24)
.padding(.top, 24)

.frameLimit(width: proxy.size.width)
}
.roundedBackground(Theme.Colors.background)
.onRightSwipeGesture {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class SignUpViewModel: ObservableObject {
private let interactor: AuthInteractorProtocol
private let analytics: AuthorizationAnalytics
private let validator: Validator
var authMethod: AuthMethod = .password

public init(
interactor: AuthInteractorProtocol,
Expand Down Expand Up @@ -121,7 +122,7 @@ public class SignUpViewModel: ObservableObject {
private var backend: String?

@MainActor
func registerUser() async {
func registerUser(authMetod: AuthMethod = .password) async {
do {
let validateFields = configureFields()
let errors = try await interactor.validateRegistrationFields(fields: validateFields)
Expand All @@ -132,7 +133,7 @@ public class SignUpViewModel: ObservableObject {
isSocial: externalToken != nil
)
analytics.identify(id: "\(user.id)", username: user.username, email: user.email)
analytics.registrationSuccess()
analytics.registrationSuccess(method: authMetod.analyticsValue)
isShowProgress = false
router.showMainOrWhatsNewScreen(sourceScreen: sourceScreen)

Expand Down Expand Up @@ -198,7 +199,8 @@ public class SignUpViewModel: ObservableObject {
self.backend = backend
thirdPartyAuthSuccess = true
isShowProgress = false
await registerUser()
self.authMethod = authMethod
await registerUser(authMetod: authMethod)
}
}

Expand Down
Loading

0 comments on commit de503fd

Please sign in to comment.