db_manager = $db_manager; $this->users_repo = $users_repo; $this->a0_options = $a0_options; } /** * Add actions and filters for the profile page. * * @deprecated - 3.10.0, will move add_action calls out of this class in the next major. * * @codeCoverageIgnore - Deprecated. */ public function init() { add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); } /** * Enqueue styles and scripts for the user profile edit screen. * Hooked to: admin_enqueue_scripts * * @codeCoverageIgnore */ public function admin_enqueue_scripts() { global $pagenow; if ( ! in_array( $pagenow, array( 'profile.php', 'user-edit.php' ) ) ) { return; } wp_enqueue_script( 'wpa0_user_profile', WPA0_PLUGIN_JS_URL . 'edit-user-profile.js', array( 'jquery' ), WPA0_VERSION ); $profile = get_auth0userinfo( $GLOBALS['user_id'] ); $strategy = isset( $profile->sub ) ? WP_Auth0_Users::get_strategy( $profile->sub ) : ''; wp_localize_script( 'wpa0_user_profile', 'wpa0UserProfile', array( 'userId' => intval( $GLOBALS['user_id'] ), 'userStrategy' => sanitize_text_field( $strategy ), 'deleteIdNonce' => wp_create_nonce( 'delete_auth0_identity' ), 'deleteMfaNonce' => wp_create_nonce( 'delete_auth0_mfa' ), 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'i18n' => array( 'confirmDeleteId' => __( 'Are you sure you want to delete the Auth0 user data for this user?', 'wp-auth0' ), 'actionComplete' => __( 'Deleted', 'wp-auth0' ), 'actionFailed' => __( 'Action failed, please see the Auth0 error log for details.', 'wp-auth0' ), 'cannotChangeEmail' => __( 'Email cannot be changed for non-database connections.', 'wp-auth0' ), ), ) ); } /* * DEPRECATED * phpcs:disable */ /** * Process email changes and pass the update to Auth0 if it passes validation. * * @deprecated - 3.9.0, use WP_Auth0_Profile_Change_Email::update_email() instead. * * @codeCoverageIgnore - Deprecated */ public function override_email_update() { global $wpdb; global $errors; if ( ! is_object( $errors ) ) { $errors = new WP_Error(); } $current_user = wp_get_current_user(); $user_profile = get_currentauth0userinfo(); $app_token = $this->a0_options->get( 'auth0_app_token' ); if ( ! $app_token ) { return; } if ( $current_user->ID != $_POST['user_id'] ) { return false; } if ( empty( $user_profile ) ) { return; } if ( isset( $_POST['email'] ) && $current_user->user_email != $_POST['email'] ) { $connection = null; foreach ( $user_profile->identities as $identity ) { if ( $identity->provider === 'auth0' ) { $connection = $identity->connection; } } if ( $connection === null ) { $errors->add( 'user_email', __( "ERROR: You can't change your email if you are using a social connection.", 'wp-auth0' ), array( 'form-field' => 'email' ) ); return false; } if ( ! is_email( $_POST['email'] ) ) { $errors->add( 'user_email', __( 'ERROR: The email address is not correct.', 'wp-auth0' ), array( 'form-field' => 'email' ) ); return false; } if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) { $errors->add( 'user_email', __( 'ERROR: The email address is already used.', 'wp-auth0' ), array( 'form-field' => 'email' ) ); delete_option( $current_user->ID . '_new_email' ); return; } $user_email = esc_html( trim( $_POST['email'] ) ); $user_id = $user_profile->user_id; $client_id = $this->a0_options->get( 'client_id' ); $domain = $this->a0_options->get( 'domain' ); $requires_verified_email = $this->a0_options->get( 'requires_verified_email' ); $response = WP_Auth0_Api_Client::update_user( $domain, $app_token, $user_id, array( 'connection' => $connection, 'email' => $user_email, 'client_id' => $client_id, 'verify_email' => ( $requires_verified_email == 1 ), ) ); if ( $response !== false ) { if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) { $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $_POST['email'], $current_user->user_login ) ); } wp_update_user( array( 'ID' => $current_user->ID, 'user_email' => $user_email, ) ); if ( $requires_verified_email ) { wp_logout(); } } } } /** * Validate a new password. * * @deprecated - 3.8.0, use WP_Auth0_Profile_Change_Password::validate_new_password() instead. * * @param WP_Error $errors - Error instance to collect user profile errors. * @param boolean $update - Update or creation. * @param WP_User $user - User to validate. * * @codeCoverageIgnore - Deprecated */ public function validate_new_password( $errors, $update, $user ) { // phpcs:ignore @trigger_error( sprintf( __( 'Method %s is deprecated.', 'wp-auth0' ), __METHOD__ ), E_USER_DEPRECATED ); $auth0_password = isset( $_POST['auth0_password'] ) ? $_POST['auth0_password'] : null; $auth0_repeat_password = isset( $_POST['auth0_repeat_password'] ) ? $_POST['auth0_repeat_password'] : null; if ( $auth0_password != $auth0_repeat_password ) { $errors->add( 'auth0_password', __( 'ERROR: The password does not match', 'wp-auth0' ), array( 'form-field' => 'auth0_password' ) ); } } /** * Delete a user's password on Auth0. * * @deprecated - 3.8.0, use WP_Auth0_Profile_Change_Password::validate_new_password() instead. * * @codeCoverageIgnore - Deprecated */ public function update_change_password() { // phpcs:ignore @trigger_error( sprintf( __( 'Method %s is deprecated.', 'wp-auth0' ), __METHOD__ ), E_USER_DEPRECATED ); $current_user = get_currentauth0user(); $user_profile = $current_user->auth0_obj; if ( empty( $user_profile ) ) { return; } $auth0_password = isset( $_POST['auth0_password'] ) ? $_POST['auth0_password'] : null; $auth0_repeat_password = isset( $_POST['auth0_repeat_password'] ) ? $_POST['auth0_repeat_password'] : null; if ( ! empty( $auth0_password ) && $auth0_password == $auth0_repeat_password ) { $domain = $this->a0_options->get( 'domain' ); $client_id = $this->a0_options->get( 'client_id' ); $api_token = $this->a0_options->get( 'auth0_app_token' ); $connection = null; $email = null; foreach ( $user_profile->identities as $identity ) { if ( $identity->provider === 'auth0' ) { $connection = $identity->connection; if ( isset( $identity->email ) ) { $email = $identity->email; } else { $email = $user_profile->email; } } } if ( $api_token ) { WP_Auth0_Api_Client::update_user( $domain, $api_token, $user_profile->user_id, array( 'password' => $auth0_password, 'connection' => $connection, ) ); } else { WP_Auth0_Api_Client::change_password( $domain, array( 'client_id' => $client_id, 'email' => $user_profile->email, 'connection' => $connection, ) ); } } } /** * Delete a user's Auth0 data in WordPress. * * @deprecated - 3.8.0, use WP_Auth0_Profile_Delete_Data::delete_user_data() instead. * * @codeCoverageIgnore - Deprecated */ public function delete_user_data() { // phpcs:ignore @trigger_error( sprintf( __( 'Method %s is deprecated.', 'wp-auth0' ), __METHOD__ ), E_USER_DEPRECATED ); if ( ! is_admin() ) { return; } $user_id = $_POST['user_id']; $this->users_repo->delete_auth0_object( $user_id ); } /** * Delete a user's MFA provider. * * @deprecated - 3.8.0, use WP_Auth0_Profile_Delete_Mfa::delete_mfa() instead. * * @codeCoverageIgnore - Deprecated */ public function delete_mfa() { // phpcs:ignore @trigger_error( sprintf( __( 'Method %s is deprecated.', 'wp-auth0' ), __METHOD__ ), E_USER_DEPRECATED ); if ( ! is_admin() ) { return; } $user_id = $_POST['user_id']; $users = $this->db_manager->get_auth0_users( array( $user_id ) ); if ( empty( $users ) ) { return; } $user_id = $users[0]->auth0_id; $provider = 'google-authenticator'; $domain = $this->a0_options->get( 'domain' ); $app_token = $this->a0_options->get( 'auth0_app_token' ); WP_Auth0_Api_Client::delete_user_mfa( $domain, $app_token, $user_id, $provider ); } /** * Show controls to delete a user's Auth0 data. * * @deprecated - 3.8.0, use WP_Auth0_Profile_Delete_Data::show_delete_identity() instead. * * @codeCoverageIgnore - Deprecated */ public function show_delete_identity() { // phpcs:ignore @trigger_error( sprintf( __( 'Method %s is deprecated.', 'wp-auth0' ), __METHOD__ ), E_USER_DEPRECATED ); if ( ! is_admin() ) { return; } if ( ! get_auth0userinfo( $_GET['user_id'] ) ) { return; } ?>