Skip to content

Commit

Permalink
Fixed Admin migration step in Setup Wizard
Browse files Browse the repository at this point in the history
Added WP_Auth0_Api_Client::signup_user
  • Loading branch information
joshcanhelp authored and cocojoe committed Jan 8, 2018
1 parent 8806d07 commit c90bb28
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
31 changes: 29 additions & 2 deletions lib/WP_Auth0_Api_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ public static function create_user( $domain, $jwt, $data ) {
$headers = self::get_info_headers();

$headers['Authorization'] = "Bearer $jwt";
$headers['content-type'] = "application/json";
$headers['content-type'] = 'application/json';

$response = wp_remote_post( $endpoint , array(
'method' => 'POST',
'headers' => $headers,
'body' => json_encode( $data )
) );
Expand All @@ -191,6 +190,34 @@ public static function create_user( $domain, $jwt, $data ) {
return json_decode( $response['body'] );
}

public static function signup_user( $domain, $data ) {

$endpoint = "https://$domain/dbconnections/signup";

$headers = self::get_info_headers();

$headers['content-type'] = 'application/json';

$response = wp_remote_post( $endpoint , array(
'headers' => $headers,
'body' => json_encode( $data )
) );

if ( $response instanceof WP_Error ) {
WP_Auth0_ErrorManager::insert_auth0_error( 'WP_Auth0_Api_Client::signup_user', $response );
error_log( $response->get_error_message() );
return false;
}

if ( $response['response']['code'] !== 200 ) {
WP_Auth0_ErrorManager::insert_auth0_error( 'WP_Auth0_Api_Client::signup_user', $response['body'] );
error_log( $response['body'] );
return false;
}

return json_decode( $response['body'] );
}

public static function get_required_scopes() {
return array(
'update:clients',
Expand Down
13 changes: 4 additions & 9 deletions lib/initial-setup/WP_Auth0_InitialSetup_AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@ public function callback() {

$current_user = wp_get_current_user();

$db_connection_name = $this->a0_options->get( "db_connection_name" );
$domain = $this->a0_options->get( 'domain' );
$jwt = $this->a0_options->get( 'auth0_app_token' );

$data = array(
'client_id' => $this->a0_options->get( 'client_id' ),
'email' => $current_user->user_email,
'password' => $_POST['admin-password'],
'connection' => $db_connection_name,
'email_verified' => true
'connection' => $this->a0_options->get( "db_connection_name" )
);

$admin_user = WP_Auth0_Api_Client::create_user( $domain, $jwt, $data );
$admin_user = WP_Auth0_Api_Client::signup_user( $this->a0_options->get( 'domain' ), $data );

if ( $admin_user === false ) {
wp_redirect( admin_url( "admin.php?page=wpa0-setup&step=3&profile=social&result=error" ) );
}
else {
} else {
wp_redirect( admin_url( "admin.php?page=wpa0-setup&step=4&profile=social" ) );
}
exit;
Expand Down

0 comments on commit c90bb28

Please sign in to comment.