firebase-authentication
Last commit date
admin
3 years ago
includes
3 years ago
languages
3 years ago
public
3 years ago
views
3 years ago
README.txt
3 years ago
class-mo-firebase-config.php
3 years ago
class-mo-firebase-contact-us.php
3 years ago
firebase-authentication.php
3 years ago
index.php
3 years ago
uninstall.php
3 years ago
firebase-authentication.php
603 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Initial File for Firebase Authentication plugin. |
| 4 | * |
| 5 | * @link https://miniorange.com |
| 6 | * @since 1.0.0 |
| 7 | * @package Firebase_Authentication |
| 8 | * |
| 9 | * @wordpress-plugin |
| 10 | * Plugin Name: Firebase Authentication |
| 11 | * Plugin URI: firebase-authentication |
| 12 | * Description: This plugin allows login into WordPress using Firebase as Identity provider. |
| 13 | * Version: 1.6.0 |
| 14 | * Author: miniOrange |
| 15 | * Author URI: https://miniorange.com |
| 16 | * License: MIT/Expat |
| 17 | */ |
| 18 | |
| 19 | // If this file is called directly, abort. |
| 20 | if ( ! defined( 'WPINC' ) ) { |
| 21 | die; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Currently plugin version. |
| 26 | * Start at version 1.0.0 and use SemVer - https://semver.org |
| 27 | * Rename this for your plugin and update it as you release new versions. |
| 28 | */ |
| 29 | define( 'MO_FIREBASE_AUTHENTICATION_VERSION', '1.6.0' ); |
| 30 | |
| 31 | /** |
| 32 | * The code that runs during plugin deactivation. |
| 33 | * This action is documented in includes/class-mo-firebase-authentication-deactivator.php |
| 34 | */ |
| 35 | function mo_firebase_deactivate_firebase_authentication() { |
| 36 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-mo-firebase-authentication-deactivator.php'; |
| 37 | MO_Firebase_Authentication_Deactivator::deactivate(); |
| 38 | } |
| 39 | |
| 40 | register_deactivation_hook( __FILE__, 'mo_firebase_deactivate_firebase_authentication' ); |
| 41 | |
| 42 | /** |
| 43 | * The core plugin class that is used to define internationalization, |
| 44 | * admin-specific hooks, and public-facing site hooks. |
| 45 | */ |
| 46 | require plugin_dir_path( __FILE__ ) . 'includes/class-mo-firebase-authentication.php'; |
| 47 | require_once 'class-mo-firebase-config.php'; |
| 48 | require 'views/feedback-form.php'; |
| 49 | require 'class-mo-firebase-contact-us.php'; |
| 50 | require 'admin/class-mo-firebase-customer.php'; |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * Begins execution of the plugin. |
| 55 | * |
| 56 | * Since everything within the plugin is registered via hooks, |
| 57 | * then kicking off the plugin from this point in the file does |
| 58 | * not affect the page life cycle. |
| 59 | * |
| 60 | * @since 1.0.0 |
| 61 | */ |
| 62 | function mo_firebase_run_firebase_authentication() { |
| 63 | |
| 64 | $plugin = new MO_Firebase_Authentication(); |
| 65 | $plugin->run(); |
| 66 | |
| 67 | } |
| 68 | mo_firebase_run_firebase_authentication(); |
| 69 | |
| 70 | /** |
| 71 | * Check if the customer key exists. |
| 72 | */ |
| 73 | function mo_firebase_authentication_is_customer_registered() { |
| 74 | $email = get_option( 'mo_firebase_authentication_admin_email' ); |
| 75 | $customer_key = get_option( 'mo_firebase_authentication_admin_customer_key' ); |
| 76 | if ( ! $email || ! $customer_key || ! is_numeric( trim( $customer_key ) ) ) { |
| 77 | return 0; |
| 78 | } else { |
| 79 | return 1; |
| 80 | } |
| 81 | } |
| 82 | /** |
| 83 | * Check is license key verified |
| 84 | */ |
| 85 | function mo_firebase_authentication_is_clv() { |
| 86 | $license_key = get_option( 'mo_firebase_authentication_lk' ); |
| 87 | $isverified = get_option( 'mo_firebase_authentication_lv' ); |
| 88 | if ( $isverified ) { |
| 89 | $isverified = mo_firebase_authentication_decrypt( $isverified ); |
| 90 | } |
| 91 | |
| 92 | if ( ! empty( $license_key ) && 'true' === $isverified ) { |
| 93 | return 1; |
| 94 | } |
| 95 | return 0; |
| 96 | } |
| 97 | /** |
| 98 | * Encryption for license key |
| 99 | * |
| 100 | * @param string $str . |
| 101 | */ |
| 102 | function mo_firebase_authentication_encrypt( $str ) { |
| 103 | $pass = get_option( 'mo_firebase_authentication_customer_token' ); |
| 104 | $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) ); |
| 105 | $stra = str_split( $str ); |
| 106 | foreach ( $stra as $k => $v ) { |
| 107 | $tmp = ord( $v ) + ord( $pass[ $k ] ); |
| 108 | $stra[ $k ] = chr( $tmp > 255 ? ( $tmp - 256 ) : $tmp ); |
| 109 | } |
| 110 | return base64_encode( join( '', $stra ) ); //phpcs:ignore -- ignoring DiscouragedPHPFunctions warning as this line of code is used for a valid code consisting license key encryption. |
| 111 | } |
| 112 | /** |
| 113 | * Decryption for license key |
| 114 | * |
| 115 | * @param string $str . |
| 116 | */ |
| 117 | function mo_firebase_authentication_decrypt( $str ) { |
| 118 | $str = base64_decode( $str ); //phpcs:ignore -- ignoring DiscouragedPHPFunctions warning as this line of code is used for a valid code consisting license key ncryption. |
| 119 | $pass = get_option( 'mo_firebase_authentication_customer_token' ); |
| 120 | $pass = str_split( str_pad( '', strlen( $str ), $pass, STR_PAD_RIGHT ) ); |
| 121 | $stra = str_split( $str ); |
| 122 | foreach ( $stra as $k => $v ) { |
| 123 | $tmp = ord( $v ) - ord( $pass[ $k ] ); |
| 124 | $stra[ $k ] = chr( $tmp < 0 ? ( $tmp + 256 ) : $tmp ); |
| 125 | } |
| 126 | return join( '', $stra ); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Firebase Authentication Main Class |
| 131 | */ |
| 132 | class Miniorange_Firebase_Authentication { |
| 133 | /** |
| 134 | * Constructor |
| 135 | */ |
| 136 | public function __construct() { |
| 137 | add_action( 'init', array( $this, 'post_register' ) ); |
| 138 | add_action( 'admin_init', array( $this, 'mo_firebase_auth_admin_forms_handler' ) ); |
| 139 | if ( 1 === (int) get_option( 'mo_enable_firebase_auth' ) ) { |
| 140 | if ( strpos( ( isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '' ), '/wp-json' ) === false ) { |
| 141 | remove_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); |
| 142 | remove_filter( 'authenticate', 'wp_authenticate_email_password', 20, 3 ); |
| 143 | add_filter( 'authenticate', array( $this, 'mo_firebase_auth' ), 0, 3 ); |
| 144 | } |
| 145 | } |
| 146 | remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message' ) ); |
| 147 | remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message' ) ); |
| 148 | add_action( 'admin_footer', array( $this, 'mo_firebase_auth_feedback_request' ) ); |
| 149 | update_option( 'host_name', 'https://login.xecurify.com' ); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Save details after customer registration |
| 154 | */ |
| 155 | public function post_register() { |
| 156 | if ( isset( $_POST['verify_user'] ) && isset( $_REQUEST['page'] ) && sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) === 'mo_firebase_authentication' && wp_verify_nonce( isset( $_REQUEST['mo_firebase_auth_config_field'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_auth_config_field'] ) ) : '', 'mo_firebase_auth_config_form' ) ) { |
| 157 | |
| 158 | if ( current_user_can( 'administrator' ) ) { |
| 159 | update_option( 'mo_firebase_auth_disable_wordpress_login', isset( $_POST['disable_wordpress_login'] ) ? (int) filter_var( wp_unslash( $_POST['disable_wordpress_login'] ), FILTER_SANITIZE_NUMBER_INT ) : 0 ); |
| 160 | |
| 161 | update_option( 'mo_firebase_auth_enable_admin_wp_login', isset( $_POST['mo_firebase_auth_enable_admin_wp_login'] ) ? (int) filter_var( wp_unslash( $_POST['mo_firebase_auth_enable_admin_wp_login'] ), FILTER_SANITIZE_NUMBER_INT ) : 0 ); |
| 162 | |
| 163 | $project_id = isset( $_POST['projectid'] ) ? sanitize_text_field( wp_unslash( $_POST['projectid'] ) ) : ''; |
| 164 | update_option( 'mo_firebase_auth_project_id', $project_id ); |
| 165 | |
| 166 | $api_key = isset( $_POST['apikey'] ) ? sanitize_text_field( wp_unslash( $_POST['apikey'] ) ) : ''; |
| 167 | update_option( 'mo_firebase_auth_api_key', $api_key ); |
| 168 | |
| 169 | $this->mo_firebase_auth_store_certificates(); |
| 170 | update_option( 'mo_firebase_auth_message', 'Configurations saved successfully. Please <a href="' . admin_url( 'admin.php?page=mo_firebase_authentication&tab=config#test_authentication' ) . '">Test Authentication</a> before trying to Login.' ); |
| 171 | $this->mo_firebase_auth_show_success_message(); |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | /** |
| 176 | * Store certificates. |
| 177 | */ |
| 178 | public function mo_firebase_auth_store_certificates() { |
| 179 | $response = wp_remote_get( 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com' ); |
| 180 | if ( is_array( $response ) ) { |
| 181 | $header = $response['headers']; // array of http header lines. |
| 182 | $body = $response['body']; // use the content. |
| 183 | |
| 184 | $split_result = explode( ':', $body ); |
| 185 | $count = count( $split_result ); |
| 186 | $kid1 = substr( $split_result[0], 5, 40 ); |
| 187 | $s = explode( ',', $split_result[1] ); |
| 188 | $c1 = substr( $s[0], 2, 1158 ); |
| 189 | $c1 = str_replace( '\n', '', $c1 ); |
| 190 | update_option( 'mo_firebase_auth_kid1', $kid1 ); |
| 191 | update_option( 'mo_firebase_auth_cert1', $c1 ); |
| 192 | if ( 3 === $count ) { |
| 193 | $kid2 = substr( $s[1], 4, 40 ); |
| 194 | $c2 = explode( '}', $split_result[2] ); |
| 195 | $c2[0] = substr( $c2[0], 2, 1158 ); |
| 196 | $c2[0] = str_replace( '\n', '', $c2[0] ); |
| 197 | update_option( 'mo_firebase_auth_kid2', $kid2 ); |
| 198 | update_option( 'mo_firebase_auth_cert2', $c2[0] ); |
| 199 | } elseif ( $count > 3 ) { |
| 200 | $kid2 = substr( $s[1], 4, 40 ); |
| 201 | $s2 = explode( ',', $split_result[2] ); |
| 202 | $c2 = substr( $s2[0], 2, 1158 ); |
| 203 | $kid3 = substr( $s2[1], 4, 40 ); |
| 204 | $c3 = explode( '}', $split_result[3] ); |
| 205 | $c3[0] = substr( $c3[0], 2, 1158 ); |
| 206 | $c2 = str_replace( '\n', '', $c2 ); |
| 207 | update_option( 'mo_firebase_auth_kid2', $kid2 ); |
| 208 | update_option( 'mo_firebase_auth_cert2', $c2 ); |
| 209 | $c3[0] = str_replace( '\n', '', $c3[0] ); |
| 210 | update_option( 'mo_firebase_auth_kid3', $kid3 ); |
| 211 | update_option( 'mo_firebase_auth_cert3', $c3[0] ); |
| 212 | } |
| 213 | } else { |
| 214 | if ( is_wp_error( $response ) ) { |
| 215 | $error_message = $response->get_error_message(); |
| 216 | echo 'Something went wrong: ' . esc_attr( $error_message ); |
| 217 | exit(); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | /** |
| 222 | * Handler function |
| 223 | * |
| 224 | * @param array $errors . |
| 225 | * @param string $redirect_to . |
| 226 | */ |
| 227 | public function mo_fb_clear_wp_login_errors( $errors, $redirect_to ) { |
| 228 | return new WP_Error(); |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * Firebase Authentication Login Handler |
| 233 | * |
| 234 | * @param WP_User/WP_Error $default_user . |
| 235 | * @param string $username . |
| 236 | * @param string $password . |
| 237 | */ |
| 238 | public function mo_firebase_auth( $default_user, $username, $password ) { |
| 239 | |
| 240 | if ( 'POST' !== ( isset( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : '' ) ) { |
| 241 | add_filter( 'wp_login_errors', array( $this, 'mo_fb_clear_wp_login_errors' ), 0, 2 ); |
| 242 | return $default_user; |
| 243 | } |
| 244 | |
| 245 | if ( empty( $username ) || empty( $password ) ) { |
| 246 | |
| 247 | $error = new WP_Error(); |
| 248 | // create new error object and add errors to it. |
| 249 | |
| 250 | if ( empty( $username ) ) { // No email. |
| 251 | $error->add( 'empty_username', __( '<strong>ERROR</strong>: Email field is empty.' ) ); |
| 252 | } elseif ( empty( $password ) ) { // No password. |
| 253 | $error->add( 'empty_password', __( '<strong>ERROR</strong>: Password field is empty.' ) ); |
| 254 | } |
| 255 | return $error; |
| 256 | } |
| 257 | |
| 258 | $mo_firebase_config_obj = new Mo_Firebase_Config(); |
| 259 | $fb_user = $mo_firebase_config_obj->mo_firebase_authenticate_call( $username, $password ); |
| 260 | $fb_user = json_decode( $fb_user, true ); |
| 261 | |
| 262 | if ( isset( $fb_user['idToken'] ) ) { |
| 263 | $response = $mo_firebase_config_obj->mo_fb_login_user( $fb_user['idToken'] ); |
| 264 | } else { |
| 265 | |
| 266 | $error_message = $fb_user['error']['message']; |
| 267 | if ( 'INVALID_EMAIL' === $error_message || 'EMAIL_NOT_FOUND' === $error_message ) { |
| 268 | if ( false === get_option( 'mo_firebase_auth_disable_wordpress_login' ) ) { |
| 269 | $user = get_user_by( 'login', $username ); |
| 270 | if ( ! $user ) { |
| 271 | $user = get_user_by( 'email', $username ); |
| 272 | } |
| 273 | if ( $user && wp_check_password( $password, $user->data->user_pass, $user->ID ) ) { |
| 274 | return $user; |
| 275 | } |
| 276 | } elseif ( get_option( 'mo_firebase_auth_enable_admin_wp_login' ) ) { |
| 277 | $user = get_user_by( 'login', $username ); |
| 278 | if ( ! $user ) { |
| 279 | $user = get_user_by( 'email', $username ); |
| 280 | } |
| 281 | if ( $user && $this->is_administrator_user( $user ) ) { |
| 282 | |
| 283 | if ( wp_check_password( $password, $user->data->user_pass, $user->ID ) ) { |
| 284 | return $user; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | } else { |
| 289 | $error = new WP_Error(); |
| 290 | if ( 'INVALID_PASSWORD' === $error_message ) { |
| 291 | $error_message = 'The password is invalid or the user does not have a password.'; |
| 292 | } |
| 293 | $error_message = '<strong>ERROR</strong>: ' . $error_message; |
| 294 | $error->add( 'firebase_error', __( $error_message ) ); //phpcs:ignore -- Ignoring as it expects a single string literal and not a string variable. |
| 295 | return $error; |
| 296 | } |
| 297 | } |
| 298 | return $default_user; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Admin dashboard messages |
| 303 | */ |
| 304 | public function mo_firebase_auth_success_message() { |
| 305 | $message = "<div class='error'><p>" . get_option( 'mo_firebase_auth_message' ) . '</p></div>'; |
| 306 | $allowed_tags = array( |
| 307 | 'div' => array( |
| 308 | 'class' => array(), |
| 309 | ), |
| 310 | 'a' => array( |
| 311 | 'href' => array(), |
| 312 | ), |
| 313 | ); |
| 314 | echo wp_kses( $message, $allowed_tags ); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Admin dashboard messages |
| 319 | */ |
| 320 | public function mo_firebase_auth_error_message() { |
| 321 | $message = "<div class='updated'><p>" . get_option( 'mo_firebase_auth_message' ) . '</p></div>'; |
| 322 | $allowed_tags = array( |
| 323 | 'div' => array( |
| 324 | 'class' => array(), |
| 325 | ), |
| 326 | 'a' => array( |
| 327 | 'href' => array(), |
| 328 | ), |
| 329 | ); |
| 330 | echo wp_kses( $message, $allowed_tags ); |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Check for admin user |
| 335 | * |
| 336 | * @param WP_User $user . |
| 337 | */ |
| 338 | public function is_administrator_user( $user ) { |
| 339 | $user_role = ( $user->roles ); |
| 340 | if ( ! is_null( $user_role ) && in_array( 'administrator', $user_role, true ) ) { |
| 341 | return true; |
| 342 | } else { |
| 343 | return false; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Admin dashboard messages |
| 349 | */ |
| 350 | private function mo_firebase_auth_show_success_message() { |
| 351 | remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message' ) ); |
| 352 | add_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message' ) ); |
| 353 | } |
| 354 | /** |
| 355 | * Admin dashboard messages |
| 356 | */ |
| 357 | private function mo_firebase_auth_show_error_message() { |
| 358 | remove_action( 'admin_notices', array( $this, 'mo_firebase_auth_error_message' ) ); |
| 359 | add_action( 'admin_notices', array( $this, 'mo_firebase_auth_success_message' ) ); |
| 360 | } |
| 361 | /** |
| 362 | * Admin dashboard feedback form on deactivation |
| 363 | */ |
| 364 | public function mo_firebase_auth_feedback_request() { |
| 365 | mo_firebase_auth_display_feedback_form(); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Function to check the validations |
| 370 | * |
| 371 | * @param string $value . |
| 372 | */ |
| 373 | private function mo_firebase_authentication_check_empty_or_null( $value ) { |
| 374 | if ( ! isset( $value ) || empty( $value ) ) { |
| 375 | return true; |
| 376 | } |
| 377 | return false; |
| 378 | } |
| 379 | /** |
| 380 | * Function for backend of admin forms such as contact us, feedback, login, etc. |
| 381 | */ |
| 382 | public function mo_firebase_auth_admin_forms_handler() { |
| 383 | |
| 384 | if ( isset( $_POST['option'] ) ) { |
| 385 | |
| 386 | if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_change_email' && isset( $_REQUEST['mo_firebase_authentication_change_email_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_authentication_change_email_form_nonce'] ) ), 'mo_firebase_authentication_change_email_form' ) ) { |
| 387 | // Adding back button. |
| 388 | update_option( 'mo_firebase_authentication_verify_customer', '' ); |
| 389 | update_option( 'mo_firebase_authentication_registration_status', '' ); |
| 390 | update_option( 'mo_firebase_authentication_new_registration', 'true' ); |
| 391 | } |
| 392 | |
| 393 | if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'change_miniorange' && isset( $_REQUEST['change_miniorange_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['change_miniorange_form_nonce'] ) ), 'change_miniorange_form' ) ) { |
| 394 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-mo-firebase-authentication-deactivator.php'; |
| 395 | MO_Firebase_Authentication_Deactivator::deactivate(); |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_register_customer' && isset( $_REQUEST['mo_fb_register_form_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_fb_register_form_nonce'] ) ), 'mo_fb_register_form' ) ) { // register the admin to miniOrange |
| 400 | // validation and sanitization. |
| 401 | $email = ''; |
| 402 | $phone = ''; |
| 403 | $password = isset( $_POST['password'] ) ? stripslashes( $_POST['password'] ) : ''; //phpcs:ignore -- Ignoring sanitization for password input in case of special characters. |
| 404 | $confirm_password = isset( $_POST['confirmPassword'] ) ? stripslashes( $_POST['confirmPassword'] ) : ''; //phpcs:ignore -- Ignoring sanitization for password input in case of special characters. |
| 405 | $fname = ''; |
| 406 | $lname = ''; |
| 407 | $company = ''; |
| 408 | if ( ! ( isset( $_POST['email'] ) && isset( $_POST['password'] ) && isset( $_POST['confirmPassword'] ) ) ) { |
| 409 | update_option( 'mo_firebase_auth_message', 'All the fields are required. Please enter valid entries.' ); |
| 410 | $this->mo_firebase_auth_show_error_message(); |
| 411 | return; |
| 412 | } elseif ( strlen( $password ) < 8 || strlen( $confirm_password ) < 8 ) { |
| 413 | update_option( 'mo_firebase_auth_message', 'Choose a password with minimum length 8.' ); |
| 414 | $this->mo_firebase_auth_show_error_message(); |
| 415 | return; |
| 416 | } else { |
| 417 | $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; |
| 418 | $phone = isset( $_POST['phone'] ) ? sanitize_text_field( wp_unslash( $_POST['phone'] ) ) : ''; |
| 419 | $fname = isset( $_POST['fname'] ) ? sanitize_text_field( wp_unslash( $_POST['fname'] ) ) : ''; |
| 420 | $lname = isset( $_POST['lname'] ) ? sanitize_text_field( wp_unslash( $_POST['lname'] ) ) : ''; |
| 421 | $company = isset( $_POST['company'] ) ? sanitize_text_field( wp_unslash( $_POST['company'] ) ) : ''; |
| 422 | } |
| 423 | |
| 424 | update_option( 'mo_firebase_authentication_admin_email', $email ); |
| 425 | update_option( 'mo_firebase_authentication_admin_phone', $phone ); |
| 426 | update_option( 'mo_firebase_authentication_admin_fname', $fname ); |
| 427 | update_option( 'mo_firebase_authentication_admin_lname', $lname ); |
| 428 | update_option( 'mo_firebase_authentication_admin_company', $company ); |
| 429 | |
| 430 | if ( 0 === strcmp( $password, $confirm_password ) ) { |
| 431 | update_option( 'password', $password ); |
| 432 | $customer = new MO_Firebase_Customer(); |
| 433 | $email = get_option( 'mo_firebase_authentication_admin_email' ); |
| 434 | $content = json_decode( $customer->check_customer(), true ); |
| 435 | |
| 436 | if ( 0 === strcasecmp( $content['status'], 'CUSTOMER_NOT_FOUND' ) ) { |
| 437 | $response = json_decode( $customer->create_customer(), true ); |
| 438 | if ( strcasecmp( $response['status'], 'SUCCESS' ) !== 0 ) { |
| 439 | update_option( 'mo_firebase_auth_message', 'Failed to create customer. Try again.' ); |
| 440 | $this->mo_firebase_auth_show_error_message(); |
| 441 | } else { |
| 442 | update_option( 'mo_firebase_auth_message', 'Your registration is successful. Please login.' ); |
| 443 | $this->mo_firebase_auth_show_success_message(); |
| 444 | } |
| 445 | } elseif ( 0 === strcasecmp( $content['status'], 'SUCCESS' ) ) { |
| 446 | update_option( 'mo_firebase_auth_message', 'Account already exist. Please Login.' ); |
| 447 | $this->mo_firebase_auth_show_error_message(); |
| 448 | } else { |
| 449 | update_option( 'mo_firebase_auth_message', $content['status'] ); |
| 450 | $this->mo_firebase_auth_show_success_message(); |
| 451 | } |
| 452 | } else { |
| 453 | update_option( 'mo_firebase_auth_message', 'Passwords do not match.' ); |
| 454 | delete_option( 'mo_firebase_authentication_verify_customer' ); |
| 455 | $this->mo_firebase_auth_show_error_message(); |
| 456 | } |
| 457 | } if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_goto_login' && isset( $_REQUEST['mo_firebase_authentication_goto_login_form_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['mo_firebase_authentication_goto_login_form_field'] ) ), 'mo_firebase_authentication_goto_login_form' ) ) { |
| 458 | delete_option( 'mo_firebase_authentication_new_registration' ); |
| 459 | update_option( 'mo_firebase_authentication_verify_customer', 'true' ); |
| 460 | |
| 461 | } if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_enable_firebase_auth' && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_enable_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_enable_field'] ) ) : '' ), 'mo_firebase_auth_enable_form' ) ) { |
| 462 | update_option( 'mo_enable_firebase_auth', isset( $_POST['mo_enable_firebase_auth'] ) ? (int) filter_var( wp_unslash( $_POST['mo_enable_firebase_auth'] ), FILTER_SANITIZE_NUMBER_INT ) : 0 ); |
| 463 | |
| 464 | } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_auth_contact_us' && isset( $_REQUEST['mo_firebase_auth_contact_us_field'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_contact_us_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_contact_us_field'] ) ) : '' ), 'mo_firebase_auth_contact_us_form' ) ) { |
| 465 | $email = isset( $_POST['mo_firebase_auth_contact_us_email'] ) ? sanitize_email( wp_unslash( $_POST['mo_firebase_auth_contact_us_email'] ) ) : ''; |
| 466 | $phone = isset( $_POST['mo_firebase_auth_contact_us_phone'] ) ? '+ ' . preg_replace( '/[^0-9]/', '', sanitize_text_field( wp_unslash( $_POST['mo_firebase_auth_contact_us_phone'] ) ) ) : ''; |
| 467 | $query = isset( $_POST['mo_firebase_auth_contact_us_query'] ) ? sanitize_textarea_field( wp_unslash( $_POST['mo_firebase_auth_contact_us_query'] ) ) : ''; |
| 468 | if ( $this->mo_firebase_authentication_check_empty_or_null( $email ) || $this->mo_firebase_authentication_check_empty_or_null( $query ) ) { |
| 469 | echo '<br><b style=color:red>Please fill up Email and Query fields to submit your query.</b>'; |
| 470 | } else { |
| 471 | $contact_us = new MO_Firebase_contact_us(); |
| 472 | $submited = $contact_us->mo_firebase_auth_contact_us( $email, $phone, $query ); |
| 473 | if ( false === $submited ) { |
| 474 | update_option( 'mo_firebase_auth_message', 'Your query could not be submitted. Please try again.' ); |
| 475 | $this->mo_firebase_auth_show_error_message(); |
| 476 | } else { |
| 477 | update_option( 'mo_firebase_auth_message', 'Thanks for getting in touch! We shall get back to you shortly.' ); |
| 478 | $this->mo_firebase_auth_show_success_message(); |
| 479 | } |
| 480 | } |
| 481 | } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_authentication_verify_customer' && isset( $_REQUEST['mo_fb_login_form_nonce'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_fb_login_form_nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_fb_login_form_nonce'] ) ) : '' ), 'mo_fb_login_form' ) ) {// register the admin to miniOrange |
| 482 | // validation and sanitization. |
| 483 | $email = ''; |
| 484 | $password = ''; |
| 485 | if ( ! ( isset( $_POST['email'] ) && isset( $_POST['password'] ) ) ) { |
| 486 | update_option( 'mo_firebase_auth_message', 'All the fields are required. Please enter valid entries.' ); |
| 487 | $this->mo_firebase_auth_show_error_message(); |
| 488 | return; |
| 489 | } else { |
| 490 | $email = sanitize_email( wp_unslash( $_POST['email'] ) ); |
| 491 | $password = stripslashes( wp_unslash( $_POST['password'] ) ); //phpcs:ignore -- Ignoring sanitization for password input in case of special characters. |
| 492 | } |
| 493 | |
| 494 | update_option( 'mo_firebase_authentication_admin_email', $email ); |
| 495 | update_option( 'password', $password ); |
| 496 | $customer = new MO_Firebase_Customer(); |
| 497 | $content = $customer->mo_firebase_auth_get_customer_key(); |
| 498 | $customer_key = json_decode( $content, true ); |
| 499 | if ( json_last_error() === JSON_ERROR_NONE ) { |
| 500 | update_option( 'mo_firebase_authentication_admin_customer_key', $customer_key['id'] ); |
| 501 | update_option( 'mo_firebase_authentication_admin_api_key', $customer_key['apiKey'] ); |
| 502 | update_option( 'mo_firebase_authentication_customer_token', $customer_key['token'] ); |
| 503 | if ( isset( $customer_key['phone'] ) ) { |
| 504 | update_option( 'mo_firebase_authentication_admin_phone', $customer_key['phone'] ); |
| 505 | } |
| 506 | delete_option( 'password' ); |
| 507 | update_option( 'mo_firebase_auth_message', 'Customer retrieved successfully' ); |
| 508 | delete_option( 'mo_firebase_authentication_verify_customer' ); |
| 509 | $this->mo_firebase_auth_show_success_message(); |
| 510 | } else { |
| 511 | update_option( 'mo_firebase_auth_message', 'Invalid username or password. Please try again.' ); |
| 512 | $this->mo_firebase_auth_show_error_message(); |
| 513 | } |
| 514 | } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_auth_skip_feedback' && isset( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_skip_feedback_form_nonce'] ) ) : '' ), 'mo_firebase_auth_skip_feedback_form' ) ) { |
| 515 | deactivate_plugins( __FILE__ ); |
| 516 | update_option( 'mo_firebase_auth_message', 'Plugin deactivated successfully' ); |
| 517 | $this->mo_firebase_auth_show_success_message(); |
| 518 | |
| 519 | } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_firebase_auth_feedback' && isset( $_REQUEST['mo_firebase_auth_feedback_field'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_firebase_auth_feedback_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_firebase_auth_feedback_field'] ) ) : '' ), 'mo_firebase_auth_feedback_form' ) ) { |
| 520 | $user = wp_get_current_user(); |
| 521 | $message = 'Plugin Deactivated:'; |
| 522 | $deactivate_reason = array_key_exists( 'deactivate_reason_radio', $_POST ) ? sanitize_text_field( wp_unslash( $_POST['deactivate_reason_radio'] ) ) : false; |
| 523 | $deactivate_reason_message = array_key_exists( 'query_feedback', $_POST ) ? sanitize_textarea_field( wp_unslash( $_POST['query_feedback'] ) ) : false; |
| 524 | if ( $deactivate_reason ) { |
| 525 | $message .= $deactivate_reason; |
| 526 | if ( isset( $deactivate_reason_message ) ) { |
| 527 | $message .= ':' . $deactivate_reason_message; |
| 528 | } |
| 529 | |
| 530 | $email = $user->user_email; |
| 531 | $contact_us = new MO_Firebase_contact_us(); |
| 532 | $submited = json_decode( $contact_us->mo_firebase_auth_send_email_alert( $email, $message, 'Feedback: WordPress Firebase Authentication' ), true ); |
| 533 | deactivate_plugins( __FILE__ ); |
| 534 | update_option( 'mo_firebase_auth_message', 'Thank you for the feedback.' ); |
| 535 | $this->mo_firebase_auth_show_success_message(); |
| 536 | |
| 537 | } else { |
| 538 | update_option( 'mo_firebase_auth_message', 'Please Select one of the reasons ,if your reason is not mentioned please select Other Reasons' ); |
| 539 | $this->mo_firebase_auth_show_error_message(); |
| 540 | } |
| 541 | } elseif ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) === 'mo_fb_demo_request_form' && isset( $_REQUEST['mo_fb_demo_request_field'] ) && wp_verify_nonce( ( isset( $_REQUEST['mo_fb_demo_request_field'] ) ? sanitize_key( wp_unslash( $_REQUEST['mo_fb_demo_request_field'] ) ) : '' ), 'mo_fb_demo_request_form' ) ) { |
| 542 | |
| 543 | if ( current_user_can( 'administrator' ) ) { |
| 544 | $email = isset( $_POST['mo_auto_create_demosite_email'] ) ? sanitize_email( wp_unslash( $_POST['mo_auto_create_demosite_email'] ) ) : ''; |
| 545 | $demo_plan = isset( $_POST['mo_auto_create_demosite_demo_plan'] ) ? sanitize_text_field( wp_unslash( $_POST['mo_auto_create_demosite_demo_plan'] ) ) : ' '; |
| 546 | $query = isset( $_POST['mo_auto_create_demosite_usecase'] ) ? sanitize_textarea_field( wp_unslash( $_POST['mo_auto_create_demosite_usecase'] ) ) : ''; |
| 547 | |
| 548 | if ( $this->mo_firebase_authentication_check_empty_or_null( $email ) || $this->mo_firebase_authentication_check_empty_or_null( $demo_plan ) || $this->mo_firebase_authentication_check_empty_or_null( $query ) ) { |
| 549 | update_option( 'message', 'Please fill up Usecase, Email field and Requested demo plan to submit your query.' ); |
| 550 | $$this->mo_firebase_auth_show_error_message(); |
| 551 | } else { |
| 552 | $url = 'https://demo.miniorange.com/wpoauthsso/'; |
| 553 | |
| 554 | $headers = array( |
| 555 | 'Content-Type' => 'application/x-www-form-urlencoded', |
| 556 | 'charset' => 'UTF - 8', |
| 557 | ); |
| 558 | $args = array( |
| 559 | 'method' => 'POST', |
| 560 | 'body' => array( |
| 561 | 'option' => 'mo_auto_create_demosite', |
| 562 | 'mo_auto_create_demosite_email' => $email, |
| 563 | 'mo_auto_create_demosite_usecase' => $query, |
| 564 | 'mo_auto_create_demosite_demo_plan' => $demo_plan, |
| 565 | ), |
| 566 | 'timeout' => '20', |
| 567 | 'redirection' => '5', |
| 568 | 'httpversion' => '1.0', |
| 569 | 'blocking' => true, |
| 570 | 'headers' => $headers, |
| 571 | ); |
| 572 | |
| 573 | $response = wp_remote_post( $url, $args ); |
| 574 | if ( is_wp_error( $response ) ) { |
| 575 | $error_message = $response->get_error_message(); |
| 576 | |
| 577 | echo 'Something went wrong: ' . esc_attr( $error_message ); |
| 578 | exit(); |
| 579 | } |
| 580 | $output = wp_remote_retrieve_body( $response ); |
| 581 | $output = json_decode( $output ); |
| 582 | if ( is_null( $output ) ) { |
| 583 | update_option( 'mo_firebase_auth_message', 'We were unable to setup the demo for you. Please try again or reach out to us at <a href="mailto:oauthsupport@xecurify.com">oauthsupport@xecurify.com</a>.' ); |
| 584 | $this->mo_firebase_auth_show_success_message(); |
| 585 | } else { |
| 586 | if ( 'SUCCESS' === $output->status ) { |
| 587 | update_option( 'mo_firebase_auth_message', $output->message ); |
| 588 | $this->mo_firebase_auth_show_success_message(); |
| 589 | } else { |
| 590 | update_option( 'mo_firebase_auth_message', $output->message ); |
| 591 | $this->mo_firebase_auth_show_error_message(); |
| 592 | } |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | } |
| 601 | |
| 602 | $mo_firebase_authentication_obj = new Miniorange_Firebase_Authentication(); |
| 603 |