关闭和打开我的应用程序会直接进入主页,而无需验证用户电子邮件

Closing and opening my app goes straight to homepage without verifying the user email

当我创建一个新用户时,它会做它应该做的所有事情并保存用户详细信息并返回登录页面等待电子邮件在允许使用之前进行验证。编码有效,因此在验证电子邮件之前不允许您继续,但我意识到当我滑动应用程序关闭它然后重新打开它(在验证电子邮件之前)时,它会绕过登录直接进入主页页面即使电子邮件尚未验证?

import UIKit
import Firebase
import SwiftKeychainWrapper

class ViewController: UIViewController {

@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!

var userUid: String!

override func viewDidLoad(){
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.view.endEditing(true)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func viewDidAppear(_ animated: Bool) {

    func Keychain() {
        KeychainWrapper.standard.set(userUid, forKey: "uid")
    }

    if let _ = KeychainWrapper.standard.string(forKey: "uid"){
        LoggedIn()
    }
}

func goToCreateUserVC() {
    performSegue(withIdentifier: "CreateAProfile", sender: nil)
}

func LoggedIn() {
    performSegue(withIdentifier: "LoginSuccessful", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "CreateAProfile" {
        if let destination = segue.destination as? CreatUsers {
            if userUid != nil {
                destination.userUid = userUid
            }
            if emailField.text != nil {
                destination.emailField = emailField.text
            }
            if passwordField.text != nil {
                destination.passwordField = passwordField.text
            }
        }
    }
}

func DisplayAlertMessage(MessageToDisplay: String) {
    let alertController = UIAlertController(title: "Alert", message: MessageToDisplay, preferredStyle: .alert)

    let OKAction = UIAlertAction(title: "OK", style: .default) { (action:UIAlertAction!) in

        // Code in this block will trigger when OK button tapped.
        print("Ok button tapped");

    }

    alertController.addAction(OKAction)

    self.present(alertController, animated: true, completion:nil)
}

@IBAction func signIntapped(_ sender: Any) {
    if let email = emailField.text, let password = passwordField.text {
        Auth.auth().signIn(withEmail: email, password: password, completion:
            {(user,error) in
                if let user = Auth.auth().currentUser {
                    if user.isEmailVerified {
                        self.userUid = user.uid
                        print("Email Verified")
                        self.LoggedIn()
                    } else {
                        self.DisplayAlertMessage(MessageToDisplay: "Need To Verify Email Address")
                    }
                } else {
                    self.DisplayAlertMessage(MessageToDisplay: "Incorrect Username/Password")
                }
        });
    }
}

@IBAction func NotaMemberisTapped(_ sender: Any) {
    self.goToCreateUserVC()
}

}

只有当我关闭应用程序并重新打开它发现它作弊时才会发生 - 试图弄清楚如何防止它发生。

您正在根据钥匙串中是否有值来调用 LoggedIn() 函数。我假设您将该信息保存到钥匙串中,无论是否已执行验证。