使用者驗證:
之前有實作過使用者驗證信的部分:
送驗證信:
firebaseUser?.sendEmailVerification { _ in
}
是否成功驗證
func emailVerified(){
Auth.auth().currentUser?.reload(completion: { (error) in
if let error = error {
print(error)
} else {
if Auth.auth().currentUser != nil && Auth.auth().currentUser!.isEmailVerified {
self.userIsEmailVerified = true
} else {
self.userIsEmailVerified = false
}
}
})
}
code:
if (Auth.auth().currentUser?.email == GlobalAppSetting.shared.username && GlobalAppSetting.shared.username == emailTextField.text!) {
emailVerified()
Auth.auth().signIn(withEmail: self.emailTextField.text!, password: self.passwordTextField.text!, completion: { (user, error) in
self.emailVerified()
guard self.userIsEmailVerified else {
TAlertView.showAlertWith(title: "", message: "Not Verified!", delegate: self, confirm: nil)
return
}
if user != nil {
// 登入成功了
TAlertView.showAlertWith(title: "", message: "Successfull!", delegate: self, confirm: nil)
}else{
// 登入失敗了
TAlertView.showAlertWith(title: "", message: "Failed to Login!", delegate: self, confirm: nil)
}
})