Compare commits

...

3 Commits

Author SHA1 Message Date
cd67c350b4 patch 2025-12-03 09:05:16 +03:00
bbe6a8a3e4 patch 2025-12-03 09:01:01 +03:00
8712c7ea22 change name placeholder 2025-12-03 08:51:35 +03:00
4 changed files with 76 additions and 49 deletions

View File

@ -6,6 +6,9 @@
}, },
"(без текста)" : { "(без текста)" : {
},
"@" : {
}, },
"@%@" : { "@%@" : {
"localizations" : { "localizations" : {
@ -282,9 +285,6 @@
}, },
"Введите логин и мы отправим шестизначный код подтверждения." : { "Введите логин и мы отправим шестизначный код подтверждения." : {
},
"Введите логин." : {
}, },
"Введите пароль" : { "Введите пароль" : {
"comment" : "Пароль\nПоле ввода пароля на приложение" "comment" : "Пароль\nПоле ввода пароля на приложение"
@ -2494,7 +2494,7 @@
"Сохранить пароль" : { "Сохранить пароль" : {
"comment" : "Кнопка сохранения пароля на приложение" "comment" : "Кнопка сохранения пароля на приложение"
}, },
"Соцсеть" : { "Соцсеть (готово 10%)" : {
}, },
"Спасибо! Мы получили ваш отзыв" : { "Спасибо! Мы получили ваш отзыв" : {
@ -2596,7 +2596,7 @@
} }
} }
}, },
"Только чаты" : { "Только чаты (готово 60%)" : {
}, },
"Ты шо ебанутый? А ниче тот факт что новый пароль должен отличаться от старого." : { "Ты шо ебанутый? А ниче тот факт что новый пароль должен отличаться от старого." : {

View File

@ -155,14 +155,14 @@ class LoginViewModel: ObservableObject {
} }
func requestPasswordlessCode() { func requestPasswordlessCode() {
let trimmedLogin = passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines) guard LoginViewModel.isLoginValid(passwordlessLogin) else {
errorMessage = NSLocalizedString("Неверный логин", comment: "")
guard !trimmedLogin.isEmpty else {
errorMessage = NSLocalizedString("Введите логин.", comment: "")
showError = true showError = true
return return
} }
let trimmedLogin = passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines)
isSendingCode = true isSendingCode = true
showError = false showError = false
@ -369,12 +369,19 @@ extension LoginViewModel {
} }
var canRequestPasswordlessCode: Bool { var canRequestPasswordlessCode: Bool {
!passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && !isSendingCode LoginViewModel.isLoginValid(passwordlessLogin) && !isSendingCode
} }
var canVerifyPasswordlessCode: Bool { var canVerifyPasswordlessCode: Bool {
isVerificationCodeComplete && !isVerifyingCode isVerificationCodeComplete && !isVerifyingCode
} }
static func isLoginValid(_ login: String) -> Bool {
let trimmed = login.trimmingCharacters(in: .whitespacesAndNewlines)
guard trimmed == login else { return false }
let pattern = "^[A-Za-z0-9_]{3,32}$"
return trimmed.range(of: pattern, options: .regularExpression) != nil
}
} }
private extension LoginViewModel { private extension LoginViewModel {

View File

@ -109,8 +109,7 @@ struct PasswordLoginView: View {
} }
private var isUsernameValid: Bool { private var isUsernameValid: Bool {
let pattern = "^[A-Za-z0-9_]{3,32}$" LoginViewModel.isLoginValid(viewModel.username)
return viewModel.username.range(of: pattern, options: .regularExpression) != nil
} }
private var isPasswordValid: Bool { private var isPasswordValid: Bool {
@ -149,10 +148,10 @@ struct PasswordLoginView: View {
} }
VStack(alignment: .leading, spacing: 12) { VStack(alignment: .leading, spacing: 12) {
HStack(spacing: 8) {
Text("@")
.foregroundColor(.secondary)
TextField(NSLocalizedString("Введите логин", comment: ""), text: $viewModel.username) TextField(NSLocalizedString("Введите логин", comment: ""), text: $viewModel.username)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(12)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
.focused($focusedField, equals: .username) .focused($focusedField, equals: .username)
@ -161,6 +160,10 @@ struct PasswordLoginView: View {
viewModel.username = String(newValue.prefix(32)) viewModel.username = String(newValue.prefix(32))
} }
} }
}
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(12)
if !isUsernameValid && !viewModel.username.isEmpty { if !isUsernameValid && !viewModel.username.isEmpty {
Text(NSLocalizedString("Неверный логин", comment: "Неверный логин")) Text(NSLocalizedString("Неверный логин", comment: "Неверный логин"))
@ -391,6 +394,10 @@ private struct PasswordlessRequestView: View {
let onShowModePrompt: () -> Void let onShowModePrompt: () -> Void
@FocusState private var isFieldFocused: Bool @FocusState private var isFieldFocused: Bool
private var isLoginValid: Bool {
LoginViewModel.isLoginValid(viewModel.passwordlessLogin)
}
var body: some View { var body: some View {
ScrollView(showsIndicators: false) { ScrollView(showsIndicators: false) {
VStack(alignment: .leading, spacing: 24) { VStack(alignment: .leading, spacing: 24) {
@ -409,19 +416,28 @@ private struct PasswordlessRequestView: View {
// Text(NSLocalizedString("Логин", comment: "")) // Text(NSLocalizedString("Логин", comment: ""))
// .font(.subheadline) // .font(.subheadline)
// .foregroundColor(.secondary) // .foregroundColor(.secondary)
HStack(spacing: 8) {
Text("@")
.foregroundColor(.secondary)
TextField(NSLocalizedString("Введите логин", comment: ""), text: $viewModel.passwordlessLogin) TextField(NSLocalizedString("Введите логин", comment: ""), text: $viewModel.passwordlessLogin)
.textContentType(.username) .textContentType(.username)
.keyboardType(.default) .keyboardType(.default)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
.focused($isFieldFocused)
.onChange(of: viewModel.passwordlessLogin) { newValue in
if newValue.count > 32 {
viewModel.passwordlessLogin = String(newValue.prefix(32))
}
}
}
.padding() .padding()
.background(Color(.secondarySystemBackground)) .background(Color(.secondarySystemBackground))
.cornerRadius(12) .cornerRadius(12)
.focused($isFieldFocused) if !isLoginValid && !viewModel.passwordlessLogin.isEmpty {
.onChange(of: viewModel.passwordlessLogin) { newValue in Text(NSLocalizedString("Неверный логин", comment: ""))
if newValue.count > 64 { .foregroundColor(.red)
viewModel.passwordlessLogin = String(newValue.prefix(64)) .font(.caption)
}
} }
} }
@ -725,13 +741,13 @@ private struct MessengerModePrompt: View {
VStack(spacing: 12) { VStack(spacing: 12) {
optionButton( optionButton(
title: NSLocalizedString("Соцсеть", comment: ""), title: NSLocalizedString("Соцсеть (готово 10%)", comment: ""),
subtitle: NSLocalizedString("Лента, истории, подписки", comment: ""), subtitle: NSLocalizedString("Лента, истории, подписки", comment: ""),
isMessenger: false isMessenger: false
) )
optionButton( optionButton(
title: NSLocalizedString("Только чаты", comment: ""), title: NSLocalizedString("Только чаты (готово 60%)", comment: ""),
subtitle: NSLocalizedString("Минимум отвлечений, чистый мессенджер", comment: ""), subtitle: NSLocalizedString("Минимум отвлечений, чистый мессенджер", comment: ""),
isMessenger: true isMessenger: true
) )

View File

@ -75,18 +75,22 @@ struct RegistrationView: View {
Group { Group {
VStack(alignment: .leading, spacing: 4) { VStack(alignment: .leading, spacing: 4) {
HStack(spacing: 8) {
Text("@")
.foregroundColor(.secondary)
TextField(NSLocalizedString("Введите логин", comment: "Логин"), text: $username) TextField(NSLocalizedString("Введите логин", comment: "Логин"), text: $username)
.autocapitalization(.none) .autocapitalization(.none)
.disableAutocorrection(true) .disableAutocorrection(true)
.focused($focusedField, equals: .username) .focused($focusedField, equals: .username)
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(12)
.onChange(of: username) { newValue in .onChange(of: username) { newValue in
if newValue.count > 32 { if newValue.count > 32 {
username = String(newValue.prefix(32)) username = String(newValue.prefix(32))
} }
} }
}
.padding()
.background(Color(.secondarySystemBackground))
.cornerRadius(12)
if !isUsernameValid && !username.isEmpty { if !isUsernameValid && !username.isEmpty {
Text(NSLocalizedString("Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)", comment: "")) Text(NSLocalizedString("Логин должен быть от 3 до 32 символов (английские буквы, цифры, _)", comment: ""))