gpt4 book ai didi

ios - 用户先前注销后使用无效数据错误地登录

转载 作者:行者123 更新时间:2023-11-30 14:06:00 26 4
gpt4 key购买 nike

我有一个登录屏幕,可确保在尝试登录之前输入字段中有有效数据。至少我是这么想的。

问题是,当我们从另一个“注销”用户的屏幕返回时,如果我在返回此页面后使用无效的用户名密码组合提交,我会按预期看到错误对话框,但在关闭它之后,我会就像我登录一样进入下一个 View Controller 。

请问有什么帮助吗?

@IBAction func btnSubmit(sender: UIButton) {
if txtUsername.text == "" || txtPassword.text == "" {
//they're missing a username or password
displayAlert("Missing Field(s)", message: "Please enter both a username and password")
}else {
//we check if they're in signup/login mode
if Switch.on {
//user is in signup mode
if txtPassword.text != txtConfirmPassword.text {
//the password fields do not match
displayAlert("Mismatched Passwords", message: "Please enter matching passwords")
}else {
//the password fields do match, and the user can register with this username/email and password
var user = PFUser()
user.username = txtUsername.text
user.password = txtPassword.text
// other fields can be set just like with PFObject

user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as! String
// Show the errorString somewhere and let the user try again.
self.displayAlert("Signup Error", message: errorString)
} else {
// Hooray! Let them use the app now.
self.performSegueWithIdentifier("register", sender: self)
}
} }
}else {
//user is in login mode and we can submit credentials


PFUser.logInWithUsernameInBackground(txtUsername.text, password:txtPassword.text) {
(user: PFUser?, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as! String
// Show the errorString somewhere and let the user try again.
self.displayAlert("Login Error", message: errorString)
} else {
if PFUser.currentUser()!.username != nil {
// Do stuff after successful login.
self.performSegueWithIdentifier("login", sender: self)
}
}

}
}
}
}

这是我从其他页面进行的注销调用

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "logout" {
PFUser.logOut()

}
}

最佳答案

我认为问题在于您没有使用完成处理程序中返回的成功 Bool 。当我使用 Parse 登录用户时,我主要用它来查看登录是否成功,如果不成功,我将检查错误消息是什么。这应该会阻止您允许用户在未正确登录的情况下继续进入应用程序。

user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if error != nil {
let errorString = error!.userInfo?["error"] as! String
// Show the errorString somewhere and let the user try again.
self.displayAlert("Signup Error", message: errorString)
} else {
if succeeded {
// Hooray! Let them use the app now.
self.performSegueWithIdentifier("register", sender: self)
} else {
//Something went wrong
}
}
}

关于ios - 用户先前注销后使用无效数据错误地登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32401129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com