Fetch user with email always returning nil error

2 posts, 0 answers
  1. Kevin
    Kevin avatar
    16 posts
    Member since:
    Oct 2015

    Posted 16 Mar 2016 Link to this post

    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

  2. Martin
    Admin
    Martin avatar
    93 posts

    Posted 17 Mar 2016 Link to this post

    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.
     
Back to Top