css
6 years ago
images
6 years ago
js
6 years ago
partials
6 years ago
class-firebase-authentication-admin.php
6 years ago
index.php
6 years ago
class-firebase-authentication-admin.php
168 lines
| 1 | <?php |
| 2 | |
| 3 | require_once 'partials/firebase-authentication-admin-display.php'; |
| 4 | class MO_Firebase_Authentication_Admin { |
| 5 | |
| 6 | /** |
| 7 | * The ID of this plugin. |
| 8 | * |
| 9 | * @since 1.0.0 |
| 10 | * @access private |
| 11 | * @var string $plugin_name The ID of this plugin. |
| 12 | */ |
| 13 | private $plugin_name; |
| 14 | |
| 15 | /** |
| 16 | * The version of this plugin. |
| 17 | * |
| 18 | * @since 1.0.0 |
| 19 | * @access private |
| 20 | * @var string $version The current version of this plugin. |
| 21 | */ |
| 22 | private $version; |
| 23 | |
| 24 | /** |
| 25 | * Initialize the class and set its properties. |
| 26 | * |
| 27 | * @since 1.0.0 |
| 28 | * @param string $plugin_name The name of this plugin. |
| 29 | * @param string $version The version of this plugin. |
| 30 | */ |
| 31 | public function __construct( $plugin_name, $version ) { |
| 32 | $this->plugin_name = $plugin_name; |
| 33 | $this->version = $version; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Register the stylesheets for the admin area. |
| 38 | * |
| 39 | * @since 1.0.0 |
| 40 | */ |
| 41 | public function enqueue_styles( $hook ) { |
| 42 | if( $hook != 'toplevel_page_mo_firebase_configuration' ) { |
| 43 | return; |
| 44 | } |
| 45 | wp_enqueue_style( 'mo_firebase_auth_admin_bootstrap_style', plugins_url( 'css/bootstrap.min.css', __FILE__ ) ); |
| 46 | wp_enqueue_style( 'mo_firebase_auth_firebase_phone_style', plugins_url( 'css/phone.css', __FILE__ ) ); |
| 47 | wp_enqueue_style( 'mo_firebase_auth_settings_style', plugins_url( 'css/style.css', __FILE__ ) ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Register the JavaScript for the admin area. |
| 52 | * |
| 53 | * @since 1.0.0 |
| 54 | */ |
| 55 | public function enqueue_scripts( $hook ) { |
| 56 | if( $hook != 'toplevel_page_mo_firebase_configuration' ) { |
| 57 | return; |
| 58 | } |
| 59 | wp_enqueue_script( 'mo_firebase_auth_bootstrap_script', plugins_url( 'js/bootstrap.min.js', __FILE__) ); |
| 60 | wp_enqueue_script( 'mo_firebase_auth_custom_settings_script', plugins_url( 'js/custom.js', __FILE__) ); |
| 61 | wp_enqueue_script( 'mo_firebase_auth_firebase_phone_script', plugins_url( 'js/phone.js', __FILE__ ), array(), $this->version , false ); |
| 62 | } |
| 63 | |
| 64 | public function enqueue_firebase_scripts() { |
| 65 | if( isset( $_GET['mo_action'] ) && 'firebaselogin' === sanitize_text_field( wp_unslash($_GET['mo_action'] ) ) ) { |
| 66 | wp_enqueue_script( 'mo_firebase_app_script', plugins_url( 'js/firebase-app.js', __FILE__) ); |
| 67 | wp_enqueue_script( 'mo_firebase_auth_script', plugins_url( 'js/firebase-auth.js', __FILE__) ); |
| 68 | wp_enqueue_script( 'mo_firebase_firestore_script', plugins_url( 'js/firebase-firestore.js', __FILE__), ['jquery'] ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | public function enqueue_firebase_wp_login_scripts() { |
| 73 | wp_enqueue_script( 'mo_firebase_app_script', plugins_url( 'js/firebase-app.js', __FILE__) ); |
| 74 | wp_enqueue_script( 'mo_firebase_auth_script', plugins_url( 'js/firebase-auth.js', __FILE__) ); |
| 75 | wp_enqueue_script( 'mo_firebase_firestore_script', plugins_url( 'js/firebase-firestore.js', __FILE__), ['jquery'] ); |
| 76 | wp_register_script( 'mo_firebase_app_main_script', plugins_url( 'js/firebase-auth-main-script.js', __FILE__), [ 'jquery' ] ); |
| 77 | wp_enqueue_script( 'mo_firebase_app_main_script' ); |
| 78 | wp_register_script( 'mo_firebase_app_login_script', plugins_url( 'js/firebase-wp-login.js', __FILE__), [ 'jquery' ] ); |
| 79 | $data = []; |
| 80 | $data['api_key'] = get_option( 'mo_firebase_auth_api_key' ); |
| 81 | $data['project_id'] = get_option( 'mo_firebase_auth_project_id' ); |
| 82 | $data['enable_firebase_login'] = get_option( 'mo_enable_firebase_auth' ); |
| 83 | $data["disable_wp_login"] = get_option( "mo_firebase_auth_disable_wordpress_login" ); |
| 84 | $data["enable_admin_wp_login"] = get_option( "mo_firebase_auth_enable_admin_wp_login" ); |
| 85 | if( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) === 'POST' ) { |
| 86 | $data['log'] = isset( $_POST['log'] ) ? sanitize_text_field( $_POST['log'] ) : ''; |
| 87 | $data['pwd'] = isset( $_POST['pwd'] ) ? sanitize_text_field( $_POST['pwd'] ) : ''; |
| 88 | } |
| 89 | wp_localize_script( 'mo_firebase_app_login_script', 'firebase_data', $data ); |
| 90 | wp_enqueue_script( 'mo_firebase_app_login_script' ); |
| 91 | } |
| 92 | |
| 93 | private function mo_firebase_auth_check_empty_or_null( $value ) { |
| 94 | if( ! isset( $value ) || empty( $value ) ) { |
| 95 | return true; |
| 96 | } |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | private function mo_firebase_auth_contact_us( $email, $phone, $query ) { |
| 101 | global $current_user; |
| 102 | wp_get_current_user(); |
| 103 | $query = '[WP Firebase Authentication Plugin] ' . $query; |
| 104 | $fields = array( |
| 105 | 'firstName' => $current_user->user_firstname, |
| 106 | 'lastName' => $current_user->user_lastname, |
| 107 | 'company' => sanitize_text_field( $_SERVER['SERVER_NAME'] ), |
| 108 | 'email' => $email, |
| 109 | 'ccEmail' => 'oauthsupport@xecurify.com', |
| 110 | 'phone' => $phone, |
| 111 | 'query' => $query |
| 112 | ); |
| 113 | $field_string = json_encode( $fields ); |
| 114 | |
| 115 | $url = 'https://login.xecurify.com/moas/rest/customer/contact-us'; |
| 116 | |
| 117 | $headers = array( |
| 118 | 'Content-Type' => 'application/json', |
| 119 | 'charset' => 'UTF - 8', |
| 120 | 'Authorization' => 'Basic' |
| 121 | ); |
| 122 | $args = array( |
| 123 | 'method' =>'POST', |
| 124 | 'body' => $field_string, |
| 125 | 'timeout' => '5', |
| 126 | 'redirection' => '5', |
| 127 | 'httpversion' => '1.0', |
| 128 | 'blocking' => true, |
| 129 | 'headers' => $headers, |
| 130 | |
| 131 | ); |
| 132 | |
| 133 | $response = wp_remote_post( $url, $args ); |
| 134 | if ( is_wp_error( $response ) ) { |
| 135 | $error_message = $response->get_error_message(); |
| 136 | echo "Something went wrong: $error_message"; |
| 137 | exit(); |
| 138 | } |
| 139 | |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | public function mo_firebase_auth_page() { |
| 144 | if ( isset( $_POST['option'] ) ) { |
| 145 | if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_enable_firebase_auth' && wp_verify_nonce( $_REQUEST['mo_firebase_auth_enable_field'], 'mo_firebase_auth_enable_form' ) ){ |
| 146 | update_option( 'mo_enable_firebase_auth', isset( $_POST['mo_enable_firebase_auth'] ) ? (int)filter_var( $_POST['mo_enable_firebase_auth'], FILTER_SANITIZE_NUMBER_INT ) : 0 ); |
| 147 | } else if ( sanitize_text_field( wp_unslash( $_POST['option'] ) ) == 'mo_firebase_auth_contact_us' && isset($_REQUEST['mo_firebase_auth_contact_us_field']) && wp_verify_nonce( $_REQUEST['mo_firebase_auth_contact_us_field'], 'mo_firebase_auth_contact_us_form' ) ) { |
| 148 | $email = isset( $_POST['mo_firebase_auth_contact_us_email'] ) ? sanitize_email( $_POST['mo_firebase_auth_contact_us_email'] ) : ""; |
| 149 | $phone = "+ ".preg_replace( '/[^0-9]/', '', $_POST['mo_firebase_auth_contact_us_phone'] ); |
| 150 | //$phone = sanitize_textarea_field($_POST['mo_firebase_auth_contact_us_phone']); |
| 151 | $query = isset( $_POST['mo_firebase_auth_contact_us_query'] ) ? sanitize_textarea_field( $_POST['mo_firebase_auth_contact_us_query'] ) : ""; |
| 152 | if ( $this->mo_firebase_auth_check_empty_or_null( $email ) || $this->mo_firebase_auth_check_empty_or_null( $query ) ) { |
| 153 | echo '<br><b style=color:red>Please fill up Email and Query fields to submit your query.</b>'; |
| 154 | } else { |
| 155 | $submited = $this->mo_firebase_auth_contact_us( $email, $phone, $query ); |
| 156 | if ( $submited == false ) { |
| 157 | echo '<br><b style=color:red>Your query could not be submitted. Please try again.</b>'; |
| 158 | } else { |
| 159 | echo '<br><b style=color:green>Thanks for getting in touch! We shall get back to you shortly.</b>'; |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | mo_firebase_auth_page_ui(); |
| 165 | } |
| 166 | |
| 167 | } |
| 168 |