//i’m doing callbacks, mostly just want to make sure there isn’t some simple SDK call I can make instead of directly hitting api like this.
Also are there any http status codes to verify if user doesn’t exist or something like that? Like 404?
func forgotPassword(email:String) {
guard let values = plistValues(bundle: Bundle.main) else {
return
}
let headers = ["content-type": "application/json"]
let parameters = [
"client_id": values.clientId,
"email": email,
"connection": "Username-Password-Authentication"
]
guard let postData = try? JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted) else {
self.forgotDelegate?.onForgotPasswordError(.errorParsing)
return
}
let url = URL(string: "https://\(values.domain)/dbconnections/change_password")!
var req = URLRequest(url: url)
req.httpMethod = "POST"
req.allHTTPHeaderFields = headers
req.httpBody = postData
URLSession.shared.dataTask(with: req) { [weak self] (data, response, error) in
guard error == nil else {
self?.forgotDelegate?.onForgotPasswordError(.networkError)
return
}
guard let resp = response as? HTTPURLResponse
, resp.statusCode >= 200 && resp.statusCode <= 399 else {
self?.forgotDelegate?.onForgotPasswordError(.networkError)
return
}
self?.forgotDelegate?.onForgotPasswordReset()
}.resume()
}