I'm building a custom parse login for my app and I'm having trouble getting one of my if statements in my loginBTN Action to execute. Once I press login with the loginSwitch.on == true even when my username and password text fields are empty/nil it segues to the profile view i.e. opens the app with the last logged user. In my code I'm trying to get it to display an alert asking for username and password to be entered. What's more confusing is that when the else if loginSwitch.on == false is called and the 3 textfields are empty I'm getting my alert message. Please help stop the automatic segue in the "LOGIN" state / loginSwitch.on == true.
@IBAction func loginBTN(sender: AnyObject)
{
if loginSwitch.on == true
{
if usernameTXTFLD != nil || passwordTXTFLD != nil
{
PFUser.logInWithUsernameInBackground(usernameTXTFLD.text!, password:passwordTXTFLD.text!) {
(user: PFUser?, error: NSError?) -> Void in
if user == user
{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.performSegueWithIdentifier("loginToProfileSegue", sender: self)
})
} else {
let errorString = error!.userInfo["error"] as? String
self.displayAlert("Log In Failed", message: errorString!)
}
}
}
else
{
self.displayAlert("Log In Failed", message: "Error: Please Provide Unique Username and Password")
}
}
else
{
if self.usernameTXTFLD != nil || self.passwordTXTFLD != nil || self.emailTXTFLD != nil
{
let user = PFUser()
user.username = usernameTXTFLD.text
user.password = passwordTXTFLD.text
user.email = emailTXTFLD.text
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let _ = error
{
self.displayAlert("Log In Failed", message: "Error: Please Provide Unique Username, Password, and Email Address")
}
else
{
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.performSegueWithIdentifier("loginToProfileSegue", sender: self)
})
}
}
}
else if usernameTXTFLD == nil || passwordTXTFLD == nil || emailTXTFLD == nil
{
//Alert - Please provide username, password, and emailaddress
self.displayAlert("Signup Failed", message: "Error: Please Provide Unique Username, Password, and Email Address")
}
}
}
Aucun commentaire:
Enregistrer un commentaire