| @@ -20,24 +20,51 @@ | ||
| 20 | 20 | $form_id = 'yatra-login-form-' . uniqid(); |
| 21 | 21 | |
| 22 | 22 | // Security nonce |
| 23 | 23 | $login_nonce = wp_create_nonce('yatra_login_nonce'); |
| 24 | + | |
| 25 | +// Account CREATION is gated by Yatra's own setting — the same one the backend | |
| 26 | +// enforces (AuthController::register rejects registration when it is off). This | |
| 27 | +// deliberately does NOT use WordPress core's get_option('users_can_register'): | |
| 28 | +// Yatra registers customers via wp_create_user() directly, so the core toggle | |
| 29 | +// (off by default) is irrelevant and was previously hiding the register option | |
| 30 | +// entirely. | |
| 31 | +$registration_enabled = \Yatra\Services\SettingsService::isEnabled('customer_registration'); | |
| 32 | + | |
| 33 | +// Nonce reused by the inline register (REST) and forgot-password (AJAX) forms. | |
| 34 | +$auth_action_nonce = wp_create_nonce('yatra_login_action'); | |
| 24 | 35 | ?> |
| 25 | 36 | |
| 26 | 37 | <div class="yatra-login-shortcode" data-form-id="<?php echo esc_attr($form_id); ?>"> |
| 27 | 38 | <div class="yatra-login-container"> |
| 28 | 39 | <div class="yatra-login-header"> |
| 40 | + <?php // Title + subtitle are kept in sync with the active panel by JS | |
| 41 | + // (each .yatra-auth-panel carries data-header-* copy). Rendered | |
| 42 | + // here with the login-state copy so there is no flash on load. ?> | |
| 29 | 43 | <h2 class="yatra-login-title"><?php echo esc_html($atts['title']); ?></h2> |
| 30 | - <?php if (!empty($atts['subtitle'])): ?> | |
| 31 | - <p class="yatra-login-subtitle"><?php echo esc_html($atts['subtitle']); ?></p> | |
| 32 | - <?php endif; ?> | |
| 44 | + <p class="yatra-login-subtitle"<?php echo empty($atts['subtitle']) ? ' style="display:none;"' : ''; ?>><?php echo esc_html($atts['subtitle'] ?? ''); ?></p> | |
| 33 | 45 | </div> |
| 34 | 46 | |
| 35 | 47 | <div class="yatra-login-form-container"> |
| 48 | + <?php if ($atts['show_register'] === 'yes' && $registration_enabled): ?> | |
| 49 | + <div class="yatra-login-tabs" role="tablist" aria-label="<?php esc_attr_e('Login or create an account', 'yatra'); ?>"> | |
| 50 | + <button type="button" class="yatra-login-tab is-active" data-target="login" id="<?php echo esc_attr($form_id); ?>-tab-login" role="tab" aria-selected="true" aria-controls="<?php echo esc_attr($form_id); ?>-panel-login" tabindex="0"> | |
| 51 | + <?php esc_html_e('Login', 'yatra'); ?> | |
| 52 | + </button> | |
| 53 | + <button type="button" class="yatra-login-tab" data-target="register" id="<?php echo esc_attr($form_id); ?>-tab-register" role="tab" aria-selected="false" aria-controls="<?php echo esc_attr($form_id); ?>-panel-register" tabindex="-1"> | |
| 54 | + <?php esc_html_e('Sign Up', 'yatra'); ?> | |
| 55 | + </button> | |
| 56 | + </div> | |
| 57 | + <?php endif; ?> | |
| 58 | + | |
| 59 | + <div class="yatra-auth-panel yatra-auth-panel-login" data-panel="login" | |
| 60 | + data-header-title="<?php echo esc_attr($atts['title']); ?>" | |
| 61 | + data-header-subtitle="<?php echo esc_attr($atts['subtitle'] ?? ''); ?>" | |
| 62 | + data-footer-text="<?php echo esc_attr__('Your login information is secure and encrypted.', 'yatra'); ?>"<?php if ($atts['show_register'] === 'yes' && $registration_enabled): ?> id="<?php echo esc_attr($form_id); ?>-panel-login" role="tabpanel" aria-labelledby="<?php echo esc_attr($form_id); ?>-tab-login" tabindex="0"<?php endif; ?>> | |
| 36 | 63 | <form class="yatra-login-form" id="<?php echo esc_attr($form_id); ?>" method="post" action="" data-ajax="true"> |
| 37 | 64 | <?php wp_nonce_field('yatra_login_action', 'yatra_login_nonce', true, true); ?> |
| 38 | 65 | <div class="yatra-form-group"> |
| 39 | - <label for="yatra-login-username" class="yatra-form-label"> | |
| 66 | + <label for="<?php echo esc_attr($form_id); ?>-username" class="yatra-form-label"> | |
| 40 | 67 | <?php esc_html_e('Email or Username', 'yatra'); ?> |
| 41 | 68 | </label> |
| 42 | 69 | <input |
| 43 | 70 | type="text" |
| @@ -106,23 +133,134 @@ | ||
| 106 | 133 | </form> |
| 107 | 134 | |
| 108 | 135 | <?php if ($atts['show_forgot_password'] === 'yes'): ?> |
| 109 | 136 | <div class="yatra-forgot-password"> |
| 110 | - <a href="<?php echo esc_url(wp_lostpassword_url()); ?>" class="yatra-link"> | |
| 137 | + <?php // href kept as a no-JS fallback; JS intercepts to open the inline reset panel. ?> | |
| 138 | + <a href="<?php echo esc_url(wp_lostpassword_url()); ?>" class="yatra-link yatra-auth-switch" data-target="forgot"> | |
| 111 | 139 | <?php esc_html_e('Forgot your password?', 'yatra'); ?> |
| 112 | 140 | </a> |
| 113 | 141 | </div> |
| 114 | 142 | <?php endif; ?> |
| 115 | 143 | |
| 116 | - <?php if ($atts['show_register'] === 'yes' && get_option('users_can_register')): ?> | |
| 144 | + <?php if ($atts['show_register'] === 'yes' && $registration_enabled): ?> | |
| 117 | 145 | <div class="yatra-register-prompt"> |
| 118 | 146 | <p> |
| 119 | 147 | <?php esc_html_e("Don't have an account?", 'yatra'); ?> |
| 120 | - <a href="<?php echo esc_url(wp_registration_url()); ?>" class="yatra-link yatra-link-bold"> | |
| 148 | + <?php // href kept as a no-JS fallback; JS intercepts to switch to the register tab. ?> | |
| 149 | + <a href="<?php echo esc_url(wp_registration_url()); ?>" class="yatra-link yatra-link-bold yatra-auth-switch" data-target="register"> | |
| 121 | 150 | <?php esc_html_e('Sign up', 'yatra'); ?> |
| 122 | 151 | </a> |
| 123 | 152 | </p> |
| 124 | 153 | </div> |
| 154 | + <?php endif; ?> | |
| 155 | + | |
| 156 | + </div><?php // .yatra-auth-panel-login ?> | |
| 157 | + | |
| 158 | + <?php if ($atts['show_register'] === 'yes' && $registration_enabled): ?> | |
| 159 | + <div class="yatra-auth-panel yatra-auth-panel-register" data-panel="register" | |
| 160 | + data-header-title="<?php echo esc_attr__('Create Account', 'yatra'); ?>" | |
| 161 | + data-header-subtitle="<?php echo esc_attr__('Create an account to manage your bookings and travel updates.', 'yatra'); ?>" | |
| 162 | + data-footer-text="<?php echo esc_attr__('Your details are secure and encrypted.', 'yatra'); ?>" | |
| 163 | + id="<?php echo esc_attr($form_id); ?>-panel-register" role="tabpanel" aria-labelledby="<?php echo esc_attr($form_id); ?>-tab-register" tabindex="0" style="display: none;" aria-hidden="true"> | |
| 164 | + <form class="yatra-register-form" id="<?php echo esc_attr($form_id); ?>-register" method="post" action="" data-ajax="true" novalidate> | |
| 165 | + <input type="hidden" name="yatra_login_nonce" value="<?php echo esc_attr($auth_action_nonce); ?>"> | |
| 166 | + <div class="yatra-form-row" style="display: flex; gap: 12px;"> | |
| 167 | + <div class="yatra-form-group" style="flex: 1;"> | |
| 168 | + <label for="<?php echo esc_attr($form_id); ?>-reg-first-name" class="yatra-form-label"> | |
| 169 | + <?php esc_html_e('First Name', 'yatra'); ?> | |
| 170 | + </label> | |
| 171 | + <input type="text" id="<?php echo esc_attr($form_id); ?>-reg-first-name" name="first_name" class="yatra-form-input" required maxlength="60" autocomplete="given-name" placeholder="<?php esc_attr_e('Enter your first name', 'yatra'); ?>"> | |
| 172 | + </div> | |
| 173 | + <div class="yatra-form-group" style="flex: 1;"> | |
| 174 | + <label for="<?php echo esc_attr($form_id); ?>-reg-last-name" class="yatra-form-label"> | |
| 175 | + <?php esc_html_e('Last Name', 'yatra'); ?> | |
| 176 | + </label> | |
| 177 | + <input type="text" id="<?php echo esc_attr($form_id); ?>-reg-last-name" name="last_name" class="yatra-form-input" required maxlength="60" autocomplete="family-name" placeholder="<?php esc_attr_e('Enter your last name', 'yatra'); ?>"> | |
| 178 | + </div> | |
| 179 | + </div> | |
| 180 | + <div class="yatra-form-group"> | |
| 181 | + <label for="<?php echo esc_attr($form_id); ?>-reg-email" class="yatra-form-label"> | |
| 182 | + <?php esc_html_e('Email', 'yatra'); ?> | |
| 183 | + </label> | |
| 184 | + <input type="email" id="<?php echo esc_attr($form_id); ?>-reg-email" name="email" class="yatra-form-input" required maxlength="100" autocomplete="email" placeholder="<?php esc_attr_e('[email protected]', 'yatra'); ?>"> | |
| 185 | + </div> | |
| 186 | + <div class="yatra-form-group"> | |
| 187 | + <label for="<?php echo esc_attr($form_id); ?>-reg-phone" class="yatra-form-label"> | |
| 188 | + <?php esc_html_e('Phone', 'yatra'); ?> <span style="color:#9ca3af; font-weight:400;">(<?php esc_html_e('optional', 'yatra'); ?>)</span> | |
| 189 | + </label> | |
| 190 | + <input type="tel" id="<?php echo esc_attr($form_id); ?>-reg-phone" name="phone" class="yatra-form-input" maxlength="30" autocomplete="tel" placeholder="<?php esc_attr_e('Enter your phone number', 'yatra'); ?>"> | |
| 191 | + </div> | |
| 192 | + <div class="yatra-form-group"> | |
| 193 | + <label for="<?php echo esc_attr($form_id); ?>-reg-password" class="yatra-form-label"> | |
| 194 | + <?php esc_html_e('Password', 'yatra'); ?> | |
| 195 | + </label> | |
| 196 | + <div class="yatra-password-input-group"> | |
| 197 | + <input type="password" id="<?php echo esc_attr($form_id); ?>-reg-password" name="password" class="yatra-form-input" required minlength="8" autocomplete="new-password" placeholder="<?php esc_attr_e('Minimum 8 characters', 'yatra'); ?>"> | |
| 198 | + <button type="button" class="yatra-password-toggle" aria-label="<?php esc_attr_e('Toggle password visibility', 'yatra'); ?>" data-target="<?php echo esc_attr($form_id); ?>-reg-password"> | |
| 199 | + <?php echo yatra_svg_icon('eye', 'yatra-eye-icon'); ?> | |
| 200 | + <?php echo yatra_svg_icon('eye-off', 'yatra-eye-off-icon'); ?> | |
| 201 | + </button> | |
| 202 | + </div> | |
| 203 | + </div> | |
| 204 | + <div class="yatra-form-group"> | |
| 205 | + <label for="<?php echo esc_attr($form_id); ?>-reg-confirm-password" class="yatra-form-label"> | |
| 206 | + <?php esc_html_e('Confirm Password', 'yatra'); ?> | |
| 207 | + </label> | |
| 208 | + <div class="yatra-password-input-group"> | |
| 209 | + <input type="password" id="<?php echo esc_attr($form_id); ?>-reg-confirm-password" name="confirm_password" class="yatra-form-input" required minlength="8" autocomplete="new-password" placeholder="<?php esc_attr_e('Re-enter password', 'yatra'); ?>"> | |
| 210 | + <button type="button" class="yatra-password-toggle" aria-label="<?php esc_attr_e('Toggle password visibility', 'yatra'); ?>" data-target="<?php echo esc_attr($form_id); ?>-reg-confirm-password"> | |
| 211 | + <?php echo yatra_svg_icon('eye', 'yatra-eye-icon'); ?> | |
| 212 | + <?php echo yatra_svg_icon('eye-off', 'yatra-eye-off-icon'); ?> | |
| 213 | + </button> | |
| 214 | + </div> | |
| 215 | + </div> | |
| 216 | + <div class="yatra-form-actions"> | |
| 217 | + <button type="submit" class="yatra-btn yatra-btn-primary yatra-btn-full"> | |
| 218 | + <span class="yatra-btn-text"><?php esc_html_e('Create Account', 'yatra'); ?></span> | |
| 219 | + <span class="yatra-btn-loading" style="display: none;"><?php esc_html_e('Creating account...', 'yatra'); ?></span> | |
| 220 | + </button> | |
| 221 | + </div> | |
| 222 | + </form> | |
| 223 | + <div class="yatra-register-prompt"> | |
| 224 | + <p> | |
| 225 | + <?php esc_html_e('Already have an account?', 'yatra'); ?> | |
| 226 | + <a href="#" class="yatra-link yatra-link-bold yatra-auth-switch" data-target="login"> | |
| 227 | + <?php esc_html_e('Log in', 'yatra'); ?> | |
| 228 | + </a> | |
| 229 | + </p> | |
| 230 | + </div> | |
| 231 | + </div><?php // .yatra-auth-panel-register ?> | |
| 232 | + <?php endif; ?> | |
| 233 | + | |
| 234 | + <?php if ($atts['show_forgot_password'] === 'yes'): ?> | |
| 235 | + <div class="yatra-auth-panel yatra-auth-panel-forgot" data-panel="forgot" | |
| 236 | + data-header-title="<?php echo esc_attr__('Reset Password', 'yatra'); ?>" | |
| 237 | + data-header-subtitle="<?php echo esc_attr__("Enter your email and we'll send you a link to reset your password.", 'yatra'); ?>" | |
| 238 | + data-footer-text="<?php echo esc_attr__('Your request is secure and encrypted.', 'yatra'); ?>" | |
| 239 | + role="region" aria-label="<?php esc_attr_e('Reset password', 'yatra'); ?>" style="display: none;" aria-hidden="true"> | |
| 240 | + <form class="yatra-forgot-form" id="<?php echo esc_attr($form_id); ?>-forgot" method="post" action="" data-ajax="true" novalidate> | |
| 241 | + <input type="hidden" name="yatra_login_nonce" value="<?php echo esc_attr($auth_action_nonce); ?>"> | |
| 242 | + <div class="yatra-form-group"> | |
| 243 | + <label for="<?php echo esc_attr($form_id); ?>-forgot-login" class="yatra-form-label"> | |
| 244 | + <?php esc_html_e('Email or Username', 'yatra'); ?> | |
| 245 | + </label> | |
| 246 | + <input type="text" id="<?php echo esc_attr($form_id); ?>-forgot-login" name="user_login" class="yatra-form-input" required maxlength="100" autocomplete="username" placeholder="<?php esc_attr_e('Enter your email or username', 'yatra'); ?>"> | |
| 247 | + </div> | |
| 248 | + <div class="yatra-form-actions"> | |
| 249 | + <button type="submit" class="yatra-btn yatra-btn-primary yatra-btn-full"> | |
| 250 | + <span class="yatra-btn-text"><?php esc_html_e('Send Reset Link', 'yatra'); ?></span> | |
| 251 | + <span class="yatra-btn-loading" style="display: none;"><?php esc_html_e('Sending...', 'yatra'); ?></span> | |
| 252 | + </button> | |
| 253 | + </div> | |
| 254 | + </form> | |
| 255 | + <div class="yatra-register-prompt"> | |
| 256 | + <p> | |
| 257 | + <a href="#" class="yatra-link yatra-auth-switch" data-target="login"> | |
| 258 | + <?php esc_html_e('Back to login', 'yatra'); ?> | |
| 259 | + </a> | |
| 260 | + </p> | |
| 261 | + </div> | |
| 262 | + </div><?php // .yatra-auth-panel-forgot ?> | |
| 125 | 263 | <?php endif; ?> |
| 126 | 264 | </div> |
| 127 | 265 | |
| 128 | 266 | <div class="yatra-login-footer"> |