patch
This commit is contained in:
parent
8712c7ea22
commit
bbe6a8a3e4
@ -282,9 +282,6 @@
|
||||
},
|
||||
"Введите логин и мы отправим шестизначный код подтверждения." : {
|
||||
|
||||
},
|
||||
"Введите логин." : {
|
||||
|
||||
},
|
||||
"Введите пароль" : {
|
||||
"comment" : "Пароль\nПоле ввода пароля на приложение"
|
||||
|
||||
@ -155,14 +155,14 @@ class LoginViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
func requestPasswordlessCode() {
|
||||
let trimmedLogin = passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
guard !trimmedLogin.isEmpty else {
|
||||
errorMessage = NSLocalizedString("Введите логин.", comment: "")
|
||||
guard LoginViewModel.isLoginValid(passwordlessLogin) else {
|
||||
errorMessage = NSLocalizedString("Неверный логин", comment: "")
|
||||
showError = true
|
||||
return
|
||||
}
|
||||
|
||||
let trimmedLogin = passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
isSendingCode = true
|
||||
showError = false
|
||||
|
||||
@ -369,12 +369,19 @@ extension LoginViewModel {
|
||||
}
|
||||
|
||||
var canRequestPasswordlessCode: Bool {
|
||||
!passwordlessLogin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty && !isSendingCode
|
||||
LoginViewModel.isLoginValid(passwordlessLogin) && !isSendingCode
|
||||
}
|
||||
|
||||
var canVerifyPasswordlessCode: Bool {
|
||||
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 {
|
||||
|
||||
@ -109,8 +109,7 @@ struct PasswordLoginView: View {
|
||||
}
|
||||
|
||||
private var isUsernameValid: Bool {
|
||||
let pattern = "^[A-Za-z0-9_]{3,32}$"
|
||||
return viewModel.username.range(of: pattern, options: .regularExpression) != nil
|
||||
LoginViewModel.isLoginValid(viewModel.username)
|
||||
}
|
||||
|
||||
private var isPasswordValid: Bool {
|
||||
@ -391,6 +390,10 @@ private struct PasswordlessRequestView: View {
|
||||
let onShowModePrompt: () -> Void
|
||||
@FocusState private var isFieldFocused: Bool
|
||||
|
||||
private var isLoginValid: Bool {
|
||||
LoginViewModel.isLoginValid(viewModel.passwordlessLogin)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 24) {
|
||||
@ -419,10 +422,15 @@ private struct PasswordlessRequestView: View {
|
||||
.cornerRadius(12)
|
||||
.focused($isFieldFocused)
|
||||
.onChange(of: viewModel.passwordlessLogin) { newValue in
|
||||
if newValue.count > 64 {
|
||||
viewModel.passwordlessLogin = String(newValue.prefix(64))
|
||||
if newValue.count > 32 {
|
||||
viewModel.passwordlessLogin = String(newValue.prefix(32))
|
||||
}
|
||||
}
|
||||
if !isLoginValid && !viewModel.passwordlessLogin.isEmpty {
|
||||
Text(NSLocalizedString("Неверный логин", comment: ""))
|
||||
.foregroundColor(.red)
|
||||
.font(.caption)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user