Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. func showLoginSignUp(){
  2. var loginAlert:UIAlertController = UIAlertController(title: "Please Login", message: "Please sign up or login", preferredStyle: UIAlertControllerStyle.Alert)
  3.  
  4. loginAlert.addTextFieldWithConfigurationHandler({
  5. textfield in
  6. textfield.placeholder = "Your username"
  7. })
  8.  
  9. loginAlert.addTextFieldWithConfigurationHandler({
  10. textfield in
  11. textfield.placeholder = "Your password"
  12. textfield.secureTextEntry = true
  13. })
  14.  
  15. loginAlert.addAction(UIAlertAction(title: "Login", style: UIAlertActionStyle.Default, handler: {
  16. alertAction in
  17. let textFields:NSArray = loginAlert.textFields! as NSArray
  18. let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
  19. let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
  20.  
  21. PFUser.logInWithUsernameInBackground(usernameTextfield.text, password: passwordTextfield.text){
  22. (user:PFUser!, error:NSError!)->Void in
  23. if ((user) != nil){
  24. println("Login successful")
  25. var installation:PFInstallation = PFInstallation.currentInstallation()
  26. installation.addUniqueObject("Reload", forKey: "channels")
  27. installation["user"] = PFUser.currentUser()
  28. installation.saveInBackground()
  29.  
  30. }else{
  31. println("Login failed")
  32. }
  33.  
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
  40. }))
  41.  
  42. loginAlert.addAction(UIAlertAction(title: "Sign Up", style: UIAlertActionStyle.Default, handler: {
  43. alertAction in
  44. let textFields:NSArray = loginAlert.textFields! as NSArray
  45. let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
  46. let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
  47.  
  48. var sweeter:PFUser = PFUser()
  49. sweeter.username = usernameTextfield.text
  50. sweeter.password = passwordTextfield.text
  51.  
  52. sweeter.signUpInBackgroundWithBlock{
  53. (success:Bool!, error:NSError!)->Void in
  54. if !(error != nil){
  55. println("Sign Up successfull")
  56.  
  57.  
  58. var installation:PFInstallation = PFInstallation.currentInstallation()
  59. installation.addUniqueObject("Reload", forKey: "channels")
  60. installation["user"] = PFUser.currentUser()
  61. installation.saveInBackground()
  62.  
  63.  
  64. }else{
  65. let errorString = error.localizedDescription
  66. println(errorString)
  67.  
  68. }
  69.  
  70.  
  71. }
  72.  
  73.  
  74.  
  75. }))
  76.  
  77. self.presentViewController(loginAlert, animated: true, completion: nil)
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement