【发布时间】:2018-01-07 07:04:28
【问题描述】:
如果我登录或注册,一切都会顺利进行。一旦用户将他们的电子邮件值更改为 firebase 然后注销,我的登录功能就不再起作用。我不确定到底是什么原因造成的,但它一定是我的 updateEmailAction 函数中的某些东西。
//在电子邮件更新之前可以正常工作。在电子邮件更新和持续 SVProgress 旋转后不再工作。
@IBAction func signInButton(_ sender: Any) {
self.view.endEditing(true)
let email = emailText.text!.lowercased()
let finalEmail = email.trimmingCharacters(in: .whitespacesAndNewlines)
let password = passwordText.text!
if finalEmail.characters.count < 8 || finalEmail.isEmpty || password.isEmpty {
let alertController = UIAlertController(title: "OOPS", message: "You must fill in all the fields", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alertController, animated: true, completion: nil)
}else {
SVProgressHUD.show()
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if error == nil {
if let user = user {
print("\(user.displayName!) has been signed in")
SVProgressHUD.dismiss()
self.enter()
self.performSegue(withIdentifier: "signInHome", sender: nil)
}else{
print(error?.localizedDescription as Any)
}
}
}
}
}
//更新邮箱功能,邮箱更改成功,退出时无法重新登录。
@IBAction func updateEmailAction(_ sender: Any) {
var pictureD: Data? = nil
if let imageView = self.profileImage.image{
pictureD = UIImageJPEGRepresentation(imageView, 0.70)
}
let emailField = emailText.text?.lowercased()
let finalEmail = emailField?.trimmingCharacters(in: .whitespacesAndNewlines)
if (finalEmail?.isEmpty)! {
self.view.endEditing(true)
let alertController = UIAlertController(title: "OOPS", message: " You must fill all the fields", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alertController, animated: true, completion: nil)
}else{
let changeRequest = Auth.auth().currentUser?.createProfileChangeRequest()
//changeRequest. = firstLastName
changeRequest?.commitChanges(completion: { (error) in
if error == nil{
let user = Auth.auth().currentUser
let userInfo = ["firstLastName": self.name, "email": finalEmail, "password": self.passwordOld, "location": self.locationOld, "interests": self.interestsOld, "biography": self.biog, "uid": self.uid, "photoURL": self.photoUrl]
let userRef = self.dataBaseRef.child("users").child((user?.uid)!)
userRef.setValue(userInfo)
print("user info set")
}else{
print(error?.localizedDescription)
}
})
//
// } else{
// print(error?.localizedDescription)
// }
}}
@IBAction func logOutAction(_ sender: Any) {
if Auth.auth().currentUser != nil {
// there is a user signed in
do {
try? Auth.auth().signOut()
self.performSegue(withIdentifier: "login", sender: self)
}
}
}
【问题讨论】:
-
注销代码在哪里?注销时看到了什么?