Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct LoginView: View {
- @Binding var showingLoginSheet: Bool
- @Binding var login: String
- @Binding var password: String
- @Binding var isUserLoggedIn: Bool
- @Binding var showingLoginFailedAlert: Bool
- @Binding var loginFailedMessage: String
- @State private var showingPassword = false // Dodaj @State do zmiennej showingPassword
- var body: some View {
- VStack {
- Text("Logowanie")
- .font(.headline)
- .padding()
- TextField("Login", text: $login)
- .autocapitalization(.none)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- if showingPassword {
- TextField("Hasło", text: $password)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- } else {
- SecureField("Hasło", text: $password)
- .textFieldStyle(RoundedBorderTextFieldStyle())
- .padding()
- }
- Button(action: {
- showingPassword.toggle()
- }) {
- HStack {
- Image(systemName: showingPassword ? "eye.slash.fill" : "eye.fill")
- Text(showingPassword ? "Ukryj hasło" : "Pokaż hasło")
- }
- .font(.subheadline)
- .foregroundColor(.blue)
- }
- .padding(.bottom, 20)
- if showingLoginFailedAlert {
- Text(loginFailedMessage)
- .foregroundColor(.red)
- .padding()
- }
- HStack {
- Button("Anuluj") {
- showingLoginSheet = false
- }
- .padding()
- Button("OK") {
- if login == "TestUser" && password == "TestPassword" {
- showingLoginFailedAlert = false
- login = ""
- password = ""
- showingLoginSheet = false
- isUserLoggedIn = true
- } else {
- loginFailedMessage = "Nieprawidłowy login lub hasło"
- showingLoginFailedAlert = true
- }
- }
- .padding()
- }
- }
- .padding()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement