每次我尝试在我的登录页面上登录用户时,我都会收到无效的登录参数
I keep receiving invalid login parameters every time i try to log in a user on my Log in page
我正在使用 swift 并在 xcode 上进行解析
我一直收到这个错误:
[Error]: invalid login parameters (Code: 101, Version: 1.7.2)
每当我尝试登录一个用户时,我知道该用户是在解析后端创建的,并且其信息是正确的。我该怎么做才能阻止这种情况发生并让用户在应用程序不发送回无效登录参数的情况下登录?
这是我的 LogInViewController:
import Foundation
import Parse
import UIKit
import Bolts
class LoginViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var loginStatusLabel: UILabel!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var loginButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
emailTextField.delegate = self
passwordTextField.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func loginButtonPress(sender: AnyObject) {
login(emailTextField.text, password: passwordTextField.text)
}
func login(email: String, password: String)
{
PFUser.logInWithUsernameInBackground("email", password: "password")
{
(user: PFUser?, error: NSError?) -> Void in
if user != nil
{
user!.fetch()
if user!.objectForKey("emailVerified") as! Bool
{
self.loginStatusLabel.text = "Success!"
}
else if !(user!.objectForKey("emailVerified") as! Bool)
{
self.loginStatusLabel.text = "Verify your email address!"
}
else // status is "missing"
{
//TODO: Handle this error better
self.loginStatusLabel.text = "Verification status: Missing"
}
}
else
{
if let errorField = error!.userInfo
{
self.loginStatusLabel.text = (errorField["error"] as! NSString) as String
}
else
{
// No userInfo dictionary present
// Help from
}
}
}
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true;
}
}
我在登录用户时哪里出错了?
您将字符串 "email"
和 "password"
传递给解析,而不是变量 email
和 password
的实际值。
将您的代码更改为:
PFUser.logInWithUsernameInBackground(email, password: password)
没有 ""
我正在使用 swift 并在 xcode 上进行解析 我一直收到这个错误:
[Error]: invalid login parameters (Code: 101, Version: 1.7.2)
每当我尝试登录一个用户时,我知道该用户是在解析后端创建的,并且其信息是正确的。我该怎么做才能阻止这种情况发生并让用户在应用程序不发送回无效登录参数的情况下登录?
这是我的 LogInViewController:
import Foundation
import Parse
import UIKit
import Bolts
class LoginViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var loginStatusLabel: UILabel!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var loginButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
emailTextField.delegate = self
passwordTextField.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func loginButtonPress(sender: AnyObject) {
login(emailTextField.text, password: passwordTextField.text)
}
func login(email: String, password: String)
{
PFUser.logInWithUsernameInBackground("email", password: "password")
{
(user: PFUser?, error: NSError?) -> Void in
if user != nil
{
user!.fetch()
if user!.objectForKey("emailVerified") as! Bool
{
self.loginStatusLabel.text = "Success!"
}
else if !(user!.objectForKey("emailVerified") as! Bool)
{
self.loginStatusLabel.text = "Verify your email address!"
}
else // status is "missing"
{
//TODO: Handle this error better
self.loginStatusLabel.text = "Verification status: Missing"
}
}
else
{
if let errorField = error!.userInfo
{
self.loginStatusLabel.text = (errorField["error"] as! NSString) as String
}
else
{
// No userInfo dictionary present
// Help from
}
}
}
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true;
}
}
我在登录用户时哪里出错了?
您将字符串 "email"
和 "password"
传递给解析,而不是变量 email
和 password
的实际值。
将您的代码更改为:
PFUser.logInWithUsernameInBackground(email, password: password)
没有 ""