AbandonedCheckoutProtocolRestServiceProvider.php
3 years ago
AbandonedCheckoutRestServiceProvider.php
2 years ago
AccountRestServiceProvider.php
3 years ago
ActivationRestServiceProvider.php
1 year ago
AffiliationProductsRestServiceProvider.php
2 years ago
AffiliationProtocolRestServiceProvider.php
2 years ago
AffiliationRequestsRestServiceProvider.php
2 years ago
AffiliationsRestServiceProvider.php
11 months ago
AutoFeeProtocolRestServiceProvider.php
5 months ago
AutoFeeRestServiceProvider.php
5 months ago
BalanceTransactionRestServiceProvider.php
3 years ago
BatchesRestServiceProvider.php
4 days ago
BlockPatternsRestServiceProvider.php
3 years ago
BrandRestServiceProvider.php
4 months ago
BumpRestServiceProvider.php
1 year ago
CancellationActRestServiceProvider.php
1 year ago
CancellationReasonRestServiceProvider.php
1 year ago
ChargesRestServiceProvider.php
3 years ago
CheckEmailRestServiceProvider.php
3 years ago
CheckoutRestServiceProvider.php
1 year ago
ClicksRestServiceProvider.php
2 years ago
CouponRestServiceProvider.php
3 years ago
CustomerNotificationProtocolRestServiceProvider.php
3 years ago
CustomerPortalProtocolRestServiceProvider.php
1 year ago
CustomerRestServiceProvider.php
1 month ago
DisplayCurrencyRestServiceProvider.php
1 year ago
DisputesRestServiceProvider.php
9 months ago
DownloadRestServiceProvider.php
2 months ago
DraftCheckoutRestServiceProvider.php
1 year ago
ExportsRestServiceProvider.php
2 years ago
FulfillmentRestServiceProvider.php
3 years ago
ImportRowsRestServiceProvider.php
2 months ago
IncomingWebhooksRestServiceProvider.php
2 years ago
IntegrationProvidersRestServiceProvider.php
3 years ago
IntegrationsCatalogRestServiceProvider.php
1 year ago
IntegrationsRestServiceProvider.php
3 years ago
InvoicesRestServiceProvider.php
1 year ago
LicenseRestServiceProvider.php
1 year ago
LineItemsRestServiceProvider.php
1 year ago
LoginRestServiceProvider.php
1 month ago
ManualPaymentMethodsRestServiceProvider.php
3 years ago
MediaRestServiceProvider.php
1 year ago
OrderProtocolRestServiceProvider.php
1 year ago
OrderRestServiceProvider.php
1 year ago
ParcelTemplateRestServiceProvider.php
3 months ago
PaymentIntentsRestServiceProvider.php
3 years ago
PaymentMethodsRestServiceProvider.php
2 years ago
PayoutGroupsRestServiceProvider.php
2 years ago
PayoutsRestServiceProvider.php
4 months ago
PeriodRestServiceProvider.php
3 years ago
PluginInstallerRestServiceProvider.php
4 days ago
PriceRestServiceProvider.php
1 year ago
ProcessorRestServiceProvider.php
3 years ago
ProductCollectionsRestServiceProvider.php
4 days ago
ProductGroupsRestServiceProvider.php
3 years ago
ProductMediaRestServiceProvider.php
1 year ago
ProductsRestServiceProvider.php
4 days ago
PromotionRestServiceProvider.php
3 years ago
ProvisionalAccountRestServiceProvider.php
3 years ago
PurchasesRestServiceProvider.php
3 years ago
ReferralItemsRestServiceProvider.php
2 years ago
ReferralsRestServiceProvider.php
2 years ago
RefundsRestServiceProvider.php
3 years ago
RegisteredWebhookRestServiceProvider.php
2 years ago
RestServiceInterface.php
3 years ago
RestServiceProvider.php
1 year ago
ReturnItemsRestServiceProvider.php
2 years ago
ReturnReasonsRestServiceProvider.php
2 years ago
ReturnRequestsRestServiceProvider.php
2 years ago
ReviewProtocolRestServiceProvider.php
4 months ago
ReviewsRestServiceProvider.php
4 days ago
RuleSchemaRestServiceProvider.php
5 months ago
SettingsRestServiceProvider.php
1 year ago
ShippingMethodRestServiceProvider.php
3 years ago
ShippingProfileRestServiceProvider.php
3 years ago
ShippingProtocolRestServiceProvider.php
1 year ago
ShippingRateRestServiceProvider.php
3 years ago
ShippingZoneRestServiceProvider.php
3 years ago
SiteHealthRestServiceProvider.php
2 years ago
StatisticRestServiceProvider.php
3 years ago
SubscriptionProtocolRestServiceProvider.php
5 months ago
SubscriptionRestServiceProvider.php
2 years ago
SwapRestServiceProvider.php
1 year ago
TaxOverrideRestServiceProvider.php
1 year ago
TaxProtocolRestServiceProvider.php
1 year ago
TaxRegistrationRestServiceProvider.php
1 year ago
TaxZoneRestServiceProvider.php
1 year ago
UploadsRestServiceProvider.php
3 years ago
UpsellFunnelRestServiceProvider.php
1 year ago
UpsellRestServiceProvider.php
1 year ago
VariantOptionsRestServiceProvider.php
2 years ago
VariantValuesRestServiceProvider.php
2 years ago
VariantsRestServiceProvider.php
2 years ago
VerificationCodeRestServiceProvider.php
3 years ago
WebhooksRestServiceProvider.php
3 years ago
LoginRestServiceProvider.php
121 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Rest; |
| 4 | |
| 5 | use SureCart\Rest\RestServiceInterface; |
| 6 | use SureCart\Controllers\Rest\LoginController; |
| 7 | |
| 8 | /** |
| 9 | * Service provider for Price Rest Requests |
| 10 | */ |
| 11 | class LoginRestServiceProvider extends RestServiceProvider implements RestServiceInterface { |
| 12 | /** |
| 13 | * Endpoint. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $endpoint = 'login'; |
| 18 | |
| 19 | /** |
| 20 | * Methods allowed for the model. |
| 21 | * |
| 22 | * @var array |
| 23 | */ |
| 24 | protected $methods = []; |
| 25 | |
| 26 | /** |
| 27 | * Register REST Routes |
| 28 | * |
| 29 | * @return void |
| 30 | */ |
| 31 | public function registerRoutes() { |
| 32 | register_rest_route( |
| 33 | "$this->name/v$this->version", |
| 34 | "$this->endpoint", |
| 35 | [ |
| 36 | [ |
| 37 | 'methods' => \WP_REST_Server::EDITABLE, |
| 38 | 'callback' => $this->callback( LoginController::class, 'authenticate' ), |
| 39 | 'permission_callback' => [ $this, 'authenticate_permissions_check' ], |
| 40 | ], |
| 41 | 'schema' => [ $this, 'get_item_schema' ], |
| 42 | ] |
| 43 | ); |
| 44 | |
| 45 | register_rest_route( |
| 46 | "$this->name/v$this->version", |
| 47 | 'logout', |
| 48 | [ |
| 49 | [ |
| 50 | 'methods' => \WP_REST_Server::CREATABLE, |
| 51 | 'callback' => $this->callback( LoginController::class, 'logout' ), |
| 52 | 'permission_callback' => [ $this, 'logout_permissions_check' ], |
| 53 | ], |
| 54 | 'schema' => [ $this, 'get_item_schema' ], |
| 55 | ] |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Get our sample schema for a post. |
| 61 | * |
| 62 | * @return array The sample schema for a post |
| 63 | */ |
| 64 | public function get_item_schema() { |
| 65 | if ( $this->schema ) { |
| 66 | // Since WordPress 5.3, the schema can be cached in the $schema property. |
| 67 | return $this->schema; |
| 68 | } |
| 69 | |
| 70 | $this->schema = [ |
| 71 | // This tells the spec of JSON Schema we are using which is draft 4. |
| 72 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 73 | // The title property marks the identity of the resource. |
| 74 | 'title' => $this->endpoint, |
| 75 | 'type' => 'object', |
| 76 | // In JSON Schema you can specify object properties in the properties attribute. |
| 77 | 'properties' => [ |
| 78 | 'login' => [ |
| 79 | 'description' => esc_html__( 'Login', 'surecart' ), |
| 80 | 'type' => 'string', |
| 81 | ], |
| 82 | 'password' => [ |
| 83 | 'description' => esc_html__( 'Password', 'surecart' ), |
| 84 | 'type' => 'integer', |
| 85 | ], |
| 86 | ], |
| 87 | ]; |
| 88 | |
| 89 | return $this->schema; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Anyone can login. |
| 94 | * |
| 95 | * @param \WP_REST_Request $request Full details about the request. |
| 96 | * |
| 97 | * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. |
| 98 | */ |
| 99 | public function authenticate_permissions_check( $request ) { |
| 100 | return true; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Only logged in users can logout. |
| 105 | * |
| 106 | * @param \WP_REST_Request $request Full details about the request. |
| 107 | * |
| 108 | * @return true|\WP_Error |
| 109 | */ |
| 110 | public function logout_permissions_check( $request ) { |
| 111 | if ( ! is_user_logged_in() ) { |
| 112 | return new \WP_Error( |
| 113 | 'rest_not_logged_in', |
| 114 | __( 'You must be logged in to perform this action.', 'surecart' ), |
| 115 | [ 'status' => 401 ] |
| 116 | ); |
| 117 | } |
| 118 | return true; |
| 119 | } |
| 120 | } |
| 121 |