AbandonedCheckoutProtocolController.php
2 years ago
AbandonedCheckoutsController.php
3 years ago
AccountController.php
2 years ago
ActivationsController.php
3 years ago
AffiliationProductsController.php
2 years ago
AffiliationProtocolController.php
2 years ago
AffiliationRequestsController.php
2 years ago
AffiliationsController.php
2 years ago
AutoFeeProtocolController.php
5 months ago
AutoFeesController.php
5 months ago
BalanceTransactionsController.php
3 years ago
BatchesController.php
6 days ago
BrandController.php
4 months ago
BumpsController.php
3 years ago
CancellationActsController.php
3 years ago
CancellationReasonsController.php
3 years ago
ChargesController.php
2 years ago
CheckEmailController.php
11 months ago
CheckoutsController.php
5 months ago
ClicksController.php
2 years ago
CouponsController.php
3 years ago
CustomerController.php
1 month ago
CustomerNotificationProtocolController.php
2 years ago
CustomerPortalProtocolController.php
1 year ago
DisplayCurrencyController.php
1 year ago
DisputesController.php
9 months ago
DownloadsController.php
3 years ago
DraftCheckoutsController.php
2 years ago
ExportsController.php
2 years ago
FulfillmentsController.php
3 years ago
ImportRowsController.php
2 months ago
IncomingWebhooksController.php
2 months ago
IntegrationCatalogController.php
1 year ago
IntegrationProvidersController.php
3 years ago
IntegrationsController.php
2 months ago
InvoicesController.php
1 year ago
LicensesController.php
3 years ago
LineItemsController.php
1 year ago
LoginController.php
1 month ago
ManualPaymentMethodsController.php
3 years ago
MediasController.php
3 years ago
OrderController.php
1 year ago
OrderProtocolController.php
2 years ago
ParcelTemplateController.php
3 months ago
PaymentIntentsController.php
2 years ago
PaymentMethodsController.php
2 years ago
PayoutGroupsController.php
2 years ago
PayoutsController.php
2 years ago
PeriodsController.php
3 years ago
PluginInstallerController.php
6 days ago
PricesController.php
1 year ago
ProcessorController.php
3 years ago
ProductCollectionsController.php
6 days ago
ProductGroupsController.php
3 years ago
ProductMediaController.php
1 year ago
ProductsController.php
6 days ago
PromotionsController.php
3 years ago
ProvisionalAccountController.php
3 years ago
PurchasesController.php
3 years ago
ReferralItemsController.php
2 years ago
ReferralsController.php
2 years ago
RefundsController.php
3 years ago
RegisteredWebhookController.php
2 years ago
RestController.php
6 days ago
ReturnItemsController.php
2 years ago
ReturnReasonsController.php
2 years ago
ReturnRequestsController.php
2 years ago
ReviewProtocolController.php
4 months ago
ReviewsController.php
6 days ago
RuleSchemaController.php
5 months ago
SettingsController.php
1 month ago
ShippingMethodController.php
3 years ago
ShippingProfileController.php
3 years ago
ShippingProtocolController.php
3 years ago
ShippingRateController.php
3 years ago
ShippingZoneController.php
3 years ago
StatisticsController.php
2 years ago
SubscriptionProtocolController.php
2 years ago
SubscriptionsController.php
2 years ago
SwapsController.php
1 year ago
TaxOverrideController.php
2 years ago
TaxProtocolController.php
2 years ago
TaxRegistrationController.php
3 years ago
TaxZoneController.php
3 years ago
UploadsController.php
3 years ago
UpsellFunnelsController.php
2 years ago
UpsellsController.php
2 years ago
VariantOptionsController.php
2 years ago
VariantValuesController.php
2 years ago
VariantsController.php
2 years ago
VerificationCodeController.php
1 month ago
WebhookController.php
3 years ago
LoginController.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Rest; |
| 4 | |
| 5 | use SureCart\Models\User; |
| 6 | |
| 7 | /** |
| 8 | * Handle coupon requests through the REST API |
| 9 | */ |
| 10 | class LoginController extends RestController { |
| 11 | /** |
| 12 | * Login user. |
| 13 | * |
| 14 | * @param \WP_REST_Request $request The REST request object. |
| 15 | * |
| 16 | * @return array|\WP_Error Returns an array with user details on success, or WP_Error on failure. |
| 17 | */ |
| 18 | public function authenticate( \WP_REST_Request $request ) { |
| 19 | // Authenticate the user. |
| 20 | $user = wp_authenticate( $request->get_param( 'login' ), $request->get_param( 'password' ) ); |
| 21 | |
| 22 | if ( is_wp_error( $user ) ) { |
| 23 | return $user; |
| 24 | } |
| 25 | |
| 26 | User::find( $user->ID )->login(); |
| 27 | |
| 28 | $redirect_to = $request->get_param( 'redirect_to' ); |
| 29 | $redirect_url = ! empty( $redirect_to ) ? wp_validate_redirect( $redirect_to, false ) : null; |
| 30 | |
| 31 | return [ |
| 32 | 'name' => $user->display_name, |
| 33 | 'email' => $user->user_email, |
| 34 | 'avatar_url' => get_avatar_url( $user->user_email, [ 'size' => 48 ] ), |
| 35 | 'redirect_url' => apply_filters( 'sc_login_redirect_url', $redirect_url ), |
| 36 | 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), |
| 37 | ]; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Logout user |
| 42 | * |
| 43 | * @param \WP_REST_Request $request Request object. |
| 44 | * |
| 45 | * @return array Returns an array with a new nonce for future requests. |
| 46 | */ |
| 47 | public function logout( \WP_REST_Request $request ) { |
| 48 | wp_logout(); |
| 49 | |
| 50 | return [ |
| 51 | 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), |
| 52 | ]; |
| 53 | } |
| 54 | } |
| 55 |