0

Right, i've been through the Firebase IOS Swift documentation and still cant find the answer i'm looking for.

In my SignUp ViewController:

 if let userName = self.userName.text where userName != "", let email = self.email.text where email != "", let password = self.password.text where password != "" {      
  DataService.dataService.BASE_REF.createUser(email, password: password, withValueCompletionBlock: { error, result in
    if error != nil {
      print(error)
    } else {
      // CREATE AND LOGIN THE NEW USER WITH AUTHUSER
      DataService.dataService.BASE_REF.authUser(email, password: password, withCompletionBlock: { error, authData in
        let user = ["provider": authData.provider!, "email": email, "username": userName]
        DataService.dataService.createNewAccount(authData.uid, user: user)
      })
        NSUserDefaults.standardUserDefaults().setValue(result ["uid"], forKey: "uid")
        //PERFORM SEGUE TO LOG USER IN
        self.signUP.animate(1, completion: {
          let myTabbarController = self.storyboard?.instantiateViewControllerWithIdentifier("myTabbarController") as! UITabBarController
          let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
          appDelegate.window?.rootViewController = myTabbarController
          myTabbarController.transitioningDelegate = self
        })
      }
    })
  } else{
    self.showErrorAlert("All fields are required", msg: "Please sign up")
  }
}

When user imput email such as a@a.com, the console accepts. I though the server side would handle this. Similarly, when i generate a code to handle this issue such as :

   // FUNC TO VALIDATE EMAIL ADDRESS
func isValidEmail(testStr:String) -> Bool {
  // println("validate calendar: \(testStr)")
  let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
  let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
  return emailTest.evaluateWithObject(testStr)
}

It still accepts false emails so long as it has the at "@" symbol with a ".com"

How can i validate user email is accurate such as a@google.com, etc? ...

Mihriban Minaz
  • 3,043
  • 2
  • 32
  • 52
Martin Q
  • 403
  • 1
  • 6
  • 13
  • a@a.com this is a valid email format and could be a real email address. On client side you shouldn't do more validations. What you could do is you can check if the email is sent, otherwise you can know that this email is not a real one. – Mihriban Minaz Apr 08 '16 at 15:26
  • and how would i do that? ... – Martin Q Apr 08 '16 at 15:32
  • It is not a swift question than. There are lots of ways: https://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/ http://www.labnol.org/software/verify-email-address/18220/ http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email – Mihriban Minaz Apr 08 '16 at 16:09
  • If you don't mind, i'd appreciate Swift's syntax. – Martin Q Apr 08 '16 at 16:13
  • as i've already mentioned basic validation check (which would say a@a.com valid) is enough for client side. If you want to have more precise info, you can check on server side (which is now SWIFT maybe PHP maybe Java or some other languages) without sending it (it is not recommended -> check this one http://stackoverflow.com/a/565537/767329) Best is at smtp server you can see whether the email could not be sent. Then you can say it is not a real email address. – Mihriban Minaz Apr 08 '16 at 16:19
  • See http://stackoverflow.com/questions/17723195/is-there-any-way-to-do-email-confirmation-for-firebase-user-creation-and-or-pass – Frank van Puffelen Apr 08 '16 at 16:58

0 Answers0