Trigger Password Reset by username

Discussion in 'Customization & add-ons' started by rweizenblut, Jun 4, 2013.

  1. rweizenblut

    rweizenblut New Member

    Joined:
    Apr 5, 2013
    Messages:
    3
    I am building an App that connects to the aMember database on my server for validation of the users. I have been successful is getting it to create an account in the aMember database. I can also validate the username / password entered in the app against the one from aMember. Lastly, once user is logged in, I am able to change the password by having them enter their current password, validate it and change it to a new one. The one piece I am missing is a forgot password. On the login of my app, if the user enters the password and it is wrong, I want to offer them an option to enter a username or email and the app will send that info to a page on my server. On that page, I need to somehow trigger the forgot password functionality for aMember that will send them an email with the password reset link. This, I have no clue how to do and is the last piece of the puzzle.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Send a post request to your /amember/sendpass with one parameter:
    login=USERLOGIN
    You will receive jSON in response, then parse it in your script.
  3. bmedwards

    bmedwards New Member

    Joined:
    Jun 27, 2014
    Messages:
    16
    Hi Alex,

    Sorry to dig up an old thread, but I am trying to do exactly this, and am not getting a response back in JSON format -- instead I am getting the response back as an entire webpage. Below is the code I am using to make the request -- is there a certain header I need to send to get JSON format?

    $foo = "http://my.server.com/signup/sendpass";
    $request = new HTTP_Request2($foo);
    $request->setHeader('Content-type: application/json');
    $request->setMethod(HTTP_Request2::METHOD_POST)
    ->addPostParameter('login',"testusername");
    try {
    $response = $request->send();
    if (200 == $response->getStatus()) {
    //echo $response->getBody();
    $debuglog->LogInfo("SUCCESS: POST TO SENDPASS");
    $debuglog->LogInfo("SUCCESS: RESPONSE ". $response->getStatus() . " " . $response->getBody());
    } else {
    //echo 'ERROR: Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
    $errorlog->LogError("ERROR: Unexpected HTTP status POST VIA HTTP_Request2(" .$foo." ): ". $response->getReasonPhrase() . "**");
    $errorlog->LogError("ERROR: POST RESPONSE: ". $response->getReasonPhrase());
    //Am_Di::getInstance()->errorLogTable->logException($response->getReasonPhrase());
    }
    } catch (HTTP_Request2_Exception $e) {
    //Am_Di::getInstance()->errorLogTable->logException($e);
    $errorlog->LogError("ERROR: An exception was thrown in HTTP_Request2( ".$foo." ) ". $e->getMessage() . "**");
    $errorlog->LogError("ERROR: FULL TRACE: ( ".$foo." ) ". $e->getTraceAsString() . "");
    //echo 'Error: ' . $e->getMessage();
    $response = "ERROR: " . $response->getReasonPhrase;
    return $response;
    }

    Thanks,
    Brian
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello Brian,

    Please set X-Requested-With header to XMLHttpRequest for your HTTP request.

Share This Page