Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.45 KB | None | 0 0
  1.  //cek input
  2.         guard let name = txtUsername.text, name != "",
  3.         let emailAddress = txtEmail.text, emailAddress != "", let password = txtPassword.text, password != "" else {
  4.            
  5.             let alertController = UIAlertController(title: "Registration Error", message: "Please make sure you provide your name, email address and password to complete the registration.", preferredStyle: .alert)
  6.             let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
  7.             alertController.addAction(okayAction)
  8.             present(alertController, animated: true, completion: nil)
  9.            
  10.             return
  11.         }
  12.        
  13.         FIRAuth.auth()?.createUser(withEmail: emailAddress, password: password, completion: { (user, error) in
  14.            
  15.             if let error = error {
  16.                 let alertController = UIAlertController(title: "Signup Error", message: error.localizedDescription, preferredStyle: .alert)
  17.                 let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
  18.                 alertController.addAction(okayAction)
  19.                 self.present(alertController, animated: true, completion: nil)
  20.                 return
  21.             }
  22.            
  23.             //email verification
  24.             guard let currentUser = user, currentUser.isEmailVerified else {
  25.                
  26.                 let alertController = UIAlertController(title: "Login Error", message: "please check your email and verified", preferredStyle: .alert)
  27.                 let okayAction = UIAlertAction(title: "Resend email", style: .default, handler: { (action) in
  28.                     user?.sendEmailVerification(completion: nil)
  29.                 })
  30.                 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
  31.                 alertController.addAction(okayAction)
  32.                 alertController.addAction(cancelAction)
  33.                
  34.                 self.present(alertController, animated: true, completion: nil)
  35.                 return
  36.             }
  37.            
  38.             //dismiss keyboard
  39.             self.view.endEditing(true)
  40.             //present the main view
  41.             if let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginView"){
  42.                 UIApplication.shared.keyWindow?.rootViewController = viewController
  43.                 self.dismiss(animated: true, completion: nil)
  44.             }
  45.        
  46.         })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement