← All changes
|
includes/widgets/Login_Register_Form/Social_Login_Handler.php
+11
-21
51.1.39
→
51.1.83
View file →
| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | // Include Security Manager |
| 10 | 10 | require_once KING_ADDONS_PATH . 'includes/widgets/Login_Register_Form/Security_Manager.php'; |
| 11 | +require_once KING_ADDONS_PATH . 'includes/widgets/Login_Register_Form/Widget_Settings_Resolver.php'; | |
| 11 | 12 | |
| 12 | 13 | /** |
| 13 | 14 | * Social Login Handler for Login Register Form widget |
| 14 | 15 | */ |
| @@ -47,9 +48,11 @@ | ||
| 47 | 48 | wp_send_json_error(['message' => esc_html__('Security check failed.', 'king-addons')]); |
| 48 | 49 | } |
| 49 | 50 | |
| 50 | 51 | $google_token = sanitize_text_field($_POST['google_token'] ?? ''); |
| 51 | - $widget_settings = self::get_widget_settings($_POST['widget_id'] ?? ''); | |
| 52 | + $widget_id = sanitize_text_field($_POST['widget_id'] ?? ''); | |
| 53 | + $post_id = absint($_POST['post_id'] ?? 0); | |
| 54 | + $widget_settings = Widget_Settings_Resolver::resolve($post_id, $widget_id); | |
| 52 | 55 | |
| 53 | 56 | if (empty($google_token)) { |
| 54 | 57 | wp_send_json_error(['message' => esc_html__('Google token is required.', 'king-addons')]); |
| 55 | 58 | } |
| @@ -93,9 +96,11 @@ | ||
| 93 | 96 | wp_send_json_error(['message' => esc_html__('Security check failed.', 'king-addons')]); |
| 94 | 97 | } |
| 95 | 98 | |
| 96 | 99 | $facebook_token = sanitize_text_field($_POST['facebook_token'] ?? ''); |
| 97 | - $widget_settings = self::get_widget_settings($_POST['widget_id'] ?? ''); | |
| 100 | + $widget_id = sanitize_text_field($_POST['widget_id'] ?? ''); | |
| 101 | + $post_id = absint($_POST['post_id'] ?? 0); | |
| 102 | + $widget_settings = Widget_Settings_Resolver::resolve($post_id, $widget_id); | |
| 98 | 103 | |
| 99 | 104 | if (empty($facebook_token)) { |
| 100 | 105 | wp_send_json_error(['message' => esc_html__('Facebook token is required.', 'king-addons')]); |
| 101 | 106 | } |
| @@ -143,9 +148,9 @@ | ||
| 143 | 148 | 'user-agent' => 'King Addons Social Login/1.0' |
| 144 | 149 | ]); |
| 145 | 150 | |
| 146 | 151 | if (is_wp_error($response)) { |
| 147 | - error_log('King Addons Social Login: Google token verification failed: ' . $response->get_error_message()); | |
| 152 | + // error_log('King Addons Social Login: Google token verification failed: ' . $response->get_error_message()); | |
| 148 | 153 | return false; |
| 149 | 154 | } |
| 150 | 155 | |
| 151 | 156 | $body = wp_remote_retrieve_body($response); |
| @@ -188,9 +193,9 @@ | ||
| 188 | 193 | 'user-agent' => 'King Addons Social Login/1.0' |
| 189 | 194 | ]); |
| 190 | 195 | |
| 191 | 196 | if (is_wp_error($response)) { |
| 192 | - error_log('King Addons Social Login: Facebook token verification failed: ' . $response->get_error_message()); | |
| 197 | + // error_log('King Addons Social Login: Facebook token verification failed: ' . $response->get_error_message()); | |
| 193 | 198 | return false; |
| 194 | 199 | } |
| 195 | 200 | |
| 196 | 201 | $verify_data = json_decode(wp_remote_retrieve_body($response), true); |
| @@ -209,9 +214,9 @@ | ||
| 209 | 214 | 'user-agent' => 'King Addons Social Login/1.0' |
| 210 | 215 | ]); |
| 211 | 216 | |
| 212 | 217 | if (is_wp_error($user_response)) { |
| 213 | - error_log('King Addons Social Login: Facebook user data request failed: ' . $user_response->get_error_message()); | |
| 218 | + // error_log('King Addons Social Login: Facebook user data request failed: ' . $user_response->get_error_message()); | |
| 214 | 219 | return false; |
| 215 | 220 | } |
| 216 | 221 | |
| 217 | 222 | $user_data = json_decode(wp_remote_retrieve_body($user_response), true); |
| @@ -243,9 +248,9 @@ | ||
| 243 | 248 | } |
| 244 | 249 | |
| 245 | 250 | // Additional security checks for social login |
| 246 | 251 | if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { |
| 247 | - error_log("King Addons Security: Invalid email from {$provider}: {$email}"); | |
| 252 | + // error_log("King Addons Security: Invalid email from {$provider}: {$email}"); | |
| 248 | 253 | return [ |
| 249 | 254 | 'success' => false, |
| 250 | 255 | 'message' => esc_html__('Invalid email address from social provider.', 'king-addons') |
| 251 | 256 | ]; |
| @@ -325,23 +330,8 @@ | ||
| 325 | 330 | $counter++; |
| 326 | 331 | } |
| 327 | 332 | |
| 328 | 333 | return $username; |
| 329 | - } | |
| 330 | - | |
| 331 | - /** | |
| 332 | - * Get widget settings from POST data | |
| 333 | - */ | |
| 334 | - private static function get_widget_settings($widget_id) | |
| 335 | - { | |
| 336 | - // This would be enhanced to get actual widget settings | |
| 337 | - // For now, return settings from POST data | |
| 338 | - return [ | |
| 339 | - 'google_client_id' => sanitize_text_field($_POST['google_client_id'] ?? ''), | |
| 340 | - 'google_client_secret' => sanitize_text_field($_POST['google_client_secret'] ?? ''), | |
| 341 | - 'facebook_app_id' => sanitize_text_field($_POST['facebook_app_id'] ?? ''), | |
| 342 | - 'facebook_app_secret' => sanitize_text_field($_POST['facebook_app_secret'] ?? ''), | |
| 343 | - ]; | |
| 344 | 334 | } |
| 345 | 335 | |
| 346 | 336 | /** |
| 347 | 337 | * Handle Google OAuth callback (for future server-side flow) |