Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching wizard admin user creation to use /dbconnections/signup #356

Merged
merged 3 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/WP_Auth0_Api_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it seems there is a change in behaviour here as the user will need to manually verify their email. I am okay with this.

'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