-
Notifications
You must be signed in to change notification settings - Fork 69
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
Bring back the rest-user-exists-controller file #6303
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0c34b6e
Bring back the rest-user-exists-controller
malithsen c0d5e69
Add changelog entry
malithsen 82d4e78
Merge branch 'develop' into fix/plugin-upgrade
shendy-a8c 1dd9f40
Remove changelog
malithsen 690e421
Merge branch 'develop' into fix/plugin-upgrade
shendy-a8c e039b80
Add back changelog
malithsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fix | ||
|
||
Missing file during plugin upgrade | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Class WC_REST_User_Exists_Controller | ||
* | ||
* @package WooCommerce\Payments\Admin | ||
*/ | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* REST controller to check if a user exists. | ||
*/ | ||
class WC_REST_User_Exists_Controller extends WP_REST_Controller { | ||
|
||
/** | ||
* Endpoint namespace. | ||
* | ||
* @var string | ||
*/ | ||
protected $namespace = 'wc/v3'; | ||
|
||
/** | ||
* Endpoint path. | ||
* | ||
* @var string | ||
*/ | ||
protected $rest_base = 'users/exists'; | ||
|
||
/** | ||
* Configure REST API routes. | ||
*/ | ||
public function register_routes() { | ||
register_rest_route( | ||
$this->namespace, | ||
'/' . $this->rest_base, | ||
[ | ||
'methods' => WP_REST_Server::CREATABLE, | ||
'callback' => [ $this, 'user_exists' ], | ||
'permission_callback' => '__return_true', | ||
'args' => [ | ||
'email' => [ | ||
'required' => true, | ||
'description' => __( 'Email address.', 'woocommerce-payments' ), | ||
'type' => 'string', | ||
'format' => 'email', | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Retrieve if a user exists by email address. | ||
* | ||
* @param WP_REST_Request $request Full details about the request. | ||
* | ||
* @return WP_REST_Response | ||
*/ | ||
public function user_exists( WP_REST_Request $request ): WP_REST_Response { | ||
$email = $request->get_param( 'email' ); | ||
$email_exists = ! empty( email_exists( $email ) ); | ||
$message = null; | ||
|
||
if ( $email_exists ) { | ||
// Use this function to show the core error message. | ||
$error = wc_create_new_customer( $email ); | ||
$message = $error->get_error_message(); | ||
} | ||
|
||
return new WP_REST_Response( | ||
[ | ||
'user-exists' => $email_exists, | ||
'message' => $message, | ||
] | ||
); | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to not add any changelog for this PR as the problem this PR is trying to fix did not exist in previous version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in 1dd9f40
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant not to remove the whole changelog file because then GH check for changelog will fail.
You can:
npm run changelog
.patch
.I know that
npm run changelog
isn't too clear.I talked about it several times, eg p1683308423223529/1683298938.613009-slack-CGGCLBN58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I misunderstood. Added an empty changelog with a comment