This is a migrated thread and some comments may be shown as answers.

Fetch user with email always returning nil error

1 Answer 17 Views
Apple iOS SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kevin
Top achievements
Rank 1
Kevin asked on 16 Mar 2016, 01:57 PM

i am trying to send a password reset to a user but when i do

EVUser.fetchUserWithEmail(userEmail.text, block: { (user:EVUser!, error:NSError!) -> Void in
    if (error == nil) {
        self.errorLabel.hidden = false
        //print("The user " + user.username + " is logged in with valid access token.")
        self.errorLabel.textColor = UIColor.whiteColor()
        self.errorLabel.text = "please Check your email account for a reset Link"
        print("please Check your email account for a reset Link")
        //self.navigationController?.popToRootViewControllerAnimated(true)
    } else {
        // fail
        print("Fail")
        self.errorLabel.hidden = false
        self.errorLabel.textColor = UIColor.redColor()
        self.errorLabel.text = error.domain
         
    }
})
:

 

the error is always nil even if no email address is provided

 

also how do i trigger the reset email to be sent to the user

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 17 Mar 2016, 03:50 PM
Hi Diego,

The function EVUser.fetchUserWithEmail returns a nil EVUser if no user with the specified email is found as the method makes a GET request with a query "Email=....". Therefore you have to add additional check if the EVUser object is nil.

Still calling EVUser.fetchUserWithEmail will not be necessary to call reset password.

To send a password reset email you should send a POST request to the following endpoint:
https://api.everlive.com/v1/your-app-id/users/resetpassword

The request body can be either an Email or Username:
Email:
{"Email": "sample@sample.com"}
or Username:
{"Username": "sample"}

Here is a sample reset password request in Swift:
let appId = Everlive.sharedInstance().appId
let serverUrl = Everlive.sharedInstance().apiServerUrl
 
let email = "sample@sample.com"
let dic = ["Email": email]
 
do {
    let request = NSMutableURLRequest(URL: NSURL(string: "\(serverUrl)/\(appId)/users/resetpassword")!)
    request.HTTPMethod = "POST"
    request.addValue("application/json", forHTTPHeaderField: "Content-Type")
     
    let jsonData = try NSJSONSerialization.dataWithJSONObject(dic, options: NSJSONWritingOptions.PrettyPrinted)
    request.HTTPBody = jsonData
    let task = NSURLSession.sharedSession().dataTaskWithRequest(request) { data, response, error in
        guard error == nil && data != nil else {
            print("error=\(error)")
            return
        }
         
        let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
        print("responseString = \(responseString)")
    }
    task.resume()
     
} catch let error as NSError {
    print(error)
}

A request password reset method in the iOS SDK will be included in future releases.

Hope I was able to help.

Regards,
Martin
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
Apple iOS SDK
Asked by
Kevin
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or