在没有有效凭证的情况下解析登录进程

时间:2015-09-04 12:38:40

标签: ios swift parse-platform

我希望我的应用程序在没有正确凭据的情况下阻止用户登录(很像其他所有应用程序)。我正在使用Parse并在他们的iOS源文档下使用他们的代码来登录序列但是一旦我点击登录按钮而没有任何凭据,甚至是错误的凭证,它仍然适用于sucessfulLoginPage segue标识符而不首先检查他们的凭据。我已经尝试了所有我知道怎么做而没有任何成功,有人可以帮助我吗?我的代码如下。

PFUser.logInWithUsernameInBackground(username, password:password) {
    (user: PFUser?, error: NSError?) -> Void in
    if user != nil {
        self.performSegueWithIdentifier("sucessfulLoginPage", sender: self)
    } else if username.isEmpty || password.isEmpty {
        var emptyFieldsError:UIAlertView = UIAlertView(title: "Please try again", message: "Please fill in all the fields we can get you logged in to your account.", delegate: self, cancelButtonTitle: "Try again")
        emptyFieldsError.show()
        self.loginActivity.hidden = true
        self.loginButton.userInteractionEnabled = true
        self.loginButton.alpha = 1.0
        self.loginActivity.stopAnimating()

        self.usernameField.userInteractionEnabled = true
        self.passwordField.userInteractionEnabled = true
        self.forgotPasswordLabel.userInteractionEnabled = true
    } else {
        self.loginActivity.hidden = true
        self.loginButton.userInteractionEnabled = true
        self.loginButton.alpha = 1.0
        self.loginActivity.stopAnimating()

        self.usernameField.userInteractionEnabled = true
        self.passwordField.userInteractionEnabled = true
        self.forgotPasswordLabel.userInteractionEnabled = true

        var invalidLogin:UIAlertView = UIAlertView(title: "Please try again", message: "The username password combo you gave us does not match our records, please reset your password or try again.", delegate: self, cancelButtonTitle: "Try again")
        invalidLogin.show()
    }
}

1 个答案:

答案 0 :(得分:1)

如果您启用了自动用户,则可能会发生这种情况。在AppDelegate中搜索PFUser.enableAutomaticUser()并删除或评论它。