Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Parse
- class RegistroUsuario: UIViewController, UITextFieldDelegate {
- var activityIndicator = UIActivityIndicatorView()
- var bottomConstraintConstant:CGFloat = 103.0
- @IBOutlet weak var scrollviewBottom: NSLayoutConstraint!
- @IBOutlet var userTextField: UITextField!
- @IBOutlet var emailTextField: UITextField!
- @IBOutlet var password1TextField: UITextField!
- @IBOutlet var password2TextField: UITextField!
- //Crear alerta
- func createAlert(title: String, message: String) {
- let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
- alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
- alert.dismiss(animated: true, completion: nil)}))
- self.present(alert, animated: true, completion: nil)
- }
- @IBAction func registerButtonPressed(_ sender: Any) {
- if emailTextField.text == "" || userTextField.text == "" || password1TextField.text == "" || password2TextField.text == "" {
- createAlert(title: "Error", message: "Please fill all the info")
- } else {
- if password1TextField.text != password2TextField.text {
- createAlert(title: "Error", message: "Passwords should match")
- } else {
- activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
- activityIndicator.center = self.view.center
- activityIndicator.hidesWhenStopped = true
- activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.gray
- view.addSubview(activityIndicator)
- activityIndicator.startAnimating()
- UIApplication.shared.beginIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared
- let user = PFUser()
- user.username = userTextField.text
- user.email = emailTextField.text
- user.password = password1TextField.text
- let acl = PFACL()
- acl.getPublicWriteAccess = true
- user.acl = acl
- user.signUpInBackground(block: { (success, error) in
- self.activityIndicator.stopAnimating()
- UIApplication.shared.endIgnoringInteractionEvents() // UIApplication.shared() is now UIApplication.shared
- if error != nil {
- var displayErrorMessage = "Please try again later."
- let error = error as NSError?
- if let errorMessage = error?.userInfo["error"] as? String {
- displayErrorMessage = errorMessage
- }
- self.createAlert(title: "Signup Error", message: displayErrorMessage)
- } else {
- self.view.endEditing(true)
- let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "sbPopUpID") as! PopUpRegistro
- self.addChildViewController(popOverVC)
- popOverVC.view.frame = self.view.frame
- self.view.addSubview(popOverVC.view)
- popOverVC.didMove(toParentViewController: self)
- }
- })
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement