[+] Dismiss alert after receiving the response

This commit is contained in:
Hykilpikonna
2021-01-22 15:37:13 -05:00
parent f37a12c963
commit 306d4bfaf1
2 changed files with 11 additions and 6 deletions
+6 -5
View File
@@ -28,19 +28,20 @@ class LoginVC: UIViewController
// Verify username and password
guard let name = username.text, name ~= "[A-Za-z0-9_-]{3,16}" else
{
alert("Username Invalid", "Username must be 3 to 16 characters long, and must only contain a-z, 0-9, underscore, and minus signs (-).")
msg("Username Invalid", "Username must be 3 to 16 characters long, and must only contain a-z, 0-9, underscore, and minus signs (-).")
return
}
guard let pass = password.text, pass.count > 8 else
guard let pass = password.text, pass.count >= 8 else
{
alert("Password Invalid", "Password must be more than 8 characters long")
msg("Password Invalid", "Password must be more than or equal to 8 characters long")
return
}
// Send register request
alert("Registering...", "Please Wait", okayable: true)
send(APIs.register, ["username": name, "password": pass]) { it in
let a = alert("Registering...", "Please Wait")
send(APIs.register, ["username": name, "password": pass.sha256]) { it in
print(it)
a.dismiss()
}
}
+5 -1
View File
@@ -134,8 +134,12 @@ extension UIViewController
return alert
}
/// A message is an okayable alert
@discardableResult
func msg(_ title: String, _ message: String) -> UIAlertController { alert(title, message, okayable: true) }
/// More convenient dismiss function
func dismiss() { dismiss(animated: false, completion: nil) }
func dismiss(_ completion: (() -> Void)? = nil) { dismiss(animated: false, completion: completion) }
}