Compare commits

..

No commits in common. "cd67c350b4da377e39b3c634d8cf35b588d47277" and "608add0714f6d56cc87196c57810bc5c44592603" have entirely different histories.

4 changed files with 49 additions and 76 deletions

View File

@ -6,9 +6,6 @@
}, },
"(без текста)" : { "(без текста)" : {
},
"@" : {
}, },
"@%@" : { "@%@" : {
"localizations" : { "localizations" : {
@ -285,6 +282,9 @@
}, },
"Введите логин и мы отправим шестизначный код подтверждения." : { "Введите логин и мы отправим шестизначный код подтверждения." : {
},
"Введите логин." : {
}, },
"Введите пароль" : { "Введите пароль" : {
"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() {
guard LoginViewModel.isLoginValid(passwordlessLogin) else { let trimmedLogin = passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines)
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,19 +369,12 @@ extension LoginViewModel {
} }
var canRequestPasswordlessCode: Bool { var canRequestPasswordlessCode: Bool {
LoginViewModel.isLoginValid(passwordlessLogin) && !isSendingCode !passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && !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,7 +109,8 @@ struct PasswordLoginView: View {
} }
private var isUsernameValid: Bool { private var isUsernameValid: Bool {
LoginViewModel.isLoginValid(viewModel.username) let pattern = "^[A-Za-z0-9_]{3,32}$"
return viewModel.username.range(of: pattern, options: .regularExpression) != nil
} }
private var isPasswordValid: Bool { private var isPasswordValid: Bool {
@ -148,10 +149,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)
@ -160,10 +161,6 @@ 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: "Неверный логин"))
@ -394,10 +391,6 @@ 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) {
@ -416,28 +409,19 @@ 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)
if !isLoginValid && !viewModel.passwordlessLogin.isEmpty { .focused($isFieldFocused)
Text(NSLocalizedString("Неверный логин", comment: "")) .onChange(of: viewModel.passwordlessLogin) { newValue in
.foregroundColor(.red) if newValue.count > 64 {
.font(.caption) viewModel.passwordlessLogin = String(newValue.prefix(64))
}
} }
} }
@ -741,13 +725,13 @@ private struct MessengerModePrompt: View {
VStack(spacing: 12) { VStack(spacing: 12) {
optionButton( optionButton(
title: NSLocalizedString("Соцсеть (готово 10%)", comment: ""), title: NSLocalizedString("Соцсеть", comment: ""),
subtitle: NSLocalizedString("Лента, истории, подписки", comment: ""), subtitle: NSLocalizedString("Лента, истории, подписки", comment: ""),
isMessenger: false isMessenger: false
) )
optionButton( optionButton(
title: NSLocalizedString("Только чаты (готово 60%)", comment: ""), title: NSLocalizedString("Только чаты", comment: ""),
subtitle: NSLocalizedString("Минимум отвлечений, чистый мессенджер", comment: ""), subtitle: NSLocalizedString("Минимум отвлечений, чистый мессенджер", comment: ""),
isMessenger: true isMessenger: true
) )

View File

@ -75,22 +75,18 @@ 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: ""))