Advertisement
Xaniasty

Untitled

Jun 12th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. struct LoginView: View {
  2. @Binding var showingLoginSheet: Bool
  3. @Binding var login: String
  4. @Binding var password: String
  5. @Binding var isUserLoggedIn: Bool
  6. @Binding var showingLoginFailedAlert: Bool
  7. @Binding var loginFailedMessage: String
  8.  
  9. @State private var showingPassword = false // Dodaj @State do zmiennej showingPassword
  10.  
  11. var body: some View {
  12. VStack {
  13. Text("Logowanie")
  14. .font(.headline)
  15. .padding()
  16.  
  17. TextField("Login", text: $login)
  18. .autocapitalization(.none)
  19. .textFieldStyle(RoundedBorderTextFieldStyle())
  20. .padding()
  21.  
  22. if showingPassword {
  23. TextField("Hasło", text: $password)
  24. .textFieldStyle(RoundedBorderTextFieldStyle())
  25. .padding()
  26. } else {
  27. SecureField("Hasło", text: $password)
  28. .textFieldStyle(RoundedBorderTextFieldStyle())
  29. .padding()
  30. }
  31.  
  32. Button(action: {
  33. showingPassword.toggle()
  34. }) {
  35. HStack {
  36. Image(systemName: showingPassword ? "eye.slash.fill" : "eye.fill")
  37. Text(showingPassword ? "Ukryj hasło" : "Pokaż hasło")
  38. }
  39. .font(.subheadline)
  40. .foregroundColor(.blue)
  41. }
  42. .padding(.bottom, 20)
  43.  
  44. if showingLoginFailedAlert {
  45. Text(loginFailedMessage)
  46. .foregroundColor(.red)
  47. .padding()
  48. }
  49.  
  50. HStack {
  51. Button("Anuluj") {
  52. showingLoginSheet = false
  53. }
  54. .padding()
  55.  
  56. Button("OK") {
  57. if login == "TestUser" && password == "TestPassword" {
  58. showingLoginFailedAlert = false
  59. login = ""
  60. password = ""
  61. showingLoginSheet = false
  62. isUserLoggedIn = true
  63. } else {
  64. loginFailedMessage = "Nieprawidłowy login lub hasło"
  65. showingLoginFailedAlert = true
  66. }
  67. }
  68. .padding()
  69. }
  70. }
  71. .padding()
  72. }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement