135 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						||
//  RegistrationView.swift
 | 
						||
//  VolnahubApp
 | 
						||
//
 | 
						||
//  Created by cheykrym on 09/06/2025.
 | 
						||
//
 | 
						||
 | 
						||
import SwiftUI
 | 
						||
 | 
						||
struct RegistrationView: View {
 | 
						||
    @Environment(\.presentationMode) private var presentationMode
 | 
						||
    
 | 
						||
    @State private var fullName: String = ""
 | 
						||
    @State private var username: String = ""
 | 
						||
    @State private var password: String = ""
 | 
						||
    @State private var confirmPassword: String = ""
 | 
						||
    @State private var inviteCode: String = ""
 | 
						||
    @AppStorage("isDarkMode") private var isDarkMode: Bool = true
 | 
						||
 | 
						||
    private var isUsernameValid: Bool {
 | 
						||
        let pattern = "^[A-Za-z0-9_]{3,32}$"
 | 
						||
        return username.range(of: pattern, options: .regularExpression) != nil
 | 
						||
    }
 | 
						||
 | 
						||
    private var isPasswordValid: Bool {
 | 
						||
        password.count >= 6 && password.count <= 32
 | 
						||
    }
 | 
						||
 | 
						||
    private var isConfirmPasswordValid: Bool {
 | 
						||
        confirmPassword == password && !confirmPassword.isEmpty
 | 
						||
    }
 | 
						||
 | 
						||
    private var isFormValid: Bool {
 | 
						||
        !fullName.isEmpty && isUsernameValid && isPasswordValid && isConfirmPasswordValid
 | 
						||
    }
 | 
						||
 | 
						||
    var body: some View {
 | 
						||
        NavigationView {
 | 
						||
            VStack {
 | 
						||
 | 
						||
                Text(NSLocalizedString("RegistrationView_title", comment: "Регистрация"))
 | 
						||
                    .font(.largeTitle)
 | 
						||
                    .bold()
 | 
						||
 | 
						||
//                Spacer()
 | 
						||
 | 
						||
                // Полное имя
 | 
						||
                TextField(NSLocalizedString("RegistrationView_fullname", comment: "Полное имя"), text: $fullName)
 | 
						||
                    .padding()
 | 
						||
                    .background(Color(.secondarySystemBackground))
 | 
						||
                    .cornerRadius(8)
 | 
						||
                    .autocapitalization(.words)
 | 
						||
                    .disableAutocorrection(true)
 | 
						||
 | 
						||
                // Логин
 | 
						||
                TextField(NSLocalizedString("RegistrationView_login", comment: "Логин"), text: $username)
 | 
						||
                    .padding()
 | 
						||
                    .background(Color(.secondarySystemBackground))
 | 
						||
                    .cornerRadius(8)
 | 
						||
                    .autocapitalization(.none)
 | 
						||
                    .disableAutocorrection(true)
 | 
						||
 | 
						||
                if !isUsernameValid && !username.isEmpty {
 | 
						||
                    Text(NSLocalizedString("RegistrationView_error_username_invalid", comment: "Неверный логин"))
 | 
						||
                        .foregroundColor(.red)
 | 
						||
                        .font(.caption)
 | 
						||
                }
 | 
						||
 | 
						||
                // Пароль
 | 
						||
                SecureField(NSLocalizedString("RegistrationView_password", comment: "Пароль"), text: $password)
 | 
						||
                    .padding()
 | 
						||
                    .background(Color(.secondarySystemBackground))
 | 
						||
                    .cornerRadius(8)
 | 
						||
                    .autocapitalization(.none)
 | 
						||
 | 
						||
                if !isPasswordValid && !password.isEmpty {
 | 
						||
                    Text(NSLocalizedString("RegistrationView_error_password_invalid", comment: "Пароль должен быть от 6 до 32 символов"))
 | 
						||
                        .foregroundColor(.red)
 | 
						||
                        .font(.caption)
 | 
						||
                }
 | 
						||
 | 
						||
                // Подтверждение пароля
 | 
						||
                SecureField(NSLocalizedString("RegistrationView_confirm_password", comment: "Подтверждение пароля"), text: $confirmPassword)
 | 
						||
                    .padding()
 | 
						||
                    .background(Color(.secondarySystemBackground))
 | 
						||
                    .cornerRadius(8)
 | 
						||
                    .autocapitalization(.none)
 | 
						||
 | 
						||
                if !isConfirmPasswordValid && !confirmPassword.isEmpty {
 | 
						||
                    Text(NSLocalizedString("RegistrationView_error_confirm_password_invalid", comment: "Пароли не совпадают"))
 | 
						||
                        .foregroundColor(.red)
 | 
						||
                        .font(.caption)
 | 
						||
                }
 | 
						||
 | 
						||
                // Инвайт-код
 | 
						||
                TextField(NSLocalizedString("RegistrationView_invite", comment: "Инвайт-код"), text: $inviteCode)
 | 
						||
                    .padding()
 | 
						||
                    .background(Color(.secondarySystemBackground))
 | 
						||
                    .cornerRadius(8)
 | 
						||
                    .autocapitalization(.none)
 | 
						||
                    .disableAutocorrection(true)
 | 
						||
 | 
						||
                // Кнопка регистрации
 | 
						||
                Button(action: {
 | 
						||
                    print("Регистрация отправлена")
 | 
						||
                }) {
 | 
						||
                    Text(NSLocalizedString("RegistrationView_button_register", comment: "Зарегистрироваться"))
 | 
						||
                        .foregroundColor(.white)
 | 
						||
                        .padding()
 | 
						||
                        .frame(maxWidth: .infinity)
 | 
						||
                        .background(isFormValid ? Color.blue : Color.gray.opacity(0.6))
 | 
						||
                        .cornerRadius(8)
 | 
						||
                }
 | 
						||
                .disabled(!isFormValid)
 | 
						||
 | 
						||
            }
 | 
						||
            .padding()
 | 
						||
            .navigationBarItems(trailing:
 | 
						||
                Button(action: {
 | 
						||
                    presentationMode.wrappedValue.dismiss()
 | 
						||
                }) {
 | 
						||
                    Text(NSLocalizedString("RegistrationView_close", comment: "Закрыть"))
 | 
						||
                }
 | 
						||
            )
 | 
						||
        }
 | 
						||
    }
 | 
						||
 | 
						||
}
 | 
						||
 | 
						||
struct RegistrationView_Previews: PreviewProvider {
 | 
						||
    static var previews: some View {
 | 
						||
        RegistrationView()
 | 
						||
    }
 | 
						||
}
 |