Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @IBOutlet weak var usernameTextField: UITextField!
- @IBOutlet weak var passwordTextField: UITextField!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- func createAlert (title:String, message:String)
- {
- let alert = UIAlertController(title: title , message: message, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: {(action) in
- let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC")
- self.present(vc!, animated: true, completion: nil)
- }))
- }
- @IBAction func createAccountTapped(_ sender: AnyObject) {
- let username = usernameTextField.text
- let password = passwordTextField.text
- Auth.auth().createUser(withEmail: username!, password: password!, completion: { (user, error) in
- if error != nil{
- let errorMessage = error?.localizedDescription
- // error creating account
- let alert = UIAlertController(title: "Error" , message: errorMessage, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
- self.present( alert, animated: true, completion: nil)
- } else {
- // success
- if ((Error.self != nil)) {
- let alert = UIAlertController(title: "Nice!", message: "Ok, now that you have an account, let's go to the Log In screen", preferredStyle: .alert)
- let action = UIAlertAction(title: "OK", style: .default) { (action) -> Void in
- let ViewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginVC")
- self.present(ViewController!, animated: true, completion: nil)
- }
- }
- }
Add Comment
Please, Sign In to add comment