| @@ -33,9 +33,9 @@ | ||
| 33 | 33 | |
| 34 | 34 | // Security: Check if user is already logged in and redirect securely |
| 35 | 35 | if (is_user_logged_in()) { |
| 36 | 36 | $current_user = wp_get_current_user(); |
| 37 | - $redirect_url = apply_filters('yatra_login_redirect_url', home_url('/my-account'), $current_user); | |
| 37 | + $redirect_url = apply_filters('yatra_login_redirect_url', home_url('/' . \Yatra\Services\SettingsService::getAccountBase()), $current_user); | |
| 38 | 38 | |
| 39 | 39 | // Use safe redirect to prevent open redirects |
| 40 | 40 | wp_safe_redirect($redirect_url, 302); |
| 41 | 41 | exit; |
| @@ -46,40 +46,24 @@ | ||
| 46 | 46 | $this->sendErrorResponse(403, __('Security check failed', 'yatra')); |
| 47 | 47 | return false; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - // Load the login page template with error handling | |
| 51 | - $template_path = YATRA_PLUGIN_PATH . 'templates/login-page.php'; | |
| 52 | - | |
| 53 | - if (!file_exists($template_path)) { | |
| 54 | - // Log error for debugging | |
| 55 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 56 | - error_log('Yatra Login Page Handler: Template not found at ' . $template_path); | |
| 57 | - } | |
| 58 | - | |
| 50 | + // Configure $wp_query + virtual WP_Post (covers FSE block-theme rendering). | |
| 51 | + $this->setupPageEnvironment('singular', [ | |
| 52 | + 'title' => __('Login', 'yatra'), | |
| 53 | + 'post_type' => 'page', | |
| 54 | + 'post_name' => 'login', | |
| 55 | + ]); | |
| 56 | + | |
| 57 | + // Security headers | |
| 58 | + $this->setSecurityHeaders(); | |
| 59 | + | |
| 60 | + if (!$this->selectTemplate('login-page', null, 'login')) { | |
| 59 | 61 | // Fallback to shortcode if template is missing |
| 60 | 62 | return $this->handleFallback(); |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | - try { | |
| 64 | - // Set up WordPress environment | |
| 65 | - $this->setupWordPressEnvironment(); | |
| 66 | - | |
| 67 | - // Security headers | |
| 68 | - $this->setSecurityHeaders(); | |
| 69 | - | |
| 70 | - // Include the template | |
| 71 | - include $template_path; | |
| 72 | - exit; | |
| 73 | - | |
| 74 | - } catch (Exception $e) { | |
| 75 | - // Log error for debugging | |
| 76 | - if (defined('WP_DEBUG') && WP_DEBUG) { | |
| 77 | - error_log('Yatra Login Page Handler Error: ' . $e->getMessage()); | |
| 78 | - } | |
| 79 | - | |
| 80 | - return $this->handleFallback(); | |
| 81 | - } | |
| 65 | + return true; | |
| 82 | 66 | } |
| 83 | 67 | |
| 84 | 68 | /** |
| 85 | 69 | * Get the route pattern for this handler |
| @@ -112,37 +96,8 @@ | ||
| 112 | 96 | } |
| 113 | 97 | |
| 114 | 98 | set_transient($transient_key, $attempts + 1, 5 * MINUTE_IN_SECONDS); |
| 115 | 99 | return true; |
| 116 | - } | |
| 117 | - | |
| 118 | - /** | |
| 119 | - * Setup WordPress environment for the login page | |
| 120 | - */ | |
| 121 | - private function setupWordPressEnvironment(): void | |
| 122 | - { | |
| 123 | - global $wp_query; | |
| 124 | - | |
| 125 | - // Prevent 404 | |
| 126 | - $wp_query->is_404 = false; | |
| 127 | - $wp_query->is_page = true; | |
| 128 | - $wp_query->is_singular = true; | |
| 129 | - | |
| 130 | - // Set proper headers | |
| 131 | - status_header(200); | |
| 132 | - | |
| 133 | - // Set page title and metadata | |
| 134 | - $wp_query->set('page_title', __('Login', 'yatra')); | |
| 135 | - $wp_query->set('meta_description', __('Login to your Yatra account', 'yatra')); | |
| 136 | - | |
| 137 | - // Set up post data for compatibility | |
| 138 | - $wp_query->set('post', (object) [ | |
| 139 | - 'ID' => 0, | |
| 140 | - 'post_title' => __('Login', 'yatra'), | |
| 141 | - 'post_content' => '', | |
| 142 | - 'post_type' => 'page', | |
| 143 | - 'post_status' => 'publish' | |
| 144 | - ]); | |
| 145 | 100 | } |
| 146 | 101 | |
| 147 | 102 | /** |
| 148 | 103 | * Set security headers |