PluginProbe ʕ •ᴥ•ʔ
Firebase Authentication / 1.0.0
Firebase Authentication v1.0.0
1.7.0 trunk 1.0.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9
firebase-authentication / admin / class-firebase-authentication-admin.php
firebase-authentication / admin Last commit date
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
167 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"] = boolval( get_option( "mo_firebase_auth_disable_wordpress_login" ) );
84 if(sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) === 'POST') {
85 $data['log'] = isset( $_POST['log'] ) ? sanitize_text_field( $_POST['log'] ) : '';
86 $data['pwd'] = isset( $_POST['pwd'] ) ? sanitize_text_field( $_POST['pwd'] ) : '';
87 }
88 wp_localize_script( 'mo_firebase_app_login_script', 'firebase_data', $data );
89 wp_enqueue_script( 'mo_firebase_app_login_script' );
90 }
91
92 private function mo_firebase_auth_check_empty_or_null( $value ) {
93 if( ! isset( $value ) || empty( $value ) ) {
94 return true;
95 }
96 return false;
97 }
98
99 private function mo_firebase_auth_contact_us( $email, $phone, $query ) {
100 global $current_user;
101 wp_get_current_user();
102 $query = '[WP Firebase Authentication Plugin] ' . $query;
103 $fields = array(
104 'firstName' => $current_user->user_firstname,
105 'lastName' => $current_user->user_lastname,
106 'company' => sanitize_text_field( $_SERVER['SERVER_NAME'] ),
107 'email' => $email,
108 'ccEmail' => 'oauthsupport@xecurify.com',
109 'phone' => $phone,
110 'query' => $query
111 );
112 $field_string = json_encode( $fields );
113
114 $url = 'https://login.xecurify.com/moas/rest/customer/contact-us';
115
116 $headers = array(
117 'Content-Type' => 'application/json',
118 'charset' => 'UTF - 8',
119 'Authorization' => 'Basic'
120 );
121 $args = array(
122 'method' =>'POST',
123 'body' => $field_string,
124 'timeout' => '5',
125 'redirection' => '5',
126 'httpversion' => '1.0',
127 'blocking' => true,
128 'headers' => $headers,
129
130 );
131
132 $response = wp_remote_post( $url, $args );
133 if ( is_wp_error( $response ) ) {
134 $error_message = $response->get_error_message();
135 echo "Something went wrong: $error_message";
136 exit();
137 }
138
139 return true;
140 }
141
142 public function mo_firebase_auth_page() {
143 if ( isset( $_POST['option'] ) ) {
144 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' ) ){
145 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 );
146 } 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' ) ) {
147 $email = isset( $_POST['mo_firebase_auth_contact_us_email'] ) ? sanitize_email( $_POST['mo_firebase_auth_contact_us_email'] ) : "";
148 $phone = "+ ".preg_replace( '/[^0-9]/', '', $_POST['mo_firebase_auth_contact_us_phone'] );
149 //$phone = sanitize_textarea_field($_POST['mo_firebase_auth_contact_us_phone']);
150 $query = isset( $_POST['mo_firebase_auth_contact_us_query'] ) ? sanitize_textarea_field( $_POST['mo_firebase_auth_contact_us_query'] ) : "";
151 if ( $this->mo_firebase_auth_check_empty_or_null( $email ) || $this->mo_firebase_auth_check_empty_or_null( $query ) ) {
152 echo '<br><b style=color:red>Please fill up Email and Query fields to submit your query.</b>';
153 } else {
154 $submited = $this->mo_firebase_auth_contact_us( $email, $phone, $query );
155 if ( $submited == false ) {
156 echo '<br><b style=color:red>Your query could not be submitted. Please try again.</b>';
157 } else {
158 echo '<br><b style=color:green>Thanks for getting in touch! We shall get back to you shortly.</b>';
159 }
160 }
161 }
162 }
163 mo_firebase_auth_page_ui();
164 }
165
166 }
167