Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func showLoginSignUp(){
- var loginAlert:UIAlertController = UIAlertController(title: "Please Login", message: "Please sign up or login", preferredStyle: UIAlertControllerStyle.Alert)
- loginAlert.addTextFieldWithConfigurationHandler({
- textfield in
- textfield.placeholder = "Your username"
- })
- loginAlert.addTextFieldWithConfigurationHandler({
- textfield in
- textfield.placeholder = "Your password"
- textfield.secureTextEntry = true
- })
- loginAlert.addAction(UIAlertAction(title: "Login", style: UIAlertActionStyle.Default, handler: {
- alertAction in
- let textFields:NSArray = loginAlert.textFields! as NSArray
- let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
- let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
- PFUser.logInWithUsernameInBackground(usernameTextfield.text, password: passwordTextfield.text){
- (user:PFUser!, error:NSError!)->Void in
- if ((user) != nil){
- println("Login successful")
- var installation:PFInstallation = PFInstallation.currentInstallation()
- installation.addUniqueObject("Reload", forKey: "channels")
- installation["user"] = PFUser.currentUser()
- installation.saveInBackground()
- }else{
- println("Login failed")
- }
- }
- }))
- loginAlert.addAction(UIAlertAction(title: "Sign Up", style: UIAlertActionStyle.Default, handler: {
- alertAction in
- let textFields:NSArray = loginAlert.textFields! as NSArray
- let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField
- let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField
- var sweeter:PFUser = PFUser()
- sweeter.username = usernameTextfield.text
- sweeter.password = passwordTextfield.text
- sweeter.signUpInBackgroundWithBlock{
- (success:Bool!, error:NSError!)->Void in
- if !(error != nil){
- println("Sign Up successfull")
- var installation:PFInstallation = PFInstallation.currentInstallation()
- installation.addUniqueObject("Reload", forKey: "channels")
- installation["user"] = PFUser.currentUser()
- installation.saveInBackground()
- }else{
- let errorString = error.localizedDescription
- println(errorString)
- }
- }
- }))
- self.presentViewController(loginAlert, animated: true, completion: nil)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement