css
4 years ago
fonts
4 years ago
images
4 years ago
js
4 years ago
partials
4 years ago
class-firebase-authentication-admin.php
4 years ago
class-firebase-authentication-customer.php
4 years ago
index.php
4 years ago
class-firebase-authentication-customer.php
212 lines
| 1 | <?php |
| 2 | class MO_Firebase_Customer{ |
| 3 | |
| 4 | public $email; |
| 5 | public $phone; |
| 6 | |
| 7 | private $defaultCustomerKey = "16555"; |
| 8 | private $defaultApiKey = "fFd2XcvTGDemZvbw1bcUesNJWEqKbbUq"; |
| 9 | |
| 10 | function create_customer(){ |
| 11 | $url = get_option('host_name') . '/moas/rest/customer/add'; |
| 12 | $this->email = get_option('mo_firebase_authentication_admin_email'); |
| 13 | $this->phone = get_option('mo_firebase_authentication_admin_phone'); |
| 14 | $password = get_option('password'); |
| 15 | $firstName = get_option('mo_firebase_authentication_admin_fname'); |
| 16 | $lastName = get_option('mo_firebase_authentication_admin_lname'); |
| 17 | $company = get_option('mo_firebase_authentication_admin_company'); |
| 18 | |
| 19 | $fields = array( |
| 20 | 'companyName' => $company, |
| 21 | 'areaOfInterest' => 'WP Firebase Authentication', |
| 22 | 'firstname' => $firstName, |
| 23 | 'lastname' => $lastName, |
| 24 | 'email' => $this->email, |
| 25 | 'phone' => $this->phone, |
| 26 | 'password' => $password |
| 27 | ); |
| 28 | $field_string = json_encode($fields); |
| 29 | $headers = array( 'Content-Type' => 'application/json', 'charset' => 'UTF - 8', 'Authorization' => 'Basic' ); |
| 30 | $args = array( |
| 31 | 'method' =>'POST', |
| 32 | 'body' => $field_string, |
| 33 | 'timeout' => '5', |
| 34 | 'redirection' => '5', |
| 35 | 'httpversion' => '1.0', |
| 36 | 'blocking' => true, |
| 37 | 'headers' => $headers, |
| 38 | |
| 39 | ); |
| 40 | |
| 41 | $response = wp_remote_post( $url, $args ); |
| 42 | if ( is_wp_error( $response ) ) { |
| 43 | $error_message = $response->get_error_message(); |
| 44 | echo "Something went wrong: $error_message"; |
| 45 | exit(); |
| 46 | } |
| 47 | |
| 48 | return wp_remote_retrieve_body($response); |
| 49 | } |
| 50 | |
| 51 | function check_customer() { |
| 52 | $url = get_option('host_name') . "/moas/rest/customer/check-if-exists"; |
| 53 | // $ch = curl_init( $url ); |
| 54 | $email = get_option("mo_firebase_authentication_admin_email"); |
| 55 | |
| 56 | $fields = array( |
| 57 | 'email' => $email, |
| 58 | ); |
| 59 | $field_string = json_encode( $fields ); |
| 60 | $headers = array( 'Content-Type' => 'application/json', 'charset' => 'UTF - 8', 'Authorization' => 'Basic' ); |
| 61 | $args = array( |
| 62 | 'method' =>'POST', |
| 63 | 'body' => $field_string, |
| 64 | 'timeout' => '5', |
| 65 | 'redirection' => '5', |
| 66 | 'httpversion' => '1.0', |
| 67 | 'blocking' => true, |
| 68 | 'headers' => $headers, |
| 69 | ); |
| 70 | |
| 71 | $response = wp_remote_post( $url, $args ); |
| 72 | if ( is_wp_error( $response ) ) { |
| 73 | $error_message = $response->get_error_message(); |
| 74 | echo "Something went wrong: $error_message"; |
| 75 | exit(); |
| 76 | } |
| 77 | |
| 78 | return wp_remote_retrieve_body($response); |
| 79 | } |
| 80 | |
| 81 | function mo_firebase_auth_get_customer_key() { |
| 82 | $url = get_option('host_name') . "/moas/rest/customer/key"; |
| 83 | $email = get_option("mo_firebase_authentication_admin_email"); |
| 84 | |
| 85 | $password = get_option("password"); |
| 86 | |
| 87 | $fields = array( |
| 88 | 'email' => $email, |
| 89 | 'password' => $password |
| 90 | ); |
| 91 | $field_string = json_encode( $fields ); |
| 92 | |
| 93 | $headers = array( 'Content-Type' => 'application/json', 'charset' => 'UTF - 8', 'Authorization' => 'Basic' ); |
| 94 | $args = array( |
| 95 | 'method' =>'POST', |
| 96 | 'body' => $field_string, |
| 97 | 'timeout' => '5', |
| 98 | 'redirection' => '5', |
| 99 | 'httpversion' => '1.0', |
| 100 | 'blocking' => true, |
| 101 | 'headers' => $headers, |
| 102 | |
| 103 | ); |
| 104 | |
| 105 | $response = wp_remote_post( $url, $args ); |
| 106 | if ( is_wp_error( $response ) ) { |
| 107 | $error_message = $response->get_error_message(); |
| 108 | echo "Something went wrong: $error_message"; |
| 109 | exit(); |
| 110 | } |
| 111 | |
| 112 | return wp_remote_retrieve_body($response); |
| 113 | } |
| 114 | |
| 115 | function mo_firebase_authentication_submit_support_request() { |
| 116 | |
| 117 | $url = get_option ( 'host_name' ) . '/moas/api/backupcode/updatestatus'; |
| 118 | $customerKey = get_option('mo_firebase_authentication_admin_customer_key'); |
| 119 | $apiKey = get_option('mo_firebase_authentication_admin_api_key'); |
| 120 | $currentTimeInMillis = round(microtime(true) * 1000); |
| 121 | $currentTimeInMillis = number_format ( $currentTimeInMillis, 0, '', '' ); |
| 122 | $stringToHash = $customerKey . $currentTimeInMillis . $apiKey; |
| 123 | $hashValue = hash("sha512", $stringToHash); |
| 124 | $timestampHeader = "Timestamp: " . $currentTimeInMillis; |
| 125 | $authorizationHeader = "Authorization: " . $hashValue; |
| 126 | $code = mo_firebase_authentication_decrypt(get_option( 'mo_firebase_authentication_lk' )); |
| 127 | $fields = array ( 'code' => $code , 'customerKey' => $customerKey, 'additionalFields' => array('field1' => home_url()) ); |
| 128 | $field_string = json_encode($fields); |
| 129 | |
| 130 | $headers = array( |
| 131 | 'Content-Type' => 'application/json', |
| 132 | 'Customer-Key' => $customerKey, |
| 133 | 'Timestamp' => $currentTimeInMillis, |
| 134 | 'Authorization' => $hashValue, |
| 135 | ); |
| 136 | $args = array( |
| 137 | 'method' =>'POST', |
| 138 | 'body' => $field_string, |
| 139 | 'timeout' => '5', |
| 140 | 'redirection' => '5', |
| 141 | 'httpversion' => '1.0', |
| 142 | 'blocking' => true, |
| 143 | 'headers' => $headers, |
| 144 | |
| 145 | ); |
| 146 | |
| 147 | $response = wp_remote_post( $url, $args ); |
| 148 | if ( is_wp_error( $response ) ) { |
| 149 | $error_message = $response->get_error_message(); |
| 150 | echo "Something went wrong: $error_message"; |
| 151 | exit(); |
| 152 | } |
| 153 | |
| 154 | return wp_remote_retrieve_body($response); |
| 155 | } |
| 156 | |
| 157 | function mo_firebase_auth_XfsZkodsfhHJ( $code ) { |
| 158 | $url = get_option('host_name') . '/moas/api/backupcode/verify'; |
| 159 | $customerKey = get_option('mo_firebase_authentication_admin_customer_key'); |
| 160 | $apiKey = get_option('mo_firebase_authentication_admin_api_key'); |
| 161 | $username = get_option('mo_firebase_authentication_admin_email'); |
| 162 | |
| 163 | /* Current time in milliseconds since midnight, January 1, 1970 UTC. */ |
| 164 | $currentTimeInMillis = round( microtime( true ) * 1000 ); |
| 165 | $currentTimeInMillis = number_format ( $currentTimeInMillis, 0, '', '' ); |
| 166 | |
| 167 | /* Creating the Hash using SHA-512 algorithm */ |
| 168 | $stringToHash = $customerKey . $currentTimeInMillis . $apiKey; |
| 169 | $hashValue = hash("sha512", $stringToHash); |
| 170 | |
| 171 | $customerKeyHeader = "Customer-Key: " . $customerKey; |
| 172 | $timestampHeader = "Timestamp: " . $currentTimeInMillis; |
| 173 | $authorizationHeader = "Authorization: " . $hashValue; |
| 174 | |
| 175 | $fields = array( |
| 176 | 'code' => $code , |
| 177 | 'customerKey' => $customerKey, |
| 178 | 'additionalFields' => array( |
| 179 | 'field1' => site_url() |
| 180 | |
| 181 | ) |
| 182 | ); |
| 183 | $field_string = json_encode($fields); |
| 184 | |
| 185 | $headers = array( |
| 186 | 'Content-Type' => 'application/json', |
| 187 | 'Customer-Key' => $customerKey, |
| 188 | 'Timestamp' => $currentTimeInMillis, |
| 189 | 'Authorization' => $hashValue, |
| 190 | ); |
| 191 | $args = array( |
| 192 | 'method' =>'POST', |
| 193 | 'body' => $field_string, |
| 194 | 'timeout' => '5', |
| 195 | 'redirection' => '5', |
| 196 | 'httpversion' => '1.0', |
| 197 | 'blocking' => true, |
| 198 | 'headers' => $headers, |
| 199 | |
| 200 | ); |
| 201 | |
| 202 | $response = wp_remote_post( $url, $args ); |
| 203 | if ( is_wp_error( $response ) ) { |
| 204 | $error_message = $response->get_error_message(); |
| 205 | echo "Something went wrong: $error_message"; |
| 206 | exit(); |
| 207 | } |
| 208 | |
| 209 | return wp_remote_retrieve_body($response); |
| 210 | } |
| 211 | } |
| 212 | ?> |