Skip to content

Commit

Permalink
Google login added with validation utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush Awasthi committed Jan 8, 2019
1 parent 24d8e8d commit c6f1979
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 2 deletions.
6 changes: 5 additions & 1 deletion KiwiPods.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "KiwiPods"
s.version = "0.0.2"
s.version = "0.0.3"
s.summary = "sdfgdgf"

# This description is used to generate tags and improve search results.
Expand Down Expand Up @@ -119,6 +119,10 @@ Pod::Spec.new do |s|
twitter.source_files = "KiwiPods/Social/Twitter/**/*.{h,m,swift}"
twitter.dependency 'TwitterKit'
end
socialMedia.subspec 'Google' do |google|
google.source_files = "KiwiPods/Social/Google/**/*.{h,m,swift}"
google.dependency 'GoogleSignIn'
end
end

s.subspec 'ImagePicker' do |imagePicker|
Expand Down
16 changes: 16 additions & 0 deletions KiwiPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/* Begin PBXBuildFile section */
38F04F541C2C888359AB8568 /* Pods_KiwiPods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 41185E9826A76800BF01C8A8 /* Pods_KiwiPods.framework */; };
D66402A921E4D4C70024B3D3 /* ValidationsUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66402A821E4D4C70024B3D3 /* ValidationsUtils.swift */; };
D66402AF21E4D4FF0024B3D3 /* GoogleHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66402AE21E4D4FF0024B3D3 /* GoogleHandler.swift */; };
D66ADF4121D50488004499F2 /* HashTextView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66ADF3E21D50488004499F2 /* HashTextView.swift */; };
D66ADF4221D50488004499F2 /* UILinkLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66ADF4021D50488004499F2 /* UILinkLabel.swift */; };
D66ADF4F21D504B0004499F2 /* ImagePickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D66ADF4321D504AD004499F2 /* ImagePickerController.swift */; };
Expand All @@ -31,6 +33,8 @@
41185E9826A76800BF01C8A8 /* Pods_KiwiPods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_KiwiPods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
807FADC5BC231460701B403A /* Pods-KiwiPods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KiwiPods.release.xcconfig"; path = "Pods/Target Support Files/Pods-KiwiPods/Pods-KiwiPods.release.xcconfig"; sourceTree = "<group>"; };
C57934D16A5207D271DDC35C /* Pods-KiwiPods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KiwiPods.debug.xcconfig"; path = "Pods/Target Support Files/Pods-KiwiPods/Pods-KiwiPods.debug.xcconfig"; sourceTree = "<group>"; };
D66402A821E4D4C70024B3D3 /* ValidationsUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ValidationsUtils.swift; sourceTree = "<group>"; };
D66402AE21E4D4FF0024B3D3 /* GoogleHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GoogleHandler.swift; sourceTree = "<group>"; };
D66ADF3E21D50488004499F2 /* HashTextView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HashTextView.swift; sourceTree = "<group>"; };
D66ADF4021D50488004499F2 /* UILinkLabel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UILinkLabel.swift; sourceTree = "<group>"; };
D66ADF4321D504AD004499F2 /* ImagePickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImagePickerController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -73,6 +77,14 @@
name = Pods;
sourceTree = "<group>";
};
D66402AD21E4D4FF0024B3D3 /* Google */ = {
isa = PBXGroup;
children = (
D66402AE21E4D4FF0024B3D3 /* GoogleHandler.swift */,
);
path = Google;
sourceTree = "<group>";
};
D66ADF3D21D50488004499F2 /* HashTextView */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -110,6 +122,7 @@
D66ADF5D21D504D8004499F2 /* Social */ = {
isa = PBXGroup;
children = (
D66402AD21E4D4FF0024B3D3 /* Google */,
D66ADF5B21D504BA004499F2 /* Facebook */,
D66ADF5C21D504C6004499F2 /* Twitter */,
);
Expand Down Expand Up @@ -158,6 +171,7 @@
D66ADF3D21D50488004499F2 /* HashTextView */,
D66ADF3F21D50488004499F2 /* UILinkLabel */,
D6B031672189D2C9003431C6 /* Networking */,
D66402A821E4D4C70024B3D3 /* ValidationsUtils.swift */,
D6B031602189D172003431C6 /* Info.plist */,
);
path = KiwiPods;
Expand Down Expand Up @@ -311,6 +325,8 @@
D66ADF5821D504B0004499F2 /* ImagePicker.swift in Sources */,
D66ADF4F21D504B0004499F2 /* ImagePickerController.swift in Sources */,
D66ADF5421D504B0004499F2 /* TwitterHelper.swift in Sources */,
D66402AF21E4D4FF0024B3D3 /* GoogleHandler.swift in Sources */,
D66402A921E4D4C70024B3D3 /* ValidationsUtils.swift in Sources */,
D66ADF5521D504B0004499F2 /* ImagePickerCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
50 changes: 50 additions & 0 deletions KiwiPods/Social/Google/GoogleHandler.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// GoogleHandler.swift
//
//
// Created by KiwiTech on 07/01/19.
// Copyright © 2019 KiwiTech. All rights reserved.
//

import UIKit
import GoogleSignIn
class GoogleHandler: NSObject {
static let `shared` = GoogleHandler()
override private init() {
super.init()
GIDSignIn.sharedInstance()?.delegate = self
}
fileprivate var loginCompletion: ((String?, Error?) -> Void)?
fileprivate var loginHandlerController: UIViewController?
func getUser(from controller: UIViewController, completion: @escaping (_ token: String?, _ error: Error?) -> Void) {
if let user = GIDSignIn.sharedInstance()?.currentUser {
loginCompletion = nil
completion(user.authentication.idToken, nil)
} else {
loginCompletion = completion
loginHandlerController = controller
GIDSignIn.sharedInstance()?.uiDelegate = self
GIDSignIn.sharedInstance()?.signIn()
}
}
}
extension GoogleHandler: GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
guard error == nil else {
loginCompletion?(nil, error)
return
}
loginCompletion?(user.authentication.idToken, nil)
}
}
extension GoogleHandler: GIDSignInUIDelegate {
func sign(_ signIn: GIDSignIn!, present viewController: UIViewController!) {
guard let controller = loginHandlerController else {
return
}
controller.present(viewController, animated: true, completion: nil)
}
func sign(_ signIn: GIDSignIn!, dismiss viewController: UIViewController!) {
viewController.dismiss(animated: true, completion: nil)
}
}
166 changes: 166 additions & 0 deletions KiwiPods/ValidationsUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//
// ValidationsUtils.swift
// Treble
//
// Created by kiwitech on 03/02/17.
// Copyright © 2016 KiwiTech. All rights reserved.
//

import UIKit

class ValidationsUtils: NSObject {
//-----------------------------------------------
// Mark Email validation
//-----------------------------------------------
class func validateEmail(emailID: String) -> Bool {
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
// NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
let emailTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegEx)
return emailTest.evaluate(with:
emailID)
}
//-----------------------------------------------
// Alpha - Numeric validation
//-----------------------------------------------
class func alphanumericValidation(validation: String) -> Bool {
let alphanumericRegEx = "^[a-zA-Z0-9]+$"
let alphanumericTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", alphanumericRegEx)
return alphanumericTest.evaluate(with: validation)
}
//-----------------------------------------------
// Mark number validation
//-----------------------------------------------
class func onlyNumberValidation(number: String) -> Bool {
let nameRegex: String = "^[0-9]+$"
let nameTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", nameRegex)
return nameTest.evaluate(with: number)
}
//-----------------------------------------------
// Mark number validation
//-----------------------------------------------
class func onlyNumberValidationWithDash(number: String) -> Bool {
let nameRegex: String = "^[0-9 '-]+$"
let nameTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", nameRegex)
return nameTest.evaluate(with: number)
}
//-----------------------------------------------
// Mark enter only alphabets
//-----------------------------------------------
class func onlyAlphabetsValidation(alphabet: String) -> Bool {
let nameRegex: String = "^[a-zA-Z '-]+$"
///^[a-zA-Z ]*$/
let nameTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", nameRegex)
return nameTest.evaluate(with: alphabet)
// return true
}
class func onlyAlphabetsWithSpaceValidation(alphabet: String) -> Bool {
let nameRegex: String = "^[a-zA-Z ]+$"
let nameTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", nameRegex)
return nameTest.evaluate(with: alphabet)
}
class func onlyAlphaNumericWithSpaceValidation(alphabet: String) -> Bool {
let nameRegex: String = "^[a-zA-Z0-9 ]+$"
let nameTest: NSPredicate = NSPredicate(format: "SELF MATCHES %@", nameRegex)
return nameTest.evaluate(with: alphabet)
}
//-----------------------------------------------
// Mark mathch password
//-----------------------------------------------
class func confirmationPasswordValidation(password: String, confirmationPassword: String) -> Bool {
if password == confirmationPassword {
return true
} else {
return false
}
}
var tableSourceList: [[String]] = [[Int](0..<20).map({ "section 0, cell \($0)" })]
class func contentView(text: String) -> UIView {
let view = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 64))
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let label = UILabel(frame: view.bounds)
label.frame.origin.x = 10
label.frame.origin.y = 10
label.frame.size.width -= label.frame.origin.x
label.frame.size.height -= label.frame.origin.y
label.autoresizingMask = [.flexibleWidth, .flexibleHeight]
label.text = text
label.numberOfLines = 2
label.textColor = UIColor.white
view.addSubview(label)
return view
}
class func isEmpty(text: String) -> Bool {
if text.trimmingCharacters(in: CharacterSet.whitespaces).isEmpty {
return true
}
return false
}
class func trimeedCount(text: String) -> Int {

return text.trimmingCharacters(in: CharacterSet.whitespaces).count
}
class func isValidCountPassword(passwordString: String) -> Bool {
if passwordString.count >= 4 {
return true
}
return false
}
class func isValidPassword(passwordString: String) -> Bool {
if passwordString.count < 4 || passwordString.count > 24 {
return false
}
return true
}
class func isValidUsername(usernameString: String) -> Bool {
let stricterFilterString = "^([\\w&-]+)$"
let usernameTest = NSPredicate(format: "SELF MATCHES %@", stricterFilterString)
return usernameTest.evaluate(with: usernameString)
}
class func hasCharacterInString(string: String) -> Bool {
let stricterFilterString = ".*[a-zA-Z]+.*"
let stringTest = NSPredicate(format: "SELF MATCHES %@", stricterFilterString)
return stringTest.evaluate(with: string)
}
class func isValidCountCharacterLimit(textString: String) -> Bool {
if textString.count > 0 && textString.count <= 30 {
return true
}
return false
}

class func isValidCountOfMobile(textString: String) -> Bool {
if textString.count != 10 {
return false
}
return true
}
class func isValidZipCode(textString: String) -> Bool {
if textString.count != 5 {
return false
}
return true
}
class func formatPhoneNumber(contactStr: String) -> String {
let range = contactStr.range(of: contactStr)
let strippedValue = contactStr.replacingOccurrences(of: "[^0-9]", with: "", options: .regularExpression, range: range)
var formattedString = ""
if strippedValue.count == 0 {
formattedString = ""
} else if strippedValue.count < 3 {
formattedString = strippedValue
} else if strippedValue.count == 3 {
formattedString = strippedValue
} else if strippedValue.count < 6 {
let startIndex = strippedValue.index(strippedValue.startIndex, offsetBy: 3)
formattedString = "(" + String(strippedValue[...startIndex]) + ") " + String(strippedValue[startIndex...])
} else if strippedValue.count == 6 {
let startIndex = strippedValue.index(strippedValue.startIndex, offsetBy: 3)
formattedString = "(" + String(strippedValue[...startIndex]) + ") " + String(strippedValue[startIndex...]) + " - "
} else if strippedValue.count <= 10 {
//let startIndex = strippedValue.index(strippedValue.startIndex, offsetBy: 3)
// formattedString = "(" + String(strippedValue[...startIndex]) + ") " + strippedValue.substring(with: NSMakeRange(0, contactStr.count)) + " - " + String(strippedValue[startIndex...])
} else if strippedValue.count >= 11 {
}
return formattedString
}
}
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ target 'KiwiPods' do
pod 'SDWebImage'
pod 'TwitterKit'
pod 'MBProgressHUD'
# Pods for KiwiPods
pod 'GoogleSignIn'

end

0 comments on commit c6f1979

Please sign in to comment.