PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / DonationForms / Routes / AuthenticationRoute.php

AuthenticationRoute.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/DonationForms/Routes/AuthenticationRoute.php

57 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonationForms\Routes;
4
5 use Give\DonationForms\DataTransferObjects\AuthenticationData;
6 use Give\DonationForms\DataTransferObjects\DonateRouteData;
7 use Give\DonationForms\DataTransferObjects\UserData;
8 use Give\Framework\PaymentGateways\Traits\HandleHttpResponses;
9 use WP_User;
10
11 /**
12 * @since 3.0.0
13 */
14 class AuthenticationRoute
15 {
16 use HandleHttpResponses;
17
18 /**
19 * @since 3.0.0
20 *
21 * @return void
22 */
23 public function __invoke(array $request)
24 {
25 $routeData = DonateRouteData::fromRequest(give_clean($_GET));
26
27 $routeData->validateSignature();
28
29 $user = $this->authenticate(AuthenticationData::fromRequest($request));
30
31 wp_send_json_success(UserData::fromUser($user));
32
33 exit;
34 }
35
36 /**
37 * @since 3.0.0
38 */
39 protected function authenticate(AuthenticationData $auth): WP_User
40 {
41 $userOrError = wp_signon([
42 'user_login' => $auth->login,
43 'user_password' => $auth->password,
44 ]);
45
46 if (is_wp_error($userOrError)) {
47 wp_send_json_error([
48 'type' => 'authentication_error',
49 'message' => __('The login/password does not match or is incorrect.', 'give'),
50 ], 401);
51 exit;
52 }
53
54 return $userOrError;
55 }
56 }
57