From 792cc508b8551966ab1f4a67f99fab6ae3d479a7 Mon Sep 17 00:00:00 2001 From: Okechi Date: Tue, 1 Mar 2016 16:24:07 -0500 Subject: [PATCH] added some validation controls for login and sign in --- GetHip.xcodeproj/project.pbxproj | 8 +-- GetHip/LoginController.swift | 49 +++++++++++---- GetHip/Main.storyboard | 6 +- GetHip/SignInController.swift | 76 ++++++++++++++++++------ GetHip/SongSelectionViewController.swift | 16 ++--- 5 files changed, 111 insertions(+), 44 deletions(-) diff --git a/GetHip.xcodeproj/project.pbxproj b/GetHip.xcodeproj/project.pbxproj index b3ce080..3083304 100644 --- a/GetHip.xcodeproj/project.pbxproj +++ b/GetHip.xcodeproj/project.pbxproj @@ -58,6 +58,7 @@ 3E43B8C91C37639C002F97A7 /* FBSDKCoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E1BDA751C3713F900EE3B84 /* FBSDKCoreKit.framework */; }; 3E43B8CA1C37639C002F97A7 /* FBSDKLoginKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E43B8C51C375E73002F97A7 /* FBSDKLoginKit.framework */; }; 3E43B8CF1C376F9F002F97A7 /* Logo.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E43B8CE1C376F9F002F97A7 /* Logo.png */; }; + 3E4AA5211C853E1A00746839 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E4AA5201C853E1A00746839 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png */; }; 3E50E0401C74B97300EB9EA9 /* BackToHomeScreenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E50E03F1C74B97300EB9EA9 /* BackToHomeScreenViewController.swift */; }; 3E5485B31C69A7DA00E7D5AB /* LoadingPartyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E5485B21C69A7DA00E7D5AB /* LoadingPartyViewController.swift */; }; 3E5485B51C69CE2F00E7D5AB /* InvitedCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E5485B41C69CE2F00E7D5AB /* InvitedCollectionViewCell.swift */; }; @@ -120,7 +121,6 @@ 3E7D37D71C75D80F002E682F /* Lower@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E7D37D61C75D80F002E682F /* Lower@2x.png */; }; 3E7D37D91C75D882002E682F /* B2P Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E7D37D81C75D882002E682F /* B2P Icon@2x.png */; }; 3E7D37DB1C75D899002E682F /* B2P Button@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E7D37DA1C75D899002E682F /* B2P Button@2x.png */; }; - 3E7D37DD1C75D9C3002E682F /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E7D37DC1C75D9C3002E682F /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png */; }; 3EB8845D1C6C647700CCDCCE /* Add More@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3EB8845B1C6C647700CCDCCE /* Add More@2x.png */; }; 3EB8845E1C6C647700CCDCCE /* Leave Party@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3EB8845C1C6C647700CCDCCE /* Leave Party@2x.png */; }; 3EBE97661C53CEDA0079B54A /* Send Invites Button.png in Resources */ = {isa = PBXBuildFile; fileRef = 3EBE97651C53CEDA0079B54A /* Send Invites Button.png */; }; @@ -205,6 +205,7 @@ 3E43B8C41C375E73002F97A7 /* Bolts.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Bolts.framework; path = ../../FacebookSDK/Bolts.framework; sourceTree = ""; }; 3E43B8C51C375E73002F97A7 /* FBSDKLoginKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FBSDKLoginKit.framework; path = ../../FacebookSDK/FBSDKLoginKit.framework; sourceTree = ""; }; 3E43B8CE1C376F9F002F97A7 /* Logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Logo.png; path = "../../../Dropbox/gethip/Screens/6 Login/Assets/Logo.png"; sourceTree = ""; }; + 3E4AA5201C853E1A00746839 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png"; path = "../../../Dropbox/gethip/Screens/6 Back to Party/6 Back to Party/Asset/Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png"; sourceTree = ""; }; 3E50E03F1C74B97300EB9EA9 /* BackToHomeScreenViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BackToHomeScreenViewController.swift; sourceTree = ""; }; 3E5485B21C69A7DA00E7D5AB /* LoadingPartyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadingPartyViewController.swift; sourceTree = ""; }; 3E5485B41C69CE2F00E7D5AB /* InvitedCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InvitedCollectionViewCell.swift; sourceTree = ""; }; @@ -283,7 +284,6 @@ 3E7D37D61C75D80F002E682F /* Lower@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Lower@2x.png"; path = "../../../Dropbox/Gethip/For final/Volume/i5 Volume/Lower@2x.png"; sourceTree = ""; }; 3E7D37D81C75D882002E682F /* B2P Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "B2P Icon@2x.png"; path = "../../../Dropbox/Gethip/For final/Back To Party/i5/B2P Icon@2x.png"; sourceTree = ""; }; 3E7D37DA1C75D899002E682F /* B2P Button@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "B2P Button@2x.png"; path = "../../../Dropbox/Gethip/For final/Back To Party/i5/B2P Button@2x.png"; sourceTree = ""; }; - 3E7D37DC1C75D9C3002E682F /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png"; path = "../../../.Trash/Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png"; sourceTree = ""; }; 3EB8845B1C6C647700CCDCCE /* Add More@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Add More@2x.png"; path = "../../../Dropbox/Gethip/Screens/iPhone 5 Party Screens/Party Screen/Assets/Add More@2x.png"; sourceTree = ""; }; 3EB8845C1C6C647700CCDCCE /* Leave Party@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Leave Party@2x.png"; path = "../../../Dropbox/Gethip/Screens/iPhone 5 Party Screens/Party Screen/Assets/Leave Party@2x.png"; sourceTree = ""; }; 3EBE97651C53CEDA0079B54A /* Send Invites Button.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Send Invites Button.png"; path = "../../../Dropbox/Gethip/Screens/Friends + Invite Screens/i6/Invite Friends/Send Invites Button.png"; sourceTree = ""; }; @@ -492,7 +492,7 @@ 3E6D438C1C78969A00CA805F /* CancelInvited@2x.png */, 3E6D438A1C78968C00CA805F /* Joining@2x.png */, 3E6D43851C782E3200CA805F /* Decline@2x.png */, - 3E7D37DC1C75D9C3002E682F /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png */, + 3E4AA5201C853E1A00746839 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png */, 3E7D37DA1C75D899002E682F /* B2P Button@2x.png */, 3E7D37D81C75D882002E682F /* B2P Icon@2x.png */, 3E7D37D61C75D80F002E682F /* Lower@2x.png */, @@ -809,6 +809,7 @@ 3E5BD3161C6C45CE00266B16 /* Party@2x.png in Resources */, 3E7D37D71C75D80F002E682F /* Lower@2x.png in Resources */, 3E4169491C385F1000B193AF /* 1x.png in Resources */, + 3E4AA5211C853E1A00746839 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png in Resources */, 3E5952641C39DBC900C88C71 /* Friends@2x.png in Resources */, 3E59528B1C39EB6100C88C71 /* Turntable@3x.png in Resources */, 3E5952661C39DBC900C88C71 /* Settings.png in Resources */, @@ -832,7 +833,6 @@ 3E5952711C39DC1E00C88C71 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@3x.png in Resources */, 3E6D438B1C78968C00CA805F /* Joining@2x.png in Resources */, 3E33EFDC1C5B56340011B9B5 /* No Friend Requests i5@2x.png in Resources */, - 3E7D37DD1C75D9C3002E682F /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2@2x.png in Resources */, 3E33EFDA1C5B56340011B9B5 /* Accept@2x.png in Resources */, 3E438AE91C5738EF0055C97A /* Star@2x.png in Resources */, 3E5BD3151C6C45CE00266B16 /* Home Copy@2x.png in Resources */, diff --git a/GetHip/LoginController.swift b/GetHip/LoginController.swift index 78f6dd7..003538a 100644 --- a/GetHip/LoginController.swift +++ b/GetHip/LoginController.swift @@ -18,20 +18,45 @@ class LoginController: UIViewController, PFLogInViewControllerDelegate, UITextFi @IBAction func loginBtnPressed(sender: UIButton){ - //check if user logging in with email, implement later - - PFUser.logInWithUsernameInBackground(userEmailField.text!, password: password.text!, block: { - (user, error) -> Void in + //check if user logging in with email + if(contains(self.userEmailField.text!, "@")){ + let predicate: NSPredicate = NSPredicate(format: "(email = %@)", argumentArray: [self.userEmailField.text!]) + var userQuery: PFQuery = PFQuery(className: "_User", predicate: predicate) - if(user != nil){ - self.performSegueWithIdentifier("LoginToHomeSegue", sender: self) - }else{ - var alert = UIAlertController(title: "Invalid Login", message: "Your username/email or password is incorrect!", preferredStyle: .Alert) - alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + //log in user through email look up in db + dispatch_async(dispatch_get_main_queue(), { + userQuery.getFirstObjectInBackgroundWithBlock({ + (object, error) -> Void in + + if(object != nil && error == nil){ + PFUser.logInWithUsernameInBackground(object!.objectForKey("username") as! String, password: self.password.text!, block: { + (user, error) -> Void in + + if(user != nil){ + self.performSegueWithIdentifier("LoginToHomeSegue", sender: self) + }else{ + var alert = UIAlertController(title: "Invalid Login", message: "Your username/email or password is incorrect!", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + } + }) } + }) + }) + }else{ + PFUser.logInWithUsernameInBackground(userEmailField.text!, password: password.text!, block: { + (user, error) -> Void in - self.presentViewController(alert, animated: true, completion: nil) - } - }) + if(user != nil){ + self.performSegueWithIdentifier("LoginToHomeSegue", sender: self) + }else{ + var alert = UIAlertController(title: "Invalid Login", message: "Your username/email or password is incorrect!", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + } + }) + } } diff --git a/GetHip/Main.storyboard b/GetHip/Main.storyboard index fd6cdd4..0e1a7a8 100644 --- a/GetHip/Main.storyboard +++ b/GetHip/Main.storyboard @@ -1646,9 +1646,9 @@ - - - + + + diff --git a/GetHip/SignInController.swift b/GetHip/SignInController.swift index 699986c..fd2143f 100644 --- a/GetHip/SignInController.swift +++ b/GetHip/SignInController.swift @@ -20,25 +20,67 @@ class SignInController: UIViewController, UINavigationControllerDelegate, UIImag @IBAction func saveNewProfile(sender: UIButton){ - var user = PFUser() - var img:PFFile = PFFile(data: UIImagePNGRepresentation(self.profilePic.image))! - user.username = userField.text! - user.password = passField.text! - user.email = emailField.text! - user.setObject(nameField.text!, forKey: "displayName") - user.setObject(img, forKey: "profilePicture") - - //sign up new user - user.signUpInBackgroundWithBlock({ - (succeeded: Bool, error: NSError?) -> Void in - - if error == nil { - self.performSegueWithIdentifier("SignedUpSegue", sender: self) - } - else{ + if(self.nameField.hasText() == false + || self.userField.hasText() == false + || self.emailField.hasText() == false + || self.passField.hasText() == false + || self.profilePic.image == nil){ + let alert = UIAlertController(title: "Invalid Registration", message: "We're missing some information from you, before we can start the party!", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + + }else{ + if(!(contains(self.userField.text!, "@") || contains(self.nameField.text!, "@"))){ + + let predicate: NSPredicate = NSPredicate(format: "((username = %@) OR (email = %@))", argumentArray: [self.nameField.text!,self.emailField.text!]) + var userQuery: PFQuery = PFQuery(className: "_User", predicate: predicate) + + dispatch_async(dispatch_get_main_queue(), { + userQuery.getFirstObjectInBackgroundWithBlock({ + (object, error) -> Void in + + if(object != nil && error == nil){ + let alert = UIAlertController(title: "User Info Taken", message: "Sorry this information is already registered to another user. Please try again.", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) + }else{ + var user = PFUser() + var img:PFFile = PFFile(data: UIImagePNGRepresentation(self.profilePic.image))! + user.username = self.userField.text! + user.password = self.passField.text! + user.email = self.emailField.text! + user.setObject(self.nameField.text!, forKey: "displayName") + user.setObject(img, forKey: "profilePicture") + + //sign up new user + user.signUpInBackgroundWithBlock({ + (succeeded: Bool, error: NSError?) -> Void in + + if error == nil { + self.performSegueWithIdentifier("SignedUpSegue", sender: self) + } + else{ + + } + }) + + } + }) + }) + + + }else{ + let alert = UIAlertController(title: "Illegal Characters", message: "The username or email you entered contains illegal characters such as: '@'", preferredStyle: .Alert) + alert.addAction(UIAlertAction(title: "OK", style: .Default, handler:{(action: UIAlertAction!) in alert.dismissViewControllerAnimated(true, completion: nil)})) + + self.presentViewController(alert, animated: true, completion: nil) } - }) + + } + } @IBAction func cancelSignUp(){ diff --git a/GetHip/SongSelectionViewController.swift b/GetHip/SongSelectionViewController.swift index b17f4a8..6cfea02 100644 --- a/GetHip/SongSelectionViewController.swift +++ b/GetHip/SongSelectionViewController.swift @@ -14,7 +14,6 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl var usr: [UserParseData] = [] var frnds: [FriendData] = [] var requestData: [FriendData] = [] - @IBOutlet weak var table: UITableView! @@ -67,7 +66,7 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl self.presentViewController(filterMenu, animated: true, completion: nil) } - private var filter: String! = "Songs" + var filter: String! = "Songs" @IBAction func cancelInvites(sender: UIBarButtonItem) { @@ -108,14 +107,15 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl switch self.filter{ //return number of rows for albums - case "albums": + case "Albums": var albumsQuery = MPMediaQuery.albumsQuery() var albums = albumsQuery.collections return albums.count + 1 //return number of rows for artists - case "artists": + case "Artists": var artistsQuery = MPMediaQuery.artistsQuery() + //artistsQuery var artists = artistsQuery.items return artists.count + 1 @@ -138,7 +138,7 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl switch self.filter{ //return albums cell - case "albums": + case "Albums": let cell = self.table.dequeueReusableCellWithIdentifier("AlbumCell", forIndexPath: indexPath) as? AlbumCell @@ -149,7 +149,7 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl //return artists cell - case "artists": + case "Artists": let cell = self.table.dequeueReusableCellWithIdentifier("ArtistCell", forIndexPath: indexPath) as? ArtistCell @@ -186,7 +186,7 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl switch self.filter{ //return albums cell - case "albums": + case "Albums": let cell = self.table.dequeueReusableCellWithIdentifier("AlbumCell", forIndexPath: indexPath) as? AlbumCell @@ -212,7 +212,7 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl return cell! //return artists cell - case "artists": + case "Artists": let cell = self.table.dequeueReusableCellWithIdentifier("ArtistCell", forIndexPath: indexPath) as? ArtistCell