Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //cek input
- guard let name = txtUsername.text, name != "",
- let emailAddress = txtEmail.text, emailAddress != "", let password = txtPassword.text, password != "" else {
- let alertController = UIAlertController(title: "Registration Error", message: "Please make sure you provide your name, email address and password to complete the registration.", preferredStyle: .alert)
- let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
- alertController.addAction(okayAction)
- present(alertController, animated: true, completion: nil)
- return
- }
- FIRAuth.auth()?.createUser(withEmail: emailAddress, password: password, completion: { (user, error) in
- if let error = error {
- let alertController = UIAlertController(title: "Signup Error", message: error.localizedDescription, preferredStyle: .alert)
- let okayAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
- alertController.addAction(okayAction)
- self.present(alertController, animated: true, completion: nil)
- return
- }
- //email verification
- guard let currentUser = user, currentUser.isEmailVerified else {
- let alertController = UIAlertController(title: "Login Error", message: "please check your email and verified", preferredStyle: .alert)
- let okayAction = UIAlertAction(title: "Resend email", style: .default, handler: { (action) in
- user?.sendEmailVerification(completion: nil)
- })
- let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
- alertController.addAction(okayAction)
- alertController.addAction(cancelAction)
- self.present(alertController, animated: true, completion: nil)
- return
- }
- //dismiss keyboard
- self.view.endEditing(true)
- //present the main view
- if let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginView"){
- UIApplication.shared.keyWindow?.rootViewController = viewController
- self.dismiss(animated: true, completion: nil)
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement