mirror of
https://github.com/wahyd4/Yep.git
synced 2026-08-15 15:55:59 +10:00
registerMobile
This commit is contained in:
@@ -55,6 +55,32 @@ func validateMobile(mobile: String, withAreaCode areaCode: String, #failureHandl
|
||||
|
||||
}
|
||||
|
||||
func registerMobile(mobile: String, withAreaCode areaCode: String, #nickname: String, #failureHandler: ((Resource<(Bool)>, Reason, NSData?) -> ())?, #completion: Bool -> Void) {
|
||||
let requestParameters = [
|
||||
"mobile": mobile,
|
||||
"phone_code": areaCode,
|
||||
"nickname": nickname,
|
||||
]
|
||||
|
||||
let parse: JSONDictionary -> Bool? = { data in
|
||||
if let state = data["state"] as? String {
|
||||
if state == "blocked" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
let resource = jsonResource(path: "/api/v1/registration/create", method: .POST, requestParameters: requestParameters, parse: parse)
|
||||
|
||||
if let failureHandler = failureHandler {
|
||||
apiRequest({_ in}, baseURL, resource, failureHandler, completion)
|
||||
} else {
|
||||
apiRequest({_ in}, baseURL, resource, defaultFailureHandler, completion)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Login
|
||||
|
||||
func sendVerifyCode(ofMobile mobile: String, withAreaCode areaCode: String, #failureHandler: ((Resource<Bool>, Reason, NSData?) -> ())?, #completion: Bool -> Void) {
|
||||
|
||||
@@ -68,8 +68,32 @@ class RegisterPickMobileViewController: UIViewController {
|
||||
if available {
|
||||
println("ValidateMobile: available")
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.performSegueWithIdentifier("showRegisterVerifyMobile", sender: ["mobile" : mobile, "areaCode": areaCode])
|
||||
registerMobile(mobile, withAreaCode: areaCode, nickname: YepUserDefaults.nickname()!, failureHandler: { (resource, reason, data) in
|
||||
defaultFailureHandler(forResource: resource, withFailureReason: reason, data)
|
||||
|
||||
if let errorMessage = errorMessageInData(data) {
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
YepAlert.alertSorry(message: errorMessage, inViewController: self, withDismissAction: { () -> Void in
|
||||
mobileNumberTextField.becomeFirstResponder()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}, completion: { created in
|
||||
if created {
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.performSegueWithIdentifier("showRegisterVerifyMobile", sender: ["mobile" : mobile, "areaCode": areaCode])
|
||||
})
|
||||
|
||||
} else {
|
||||
dispatch_async(dispatch_get_main_queue(), { () -> Void in
|
||||
self.nextButton.enabled = false
|
||||
|
||||
YepAlert.alertSorry(message: "registerMobile failed", inViewController: self, withDismissAction: { () -> Void in
|
||||
mobileNumberTextField.becomeFirstResponder()
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user