| | |
| | | namespace JVBase\rest\routes; |
| | | |
| | | use JVBase\rest\RestRouteManager; |
| | | use JVBase\managers\MagicLinkManager; |
| | | use JVBase\managers\MagicLinks; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use WP_Error; |
| | |
| | | } |
| | | |
| | | /** |
| | | * @deprecated all bundled in with LoginRoutes.php |
| | | * Magic Link REST Routes |
| | | * |
| | | * Handles API endpoints for passwordless authentication |
| | |
| | | return $this->error('Security verification failed', 'turnstile_failed', 403); |
| | | } |
| | | $email = sanitize_email($request->get_param('email')??$request->get_param('user_email')??''); |
| | | $type = sanitize_text_field($request->get_param('type')) ?? MagicLinkManager::TYPE_LOGIN; |
| | | $type = sanitize_text_field($request->get_param('type')) ?? MagicLinks::TYPE_LOGIN; |
| | | $context = $request->get_param('context') ?? []; |
| | | |
| | | // Validate email |
| | |
| | | |
| | | // Check if email exists |
| | | $exists = email_exists($email); |
| | | if ($type === MagicLinkManager::TYPE_LOGIN && !$exists) { |
| | | if ($type === MagicLinks::TYPE_LOGIN && !$exists) { |
| | | return new WP_REST_Response([ |
| | | 'success' => true, |
| | | 'message' => 'Invalid email address' |
| | | ]); |
| | | } |
| | | |
| | | if ($type === MagicLinkManager::TYPE_SIGNUP && $exists) { |
| | | if ($type === MagicLinks::TYPE_SIGNUP && $exists) { |
| | | // Redirect to login instead |
| | | $type = MagicLinkManager::TYPE_LOGIN; |
| | | $type = MagicLinks::TYPE_LOGIN; |
| | | } |
| | | |
| | | // Send the magic link |
| | | $result = JVB()->magicLink()?->sendMagicLink($email, $type, $context); |
| | | $result = MagicLinks::getInstance()?->sendMagicLink($email, $type, $context); |
| | | |
| | | if (is_wp_error($result)) { |
| | | return new WP_REST_Response([ |
| | |
| | | $email = sanitize_email($request->get_param('email')); |
| | | |
| | | // This returns array|WP_Error - check for error first |
| | | $token_data = JVB()->magicLink()?->verifyToken($token, $email); |
| | | $token_data = MagicLinks::getInstance()?->verifyToken($token, $email); |
| | | |
| | | if (is_wp_error($token_data)) { |
| | | return new WP_REST_Response([ |