Advertisement
Guest User

Untitled

a guest
Nov 1st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. import UIKit
  2. //import Parse
  3.  
  4.  
  5. class RegisterPageViewController: UIViewController {
  6.  
  7. @IBOutlet weak var userEmailTextField: UITextField!
  8. @IBOutlet weak var userPasswordTextField: UITextField!
  9. @IBOutlet weak var repeatPasswordTextField: UITextField!
  10.  
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13.  
  14. // Do any additional setup after loading the view.
  15. }
  16.  
  17. override func didReceiveMemoryWarning() {
  18. super.didReceiveMemoryWarning()
  19. // Dispose of any resources that can be recreated.
  20. }
  21.  
  22.  
  23. @IBAction func registerButtonTapped(sender: AnyObject) {
  24.  
  25. let userEmail = userEmailTextField.text;
  26. let userPassword = userPasswordTextField.text;
  27. let userRepeatPassword = repeatPasswordTextField.text;
  28.  
  29. // Check for empty fields
  30. if(userEmail.isEmpty || userPassword.isEmpty || userRepeatPassword.isEmpty)
  31. {
  32.  
  33. // Display alert message
  34.  
  35. displayMyAlertMessage("All fields are required");
  36.  
  37. return;
  38. }
  39.  
  40. //Check if passwords match
  41. if(userPassword != userRepeatPassword)
  42. {
  43. // Display an alert message
  44. displayMyAlertMessage("Passwords do not match");
  45. return;
  46.  
  47. }
  48.  
  49.  
  50.  
  51.  
  52. // Store data
  53. let myUser:PFUser = PFUser();
  54.  
  55. myUser.username = userEmail
  56. myUser.password = userPassword
  57. myUser.email = userEmail
  58.  
  59.  
  60. myUser.signUpInBackgroundWithBlock {
  61. (success:Bool!, error:NSError!) -> Void in
  62.  
  63. println("User successfully registered")
  64.  
  65. // Display alert message with confirmation.
  66. var myAlert = UIAlertController(title:"Alert", message:"Registration is successful. Thank you!", preferredStyle: UIAlertControllerStyle.Alert);
  67.  
  68. let okAction = UIAlertAction(title:"Ok", style:UIAlertActionStyle.Default){ action in
  69. self.dismissViewControllerAnimated(true, completion:nil);
  70. }
  71.  
  72. myAlert.addAction(okAction);
  73. self.presentViewController(myAlert, animated:true, completion:nil);
  74.  
  75.  
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. }
  84.  
  85.  
  86. func displayMyAlertMessage(userMessage:String)
  87. {
  88.  
  89. var myAlert = UIAlertController(title:"Alert", message:userMessage, preferredStyle: UIAlertControllerStyle.Alert);
  90.  
  91. let okAction = UIAlertAction(title:"Ok", style:UIAlertActionStyle.Default, handler:nil);
  92.  
  93. myAlert.addAction(okAction);
  94.  
  95. self.presentViewController(myAlert, animated:true, completion:nil);
  96.  
  97. }
  98.  
  99. @IBAction func iHaveAnAccountButtonTapped(sender: AnyObject) {
  100. self.dismissViewControllerAnimated(true, completion: nil)
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement