Skip to content

Commit

Permalink
Merge pull request #63 from Cidaas/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
cidaas-samples authored Apr 2, 2019
2 parents 69d96a8 + 4628de1 commit be45592
Show file tree
Hide file tree
Showing 54 changed files with 1,767 additions and 252 deletions.
2 changes: 1 addition & 1 deletion Cidaas.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'Cidaas'
s.version = '1.1.2'
s.version = '1.1.3'
s.summary = 'Native SDK for iOS providing login, registration and verification functionalities'
s.homepage = 'https://github.com/Cidaas/cidaas-sdk-ios-v2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,76 @@ public class UserActivityController {
}
}
}

// get user login info
public func getUserLoginInformation(userInfo: UserLoginInfoEntity, properties: Dictionary<String, String>, callback: @escaping(Result<UserLoginInfoResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil {
let error = WebAuthError.shared.propertyMissingException()
// log error
let loggerMessage = "Read properties failure : " + "Error Code - " + String(describing: error.errorCode) + ", Error Message - " + error.errorMessage + ", Status Code - " + String(describing: error.statusCode)
logw(loggerMessage, cname: "cidaas-sdk-error-log")

DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}

// validating fields
if (userInfo.sub == "" && userInfo.verificationType == "") {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "sub or verificationType must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
}

// get access token from sub
AccessTokenController.shared.getAccessToken(sub: userInfo.sub) {
switch $0 {
case .failure(let error):
// log error
let loggerMessage = "Access token failure : " + "Error Code - " + String(describing: error.errorCode) + ", Error Message - " + error.errorMessage + ", Status Code - " + String(describing: error.statusCode)
logw(loggerMessage, cname: "cidaas-sdk-error-log")

// return failure callback
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
case .success(let tokenResponse):
// log success
let loggerMessage = "Access Token success : " + "Access Token - " + String(describing: tokenResponse.data.access_token)
logw(loggerMessage, cname: "cidaas-sdk-success-log")

// call get login user info service
UserActivityService.shared.getUserLoginInformation(accessToken: tokenResponse.data.access_token, userInfo: userInfo, properties: properties) {
switch $0 {
case .failure(let error):
// log error
let loggerMessage = "User Login Info service failure : " + "Error Code - " + String(describing: error.errorCode) + ", Error Message - " + error.errorMessage + ", Status Code - " + String(describing: error.statusCode)
logw(loggerMessage, cname: "cidaas-sdk-error-log")

// return failure callback
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
case .success(let tenantInfoResponse):
// log success
let loggerMessage = "User User Login Info service success : " + "Count - " + String(describing: tenantInfoResponse.data.count)
logw(loggerMessage, cname: "cidaas-sdk-success-log")

// return callback
DispatchQueue.main.async {
callback(Result.success(result: tenantInfoResponse))
}
}
}

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class FaceVerificationController {
}

// configure Face from properties
public func configureFace(sub: String, photo: UIImage, logoUrl: String, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollFaceResponseEntity>) -> Void) {
public func configureFace(sub: String, photo: UIImage, logoUrl: String, attempt: Int32, intermediate_id: String = "", properties: Dictionary<String, String>, callback: @escaping(Result<EnrollFaceResponseEntity>) -> Void) {
// null check
if properties["DomainURL"] == "" || properties["DomainURL"] == nil || properties["ClientId"] == "" || properties["ClientId"] == nil {
let error = WebAuthError.shared.propertyMissingException()
Expand Down Expand Up @@ -66,6 +66,19 @@ public class FaceVerificationController {
let loggerMessage = "Access Token success : " + "Access Token - " + String(describing: tokenResponse.data.access_token)
logw(loggerMessage, cname: "cidaas-sdk-success-log")


// if attempt > 1 call enroll
if attempt > 1 {
let enrollFaceEntity = EnrollFaceEntity()
enrollFaceEntity.statusId = self.statusId
enrollFaceEntity.attempt = attempt

// call enroll service
FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback)
return
}


// construct object
var setupFaceEntity = SetupFaceEntity()
setupFaceEntity.logoUrl = logoUrl
Expand Down Expand Up @@ -130,22 +143,10 @@ public class FaceVerificationController {

let enrollFaceEntity = EnrollFaceEntity()
enrollFaceEntity.statusId = self.statusId
enrollFaceEntity.attempt = attempt

// call enroll service
FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties) {
switch $0 {
case .failure(let error):
// return failure callback
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
return
case .success(let enrollResponse):
DispatchQueue.main.async {
callback(Result.success(result: enrollResponse))
}
}
}
FaceVerificationController.shared.enrollFaceRecognition(access_token: tokenResponse.data.access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties, callback: callback)

break
case .failure(let error):
Expand Down Expand Up @@ -300,9 +301,9 @@ public class FaceVerificationController {
}

// validating fields
if (enrollFaceEntity.statusId == "" || enrollFaceEntity.userDeviceId == "") {
if (enrollFaceEntity.statusId == "" || enrollFaceEntity.userDeviceId == "" || enrollFaceEntity.attempt == 0) {
let error = WebAuthError.shared.propertyMissingException()
error.errorMessage = "statusId or userDeviceId must not be empty"
error.errorMessage = "statusId or userDeviceId or attempt must not be empty"
DispatchQueue.main.async {
callback(Result.failure(error: error))
}
Expand Down Expand Up @@ -387,11 +388,12 @@ public class FaceVerificationController {
timer.invalidate()

// construct object
let enrollFaceEntity = EnrollFaceEntity()
enrollFaceEntity.usage_pass = Cidaas.intermediate_verifiation_id
let enrollFaceUsageEntity = EnrollFaceEntity()
enrollFaceUsageEntity.usage_pass = Cidaas.intermediate_verifiation_id
enrollFaceUsageEntity.attempt = enrollFaceEntity.attempt

// call enroll service
FaceVerificationService.shared.enrollFace(accessToken:access_token, photo: photo, enrollFaceEntity: enrollFaceEntity, properties: properties) {
FaceVerificationService.shared.enrollFace(accessToken:access_token, photo: photo, enrollFaceEntity: enrollFaceUsageEntity, properties: properties) {
switch $0 {
case .failure(let error):
// log error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DeviceAuthenticationResponseEntity.swift
// Cidaas
//
// Created by ganesh on 18/02/19.
//

import Foundation

public class DeviceAuthenticationResponseEntity: Codable {
// properties
public var success: Bool = false
public var status: Int32 = 400
public var message: String = ""

// Constructors
public init() {

}

public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.success = try container.decodeIfPresent(Bool.self, forKey: .success) ?? false
self.status = try container.decodeIfPresent(Int32.self, forKey: .status) ?? 400
self.message = try container.decodeIfPresent(String.self, forKey: .message) ?? ""
}
}
Loading

0 comments on commit be45592

Please sign in to comment.