• Resolved theblindhawk

    (@theblindhawk)


    hello,
    I am trying to register a user from a login page located in a different site.
    I have activated the plugin, added a decryption key, allowed register and added an auth code.
    this is the code I am trying to run in order to register the user:

    $data=array(
            'email' => '[email protected]',
            'password' => 'somethin',
            'AUTH_KEY' => 'the-key',
    	);
    	$url = "https://my=site/?rest_route=/simple-jwt-login/v1/users";
        $context = array(
            'http' => array(
                'method'  => 'POST',
                'header'  => implode("\r\n", array('Content-Type: application/x-www-form-urlencoded',)),
                'content' => http_build_query($data)
            )
        );
    	
        //$html = file_get_contents($url, false, stream_context_create($context));
        $html = file_get_contents($url);
    	echo $html;

    I have tried to change the code in multiple ways, but it’s not working, and I feel like I am missing something.
    I have never used REST APIs before, so I might be missing something very basic.

    • This topic was modified 4 years, 11 months ago by theblindhawk.
    • This topic was modified 4 years, 11 months ago by theblindhawk.
    • This topic was modified 4 years, 11 months ago by theblindhawk.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Nicu Micle

    (@nicu_m)

    Hello @theblindhawk,

    I’ve prepared a simple example for you:

    
    //Data you want to be sent
    $data=array(
        "username"=> "username-tests",
        "email"=> "[email protected]",
        "password"=> '000000'
        'AUTH_CODE' => 'Your AUTH CODE here',
    );
    
    $url = 'https://your-domain.com/?rest_route=/simple-jwt-login/v1/users';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($cf, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $response = curl_exec($ch);
    curl_close ($ch);
    
    echo $response;
    
    

    Just replace the variables and the domain from the $url variable and you should be able to get the response.

    Let me know if this was helpful and please don’t forget to rate this plugin.

    Best regards,
    Nicu.

    Thread Starter theblindhawk

    (@theblindhawk)

    Thank you so much for the reply!

    I tried out the code you sent me, but it is returning me “401 unauthorized”.
    I tried deleting cookies and cache, and checked the plugin settings, but they all seem fine. Could it be a problem with some other wordpress settings?
    Or could I have i misconfigured the plugin?

    The site I am working on is still not open to the public and cannot be accessed without some credentials. could that be the problem?

    Thanks again for the sample code!

    Thread Starter theblindhawk

    (@theblindhawk)

    It seems the problem was the basic authentication on the site.
    The code is now running, thanks for the sample 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘having problems registering a user’ is closed to new replies.