Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. import UIKit
  2. import Parse
  3.  
  4. class RegistroUsuario: UIViewController, UITextFieldDelegate {
  5.  
  6. var activityIndicator = UIActivityIndicatorView()
  7. var bottomConstraintConstant:CGFloat = 103.0
  8.  
  9. @IBOutlet weak var scrollviewBottom: NSLayoutConstraint!
  10.  
  11. @IBOutlet var userTextField: UITextField!
  12. @IBOutlet var emailTextField: UITextField!
  13. @IBOutlet var password1TextField: UITextField!
  14. @IBOutlet var password2TextField: UITextField!
  15.  
  16. //Crear alerta
  17. func createAlert(title: String, message: String) {
  18. let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
  19.  
  20. alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
  21. alert.dismiss(animated: true, completion: nil)}))
  22. self.present(alert, animated: true, completion: nil)
  23. }
  24.  
  25. @IBAction func registerButtonPressed(_ sender: Any) {
  26. if emailTextField.text == "" || userTextField.text == "" || password1TextField.text == "" || password2TextField.text == "" {
  27. createAlert(title: "Error", message: "Please fill all the info")
  28.  
  29. } else {
  30.  
  31. if password1TextField.text != password2TextField.text {
  32.  
  33. createAlert(title: "Error", message: "Passwords should match")
  34. } else {
  35.  
  36. activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
  37. activityIndicator.center = self.view.center
  38. activityIndicator.hidesWhenStopped = true
  39. activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
  40. view.addSubview(activityIndicator)
  41. activityIndicator.startAnimating()
  42. UIApplication.shared.beginIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared
  43.  
  44. let user = PFUser()
  45.  
  46. user.username = userTextField.text
  47. user.email = emailTextField.text
  48. user.password = password1TextField.text
  49.  
  50. let acl = PFACL()
  51.  
  52. acl.getPublicWriteAccess = true
  53.  
  54. user.acl = acl
  55.  
  56. user.signUpInBackground(block: { (success, error) in
  57.  
  58. self.activityIndicator.stopAnimating()
  59. UIApplication.shared.endIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared
  60.  
  61. if error != nil {
  62.  
  63. var displayErrorMessage = "Please try again later."
  64.  
  65. let error = error as NSError?
  66.  
  67. if let errorMessage = error?.userInfo["error"] as? String {
  68.  
  69. displayErrorMessage = errorMessage
  70.  
  71. }
  72.  
  73. self.createAlert(title: "Signup Error", message: displayErrorMessage)
  74.  
  75. } else {
  76.  
  77. self.view.endEditing(true)
  78.  
  79. let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpRegistro
  80. self.addChildViewController(popOverVC)
  81. popOverVC.view.frame = self.view.frame
  82. self.view.addSubview(popOverVC.view)
  83. popOverVC.didMove(toParentViewController: self)
  84.  
  85.  
  86. }
  87. })
  88. }
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement