Guest User

Untitled

a guest
Feb 23rd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. @IBOutlet weak var usernameTextField: UITextField!
  2. @IBOutlet weak var passwordTextField: UITextField!
  3.  
  4. override func viewDidLoad() {
  5. super.viewDidLoad()
  6.  
  7. // Do any additional setup after loading the view.
  8. }
  9.  
  10. override func didReceiveMemoryWarning() {
  11. super.didReceiveMemoryWarning()
  12. // Dispose of any resources that can be recreated.
  13. }
  14.  
  15. func createAlert (title:String, message:String)
  16. {
  17. let alert = UIAlertController(title: title , message: message, preferredStyle: .alert)
  18. alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: {(action) in
  19. let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC")
  20. self.present(vc!, animated: true, completion: nil)
  21. }))
  22. }
  23.  
  24. @IBAction func createAccountTapped(_ sender: AnyObject) {
  25.  
  26. let username = usernameTextField.text
  27. let password = passwordTextField.text
  28.  
  29. Auth.auth().createUser(withEmail: username!, password: password!, completion: { (user, error) in
  30. if error != nil{
  31. let errorMessage = error?.localizedDescription
  32.  
  33. // error creating account
  34. let alert = UIAlertController(title: "Error" , message: errorMessage, preferredStyle: .alert)
  35. alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
  36. self.present( alert, animated: true, completion: nil)
  37. } else {
  38.  
  39. // success
  40. if ((Error.self != nil)) {
  41. let alert = UIAlertController(title: "Nice!", message: "Ok, now that you have an account, let's go to the Log In screen", preferredStyle: .alert)
  42. let action = UIAlertAction(title: "OK", style: .default) { (action) -> Void in
  43. let ViewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC")
  44. self.present(ViewController!, animated: true, completion: nil)
  45. }
  46.  
  47. }
  48. }
Add Comment
Please, Sign In to add comment