onsubmit for login/register

This commit is contained in:
Andy Pack 2023-01-08 22:46:17 +00:00
parent 509aea0b42
commit 7c4832c82d
Signed by: sarsoo
GPG Key ID: A55BA3536A5E0ED7

View File

@ -48,12 +48,20 @@ struct LoginScreen: View {
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
SecureField("Password", text: $password) SecureField("Password", text: $password)
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.onSubmit {
if screenMode == .Login {
login()
}
}
} }
if screenMode == .Register { if screenMode == .Register {
SecureField("Password Again", text: $password2) SecureField("Password Again", text: $password2)
.textFieldStyle(.roundedBorder) .textFieldStyle(.roundedBorder)
.padding(.bottom, 20) .padding(.bottom, 20)
.onSubmit {
register()
}
} }
if screenMode == .None { if screenMode == .None {
@ -79,7 +87,39 @@ struct LoginScreen: View {
if screenMode == .Login { if screenMode == .Login {
Button(action: { Button(action: {
login()
}) {
Text("Log In")
}
.buttonStyle(.bordered)
.padding(.top, 20)
}
if screenMode == .Register {
Button(action: {
register()
}) {
Text("Register")
}
.buttonStyle(.bordered)
}
Button(action: {
UIApplication.shared.open(URL(string: "https://mixonomer.sarsoo.xyz/privacy")!)
}) {
Text("Privacy Policy")
}
.padding(.top, 20)
}
.toast(isPresented: $showingToast, dismissAfter: 3.0){
ToastView(toastText)
.toastViewStyle(.failure)
}
.toastDimmedBackground(false)
.padding()
}
func login() {
let keychain = Keychain(service: "xyz.sarsoo.music.login") let keychain = Keychain(service: "xyz.sarsoo.music.login")
keychain["username"] = username keychain["username"] = username
@ -131,16 +171,9 @@ struct LoginScreen: View {
} }
} }
} }
}) {
Text("Log In")
}
.buttonStyle(.bordered)
.padding(.top, 20)
} }
if screenMode == .Register { func register() {
Button(action: {
let keychain = Keychain(service: "xyz.sarsoo.music.login") let keychain = Keychain(service: "xyz.sarsoo.music.login")
keychain["username"] = username keychain["username"] = username
@ -213,25 +246,6 @@ struct LoginScreen: View {
showingToast = true showingToast = true
} }
} }
}) {
Text("Register")
}
.buttonStyle(.bordered)
}
Button(action: {
UIApplication.shared.open(URL(string: "https://mixonomer.sarsoo.xyz/privacy")!)
}) {
Text("Privacy Policy")
}
.padding(.top, 20)
}
.toast(isPresented: $showingToast, dismissAfter: 3.0){
ToastView(toastText)
.toastViewStyle(.failure)
}
.toastDimmedBackground(false)
.padding()
} }
} }