Commit 2eadac7e by Anand.suthar

Add magento refresh token

parent cee4135a
......@@ -6,38 +6,6 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Bhagyashree/Sunarc/Other/HTTP/HTTP.swift"
timestampString = "553782528.910941"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "64"
endingLineNumber = "64"
landmarkName = "connectWithRequestObject(api:parameters:method:contentType:indicator:success:failure:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Bhagyashree/Sunarc/Other/HTTP/HTTP.swift"
timestampString = "553782528.911128"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "76"
endingLineNumber = "76"
landmarkName = "connectWithRequestObject(api:parameters:method:contentType:indicator:success:failure:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
......@@ -58,7 +26,7 @@
moduleName = "Bhagyashree"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/sunarcmac/Documents/Futurecommerce/Fengshui-Seller-iOS/Bhagyashree/Sunarc/Controller/Me/CorporateCultureViewController.swift"
timestampString = "556268845.984683"
timestampString = "556273458.770355"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "22"
......@@ -73,7 +41,7 @@
moduleName = "Bhagyashree"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/sunarcmac/Documents/Futurecommerce/Fengshui-Seller-iOS/Bhagyashree/Sunarc/Controller/Me/CorporateCultureViewController.swift"
timestampString = "556268845.988762"
timestampString = "556273458.774583"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "22"
......@@ -88,7 +56,7 @@
moduleName = "Bhagyashree"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/sunarcmac/Documents/Futurecommerce/Fengshui-Seller-iOS/Bhagyashree/Sunarc/Controller/Me/CorporateCultureViewController.swift"
timestampString = "556268845.991715"
timestampString = "556273458.780182"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "22"
......@@ -103,7 +71,7 @@
moduleName = "Bhagyashree"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/sunarcmac/Documents/Futurecommerce/Fengshui-Seller-iOS/Bhagyashree/Sunarc/Controller/Me/CorporateCultureViewController.swift"
timestampString = "556268845.995146"
timestampString = "556273458.785668"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "22"
......
......@@ -28,9 +28,23 @@ extension User {
}
}
}
class func regenerateToken(_ completion: @escaping () -> Void) {
let parameters: [String: Any] = ["emailId": User.customerEmail!]
HTTP().connectionWithRequestObject(api: API.REGENERATE_TOKEN, parameters: parameters, method: .post, indicator: true, success: { (response) in
if let magentoToken = response as? String {
User.bearerToken = magentoToken
}
completion()
}) { (error) in
completion()
}
}
class func login(email: String, password: String, success: @escaping () -> Void, failure: @escaping (_ message: String) -> Void) {
......
......@@ -32,6 +32,7 @@ class API {
static let ENQUIRY_FEEDBACK = "/rest/V1/merchant/comment"
static let COMPLETED_SERVICE = "/rest/V1/service/completed"
static let CORPORATE_CULTURE = "/rest/V1/bannerInfo"
static let REGENERATE_TOKEN = "/rest/V1/customer/regenerate"
// Appointment
......
......@@ -102,7 +102,15 @@ class HTTP: NSObject {
HTTP().connectionWithRequestObject(api: api, parameters: parameters, method: method, indicator: indicator, success: success, failure: failure)
}
} else {
failure("Authorization failed")
User.regenerateToken { // generate magento token
if contentType == "application/x-www-form-urlencoded" {
HTTP().connectionWithRequestObjectFormUrl(api: api, parameters: parameters, method: method, indicator: indicator, success: success, failure: failure)
} else {
HTTP().connectionWithRequestObject(api: api, parameters: parameters, method: method, indicator: indicator, success: success, failure: failure)
}
}
}
} else {
if let result = response.result.value{
......@@ -173,8 +181,6 @@ class HTTP: NSObject {
if let tokenValue = response.response?.allHeaderFields["token"] as? String {
let usernamePasswordMd5:String = (API_USER_NAME+":"+API_KEY).md5;
print(usernamePasswordMd5)
let authkey = (usernamePasswordMd5+":"+tokenValue).md5;
defaults.set(authkey, forKey: "authKey")
defaults.synchronize()
......@@ -185,7 +191,15 @@ class HTTP: NSObject {
HTTP().connectionWithoutRequestObject(api: api, parameters: parameters, method: method, indicator: indicator, success: success, failure: failure)
}
} else {
failure("Authorization failed")
User.regenerateToken { // generate magento token
if contentType == "application/x-www-form-urlencoded" {
HTTP().connectionWithoutRequestObjectFormUrl(api: api, parameters: parameters, method: method, indicator: indicator, success: success, failure: failure)
} else {
HTTP().connectionWithoutRequestObject(api: api, parameters: parameters, method: method, indicator: indicator, success: success, failure: failure)
}
}
}
} else {
if let result = response.result.value{
......
......@@ -526,7 +526,7 @@
</constraints>
<nil key="textColor"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="next"/>
<textInputTraits key="textInputTraits" keyboardType="emailAddress" returnKeyType="next"/>
<connections>
<outlet property="delegate" destination="Bhz-MZ-b15" id="afw-7F-lJM"/>
</connections>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment