This commit is contained in:
cheykrym 2025-12-04 02:14:34 +03:00
parent 0617d1bd9c
commit 0311e0f5b1
4 changed files with 107 additions and 109 deletions

View File

@ -198,6 +198,9 @@
} }
} }
} }
},
"Yobble Passport" : {
}, },
"Автоудаление аккаунта" : { "Автоудаление аккаунта" : {
"localizations" : { "localizations" : {
@ -285,9 +288,6 @@
}, },
"Введите логин" : { "Введите логин" : {
"comment" : "Логин" "comment" : "Логин"
},
"Введите логин и мы отправим шестизначный код подтверждения." : {
}, },
"Введите пароль" : { "Введите пароль" : {
"comment" : "Пароль\nПоле ввода пароля на приложение" "comment" : "Пароль\nПоле ввода пароля на приложение"
@ -392,7 +392,7 @@
"Всего сессий" : { "Всего сессий" : {
"comment" : "Сводка по количеству сессий" "comment" : "Сводка по количеству сессий"
}, },
"Вход" : { "Вход в аккаунт" : {
}, },
"Вход и защита аккаунта (заглушка)" : { "Вход и защита аккаунта (заглушка)" : {
@ -778,9 +778,6 @@
}, },
"Код дружбы" : { "Код дружбы" : {
"comment" : "Friend code badge" "comment" : "Friend code badge"
},
"Код может прийти по почте, push или в другое подключенное приложение." : {
}, },
"Код отправлен. Аккаунт: @%@" : { "Код отправлен. Аккаунт: @%@" : {
@ -905,6 +902,7 @@
}, },
"Логин" : { "Логин" : {
"comment" : "Логин", "comment" : "Логин",
"extractionState" : "stale",
"localizations" : { "localizations" : {
"en" : { "en" : {
"stringUnit" : { "stringUnit" : {
@ -1777,9 +1775,6 @@
}, },
"Перейдите в раздел \"Настройки > Сменить пароль\" и следуйте инструкциям." : { "Перейдите в раздел \"Настройки > Сменить пароль\" и следуйте инструкциям." : {
"comment" : "FAQ answer: reset password" "comment" : "FAQ answer: reset password"
},
"Перейти к входу по коду" : {
}, },
"По умолчанию это полноценная соцсеть с лентой, историями и подписками. Если нужно только общение без лишнего контента, переключитесь на режим “Только чаты”. Переключить режим можно в любой момент." : { "По умолчанию это полноценная соцсеть с лентой, историями и подписками. Если нужно только общение без лишнего контента, переключитесь на режим “Только чаты”. Переключить режим можно в любой момент." : {
@ -1923,9 +1918,6 @@
}, },
"Получать коды на email при входе" : { "Получать коды на email при входе" : {
"comment" : "Переключатель отправки кодов при входе" "comment" : "Переключатель отправки кодов при входе"
},
"Получить код" : {
}, },
"Получить ответ от команды" : { "Получить ответ от команды" : {
"comment" : "feedback: contact toggle", "comment" : "feedback: contact toggle",

View File

@ -25,7 +25,13 @@ class LoginViewModel: ObservableObject {
@Published var termsErrorMessage: String? @Published var termsErrorMessage: String?
@Published var onboardingDestination: OnboardingDestination? @Published var onboardingDestination: OnboardingDestination?
@Published var loginFlowStep: LoginFlowStep = .passwordlessRequest @Published var loginFlowStep: LoginFlowStep = .passwordlessRequest
@Published var passwordlessLogin: String = "" @Published var passwordlessLogin: String = "" {
didSet {
if passwordlessLogin.count > 32 {
passwordlessLogin = String(passwordlessLogin.prefix(32))
}
}
}
@Published var verificationCode: String = "" { @Published var verificationCode: String = "" {
didSet { didSet {
let filtered = verificationCode let filtered = verificationCode
@ -137,8 +143,13 @@ class LoginViewModel: ObservableObject {
func login() { func login() {
isLoading = true isLoading = true
showError = false showError = false
let trimmedLogin = passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines)
if trimmedLogin != passwordlessLogin {
passwordlessLogin = trimmedLogin
}
username = trimmedLogin
authService.login(username: username, password: password) { [weak self] success, error in authService.login(username: trimmedLogin, password: password) { [weak self] success, error in
DispatchQueue.main.async { DispatchQueue.main.async {
self?.isLoading = false self?.isLoading = false
if success { if success {
@ -178,6 +189,9 @@ class LoginViewModel: ObservableObject {
self.loginFlowStep = .passwordlessVerify self.loginFlowStep = .passwordlessVerify
self.startResendTimer() self.startResendTimer()
} else { } else {
if self.handlePasswordlessRedirect(message: message, login: trimmedLogin) {
return
}
self.errorMessage = message ?? NSLocalizedString("Не удалось отправить код.", comment: "") self.errorMessage = message ?? NSLocalizedString("Не удалось отправить код.", comment: "")
self.showError = true self.showError = true
} }
@ -208,7 +222,7 @@ class LoginViewModel: ObservableObject {
} else { } else {
self.errorMessage = message ?? NSLocalizedString("Проверьте введённый код и попробуйте снова.", comment: "") self.errorMessage = message ?? NSLocalizedString("Проверьте введённый код и попробуйте снова.", comment: "")
self.showError = true self.showError = true
self.verificationCode = "" // self.verificationCode = ""
} }
} }
} }
@ -385,6 +399,26 @@ extension LoginViewModel {
} }
private extension LoginViewModel { private extension LoginViewModel {
func handlePasswordlessRedirect(message: String?, login: String) -> Bool {
guard let message else { return false }
switch message {
case "otp_not_found":
username = login
passwordlessLogin = login
loginFlowStep = .password
return true
case "account_not_found":
username = login
passwordlessLogin = login
hasAcceptedTerms = false
loginFlowStep = .registration
return true
default:
return false
}
}
enum Constants { enum Constants {
static let verificationCodeLength = 6 static let verificationCodeLength = 6
static let defaultResendDelay = 60 static let defaultResendDelay = 60

View File

@ -109,7 +109,7 @@ struct PasswordLoginView: View {
} }
private var isUsernameValid: Bool { private var isUsernameValid: Bool {
LoginViewModel.isLoginValid(viewModel.username) LoginViewModel.isLoginValid(viewModel.passwordlessLogin)
} }
private var isPasswordValid: Bool { private var isPasswordValid: Bool {
@ -151,21 +151,16 @@ struct PasswordLoginView: View {
HStack(spacing: 8) { HStack(spacing: 8) {
Text("@") Text("@")
.foregroundColor(.secondary) .foregroundColor(.secondary)
TextField(NSLocalizedString("Введите логин", comment: ""), text: $viewModel.username) TextField(NSLocalizedString("Введите логин", comment: ""), text: $viewModel.passwordlessLogin)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
.focused($focusedField, equals: .username) .focused($focusedField, equals: .username)
.onChange(of: viewModel.username) { newValue in
if newValue.count > 32 {
viewModel.username = String(newValue.prefix(32))
}
}
} }
.padding() .padding()
.background(Color(.secondarySystemBackground)) .background(Color(.secondarySystemBackground))
.cornerRadius(12) .cornerRadius(12)
if !isUsernameValid && !viewModel.username.isEmpty { if !isUsernameValid && !viewModel.passwordlessLogin.isEmpty {
Text(NSLocalizedString("Неверный логин", comment: "Неверный логин")) Text(NSLocalizedString("Неверный логин", comment: "Неверный логин"))
.foregroundColor(.red) .foregroundColor(.red)
.font(.caption) .font(.caption)
@ -400,22 +395,17 @@ private struct PasswordlessRequestView: View {
var body: some View { var body: some View {
ScrollView(showsIndicators: false) { ScrollView(showsIndicators: false) {
VStack(alignment: .leading, spacing: 24) { VStack(alignment: .leading, spacing: 24) {
LoginTopBar(openLanguageSettings: openLanguageSettings, onShowModePrompt: hideKeyboardAndShowModePrompt) LoginTopBar(openLanguageSettings: openLanguageSettings, onShowModePrompt: hideKeyboardAndShowModePrompt)
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text(NSLocalizedString("Вход", comment: ""))
Text(NSLocalizedString("Yobble Passport", comment: ""))
.font(.largeTitle).bold() .font(.largeTitle).bold()
// Text(NSLocalizedString("Введите логин и мы отправим шестизначный код подтверждения.", comment: ""))
// .foregroundColor(.secondary)
// Text(NSLocalizedString("Введите логин и мы отправим шестизначный код подтверждения.", comment: ""))
// .foregroundColor(.secondary)
} }
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
// Text(NSLocalizedString("Логин", comment: ""))
// .font(.subheadline)
// .foregroundColor(.secondary)
HStack(spacing: 8) { HStack(spacing: 8) {
Text("@") Text("@")
.foregroundColor(.secondary) .foregroundColor(.secondary)
@ -434,11 +424,6 @@ private struct PasswordlessRequestView: View {
.padding() .padding()
.background(Color(.secondarySystemBackground)) .background(Color(.secondarySystemBackground))
.cornerRadius(12) .cornerRadius(12)
if !isLoginValid && !viewModel.passwordlessLogin.isEmpty {
Text(NSLocalizedString("Неверный логин", comment: ""))
.foregroundColor(.red)
.font(.caption)
}
} }
Button { Button {
@ -451,10 +436,6 @@ private struct PasswordlessRequestView: View {
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
.padding() .padding()
} else { } else {
// Text(NSLocalizedString("Получить код", comment: ""))
// .bold()
// .frame(maxWidth: .infinity)
// .padding()
Text(NSLocalizedString("Войти", comment: "")) Text(NSLocalizedString("Войти", comment: ""))
.bold() .bold()
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
@ -478,31 +459,6 @@ private struct PasswordlessRequestView: View {
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
} }
// Button(action: {
// viewModel.hasAcceptedTerms = false
// withAnimation {
// viewModel.showRegistration()
// }
// }) {
// Text(NSLocalizedString("Нет аккаунта? Регистрация", comment: "Регистрация"))
// .foregroundColor(.blue)
// .frame(maxWidth: .infinity)
// }
Button {
withAnimation {
viewModel.showPasswordLogin()
}
} label: {
Text(NSLocalizedString("Войти по паролю", comment: ""))
.font(.body)
.frame(maxWidth: .infinity)
}
.padding(.vertical, 4)
// Text(NSLocalizedString("Код может прийти по почте, push или в другое подключенное приложение.", comment: ""))
// .font(.footnote)
// .foregroundColor(.secondary)
} }
.padding(.vertical, 32) .padding(.vertical, 32)
} }
@ -554,35 +510,55 @@ private struct PasswordlessVerifyView: View {
VStack(alignment: .leading, spacing: 24) { VStack(alignment: .leading, spacing: 24) {
LoginTopBar(openLanguageSettings: openLanguageSettings, onShowModePrompt: hideKeyboardAndShowModePrompt) LoginTopBar(openLanguageSettings: openLanguageSettings, onShowModePrompt: hideKeyboardAndShowModePrompt)
Button {
// focusedField = nil
withAnimation {
viewModel.showPasswordlessRequest()
}
} label: {
HStack(spacing: 6) {
Image(systemName: "arrow.left")
Text(NSLocalizedString("Назад", comment: ""))
}
.font(.footnote)
.foregroundColor(.blue)
}
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text(NSLocalizedString("Введите код", comment: "")) Text(NSLocalizedString("Вход в аккаунт", comment: ""))
.font(.largeTitle).bold() .font(.largeTitle).bold()
Text(String(format: NSLocalizedString("Код отправлен. Аккаунт: @%@", comment: ""), viewModel.passwordlessLogin)) Text(String(format: NSLocalizedString("@%@", comment: ""), viewModel.passwordlessLogin))
.foregroundColor(.secondary) .foregroundColor(.secondary)
// Text(NSLocalizedString("Введите код", comment: ""))
// .font(.largeTitle).bold()
//
// Text(String(format: NSLocalizedString("Код отправлен. Аккаунт: @%@", comment: ""), viewModel.passwordlessLogin))
// .foregroundColor(.secondary)
} }
OTPInputView(code: $viewModel.verificationCode, isFocused: $isCodeFieldFocused) OTPInputView(code: $viewModel.verificationCode, isFocused: $isCodeFieldFocused)
Button { // Button {
withAnimation { // withAnimation {
viewModel.verifyPasswordlessCode() // viewModel.verifyPasswordlessCode()
} // }
} label: { // } label: {
if viewModel.isVerifyingCode { // if viewModel.isVerifyingCode {
ProgressView() // ProgressView()
.frame(maxWidth: .infinity) // .frame(maxWidth: .infinity)
.padding() // .padding()
} else { // } else {
Text(NSLocalizedString("Подтвердить вход", comment: "")) // Text(NSLocalizedString("Подтвердить вход", comment: ""))
.bold() // .bold()
.frame(maxWidth: .infinity) // .frame(maxWidth: .infinity)
.padding() // .padding()
} // }
} // }
.foregroundColor(.white) // .foregroundColor(.white)
.background(viewModel.canVerifyPasswordlessCode ? Color.blue : Color.gray) // .background(viewModel.canVerifyPasswordlessCode ? Color.blue : Color.gray)
.cornerRadius(12) // .cornerRadius(12)
.disabled(!viewModel.canVerifyPasswordlessCode) // .disabled(!viewModel.canVerifyPasswordlessCode)
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text(NSLocalizedString("Не получили код?", comment: "")) Text(NSLocalizedString("Не получили код?", comment: ""))
@ -609,14 +585,14 @@ private struct PasswordlessVerifyView: View {
Divider() Divider()
Button { // Button {
withAnimation { // withAnimation {
viewModel.backToPasswordlessRequest() // viewModel.backToPasswordlessRequest()
} // }
} label: { // } label: {
Text(NSLocalizedString("Изменить способ входа", comment: "")) // Text(NSLocalizedString("Изменить способ входа", comment: ""))
.frame(maxWidth: .infinity) // .frame(maxWidth: .infinity)
} // }
Button { Button {
withAnimation { withAnimation {
@ -866,7 +842,7 @@ private struct ForgotPasswordInfoView: View {
.foregroundColor(.secondary) .foregroundColor(.secondary)
Button(action: onUseCode) { Button(action: onUseCode) {
Text(NSLocalizedString("Перейти к входу по коду", comment: "")) Text(NSLocalizedString("Войти", comment: ""))
.foregroundColor(.white) .foregroundColor(.white)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
.padding() .padding()

View File

@ -11,7 +11,6 @@ struct RegistrationView: View {
@ObservedObject var viewModel: LoginViewModel @ObservedObject var viewModel: LoginViewModel
let onShowModePrompt: (() -> Void)? let onShowModePrompt: (() -> Void)?
@State private var username: String = ""
@State private var password: String = "" @State private var password: String = ""
@State private var confirmPassword: String = "" @State private var confirmPassword: String = ""
@State private var inviteCode: String = "" @State private var inviteCode: String = ""
@ -32,7 +31,7 @@ struct RegistrationView: View {
private var isUsernameValid: Bool { private var isUsernameValid: Bool {
let pattern = "^[A-Za-z0-9_]{3,32}$" let pattern = "^[A-Za-z0-9_]{3,32}$"
return username.range(of: pattern, options: .regularExpression) != nil return viewModel.passwordlessLogin.range(of: pattern, options: .regularExpression) != nil
} }
private var isPasswordValid: Bool { private var isPasswordValid: Bool {
@ -78,21 +77,16 @@ struct RegistrationView: View {
HStack(spacing: 8) { HStack(spacing: 8) {
Text("@") Text("@")
.foregroundColor(.secondary) .foregroundColor(.secondary)
TextField(NSLocalizedString("Введите логин", comment: "Логин"), text: $username) TextField(NSLocalizedString("Введите логин", comment: "Логин"), text: $viewModel.passwordlessLogin)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
.focused($focusedField, equals: .username) .focused($focusedField, equals: .username)
.onChange(of: username) { newValue in
if newValue.count > 32 {
username = String(newValue.prefix(32))
}
}
} }
.padding() .padding()
.background(Color(.secondarySystemBackground)) .background(Color(.secondarySystemBackground))
.cornerRadius(12) .cornerRadius(12)
if !isUsernameValid && !username.isEmpty { if !isUsernameValid && !viewModel.passwordlessLogin.isEmpty {
Text(NSLocalizedString("Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)", comment: "")) Text(NSLocalizedString("Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)", comment: ""))
.foregroundColor(.red) .foregroundColor(.red)
.font(.caption) .font(.caption)
@ -207,7 +201,9 @@ struct RegistrationView: View {
private func registerUser() { private func registerUser() {
isLoading = true isLoading = true
errorMessage = "" errorMessage = ""
viewModel.registerUser(username: username, password: password, invite: inviteCode.isEmpty ? nil : inviteCode) { success, message in let trimmedLogin = viewModel.passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines)
viewModel.passwordlessLogin = trimmedLogin
viewModel.registerUser(username: trimmedLogin, password: password, invite: inviteCode.isEmpty ? nil : inviteCode) { success, message in
isLoading = false isLoading = false
if success { if success {
viewModel.hasAcceptedTerms = false viewModel.hasAcceptedTerms = false