You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
//
|
|
// LoginView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 19/02/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
struct LoginView: View {
|
|
|
|
@State var username: String = "laurent"
|
|
@State var password: String = "staxkikoo"
|
|
|
|
var body: some View {
|
|
|
|
Form {
|
|
|
|
TextField("Username", text: self.$username)
|
|
.autocorrectionDisabled()
|
|
.textInputAutocapitalization(.never)
|
|
SecureField("Password", text: self.$password)
|
|
.autocorrectionDisabled()
|
|
.textInputAutocapitalization(.never)
|
|
|
|
Section {
|
|
Button(action: {
|
|
self._login()
|
|
}, label: {
|
|
Text("Login")
|
|
})
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
|
|
Section {
|
|
HStack {
|
|
Button(action: {
|
|
self._login()
|
|
}, label: {
|
|
Text("Sign up")
|
|
})
|
|
.frame(maxWidth: .infinity)
|
|
Button(action: {
|
|
self._login()
|
|
}, label: {
|
|
Text("Forgotten password")
|
|
})
|
|
.frame(maxWidth: .infinity)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
.navigationTitle("Login")
|
|
}
|
|
|
|
fileprivate func _login() {
|
|
guard let service = Store.main.service else {
|
|
return
|
|
}
|
|
Task {
|
|
do {
|
|
let _: User = try await service.login(
|
|
username: self.username,
|
|
password: self.password)
|
|
} catch {
|
|
Logger.error(error)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#Preview {
|
|
LoginView()
|
|
}
|
|
|