注销后PARSE用户仍然有效

时间:2017-12-14 23:48:36

标签: swift authentication parse-platform

我正在学习使用Parse Server来管理用户和密码。我有一个应用程序,允许用户登录并在服务器中存储信息(年龄,体重,性别和名称)。但我遇到了问题,如果用户退出,应用程序将他们带到登录页面,如果之后他们使用不存在的用户或不正确的密码,在显示警告“用户或密码不正确”后,应用程序将它们带到以前用户信息的主页面。我不确定发生了什么事;我用来登录的代码是:

@IBAction func signInButton(_ sender: Any) {

    let acl = PFACL()

    acl.getPublicWriteAccess = true

    PFUser().acl = acl

    if userTextField.text == "" || passwordTextField.text == ""  {

        createAlert(title: "Error", message: "Both fields should be filled")
    } else {

        activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
        activityIndicator.center = self.view.center
        activityIndicator.hidesWhenStopped = true
        activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
        view.addSubview(activityIndicator)
        activityIndicator.startAnimating()
        UIApplication.shared.beginIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared


        PFUser.logInWithUsername(inBackground: userTextField.text!, password: passwordTextField.text!, block: { (user, error) in


            self.activityIndicator.stopAnimating()
            UIApplication.shared.endIgnoringInteractionEvents() // UIApplication.shared() is now  UIApplication.shared

            if error != nil {

                var displayErrorMessage = "Please try again later."
                let error = error as NSError?
                if let errorMessage = error?.userInfo["error"] as? String {

                    displayErrorMessage = errorMessage
                }

                self.createAlert(title: "Login Error", message: displayErrorMessage)


            } else {

                print("Logged in")
                let usuario = PFUser.current()
                let dataUse = self.queryDownload(usuario: usuario!)


                for items in dataUse {
                    let dataMeassure: GlucoseEvents = NSEntityDescription.insertNewObject(forEntityName: "GlucoseEvents", into: DatabaseController.getContext()) as! GlucoseEvents

                    dataMeassure.allAtributes = items
                }

                DatabaseController.saveContext()
                self.performSegue(withIdentifier: "goToMain", sender: self)
            }
        })
        }
}

现在,此问题仅在注销后发生,因此我猜测该函数中的错误。注销的代码是:

@IBAction func logOut(_ sender: Any) {

    let refreshAlert = UIAlertController(title: "Confirm", message: "Really LogOut?", preferredStyle: UIAlertControllerStyle.alert)

    refreshAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
        PFUser.logOutInBackground { (error) in
            if error != nil {
                self.createAlert(title: "Error", message: "Error")
            }
        }
        self.performSegue(withIdentifier: "closedProf", sender: self)
    }))

    refreshAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
        print("Handle Cancel Logic here")
    }))

    present(refreshAlert, animated: true, completion: nil)

}

还有其他方法可以注销并避免此问题吗?感谢

更多信息

所以我试着看看问题是服务器没有返回nil用户。并在注销时添加了一个print语句。事实证明它是零,所以我不知道为什么它被存储(或在哪里)但LogOut返回一个零用户。

0 个答案:

没有答案