| 1 |
<?php |
| 2 |
/** |
| 3 |
* Login register |
| 4 |
* |
| 5 |
* @package wpstream-theme |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* WpStream_Login_Register |
| 10 |
*/ |
| 11 |
class WpStream_Login_Register { |
| 12 |
|
| 13 |
|
| 14 |
/** |
| 15 |
* Facebook status |
| 16 |
* |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
private $facebook_status = 'no'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Google status |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
private $google_status = 'no'; |
| 27 |
|
| 28 |
/** |
| 29 |
* Twitter status |
| 30 |
* |
| 31 |
* @var string |
| 32 |
*/ |
| 33 |
private $twiter_status = 'no'; |
| 34 |
|
| 35 |
/** |
| 36 |
* Enable user pass status |
| 37 |
* |
| 38 |
* @var string |
| 39 |
*/ |
| 40 |
private $enable_user_pass_status = 'yes'; |
| 41 |
|
| 42 |
/** |
| 43 |
* Terms condition lin |
| 44 |
* |
| 45 |
* @var string |
| 46 |
*/ |
| 47 |
private $terms_conditions_link = '#'; |
| 48 |
|
| 49 |
/** |
| 50 |
* Captcha |
| 51 |
* |
| 52 |
* @var string |
| 53 |
*/ |
| 54 |
private $use_captcha = 'yes'; |
| 55 |
|
| 56 |
/** |
| 57 |
* Instance |
| 58 |
* |
| 59 |
* @var null |
| 60 |
*/ |
| 61 |
private static $instance = null; |
| 62 |
|
| 63 |
/** |
| 64 |
* Constructor |
| 65 |
*/ |
| 66 |
private function __construct() { |
| 67 |
// Private constructor to prevent direct instantiation. |
| 68 |
|
| 69 |
add_action( 'wp_ajax_handle_login', array( $this, 'handle_login' ) ); |
| 70 |
add_action( 'wp_ajax_nopriv_handle_login', array( $this, 'handle_login' ) ); |
| 71 |
|
| 72 |
add_action( 'wp_ajax_handle_register', array( $this, 'handle_register' ) ); |
| 73 |
add_action( 'wp_ajax_nopriv_handle_register', array( $this, 'handle_register' ) ); |
| 74 |
|
| 75 |
add_action( 'wp_ajax_handle_forgot_pass', array( $this, 'handle_forgot_pass' ) ); |
| 76 |
add_action( 'wp_ajax_nopriv_handle_forgot_pass', array( $this, 'handle_forgot_pass' ) ); |
| 77 |
|
| 78 |
add_action( 'wp_head', array( $this, 'wpstream_theme_hook_javascript' ) ); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
/** |
| 83 |
* Get instance |
| 84 |
*/ |
| 85 |
public static function get_instance() { |
| 86 |
if ( null === self::$instance ) { |
| 87 |
self::$instance = new self(); |
| 88 |
} |
| 89 |
return self::$instance; |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Javascript hook |
| 94 |
*/ |
| 95 |
public function wpstream_theme_hook_javascript() { |
| 96 |
global $wpdb; |
| 97 |
|
| 98 |
if ( isset( $_GET['key'] ) && isset( $_GET['action'] ) && 'reset_pwd' === $_GET['action'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 99 |
$reset_key = sanitize_text_field( wp_unslash( $_GET['key'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 100 |
|
| 101 |
if ( isset( $_GET['login'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 102 |
$user_login = sanitize_text_field( wp_unslash( $_GET['login'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 103 |
} |
| 104 |
|
| 105 |
$user_data = wp_cache_get( 'user_data_' . $reset_key . '_' . $user_login, 'user_data' ); |
| 106 |
|
| 107 |
if ( false === $user_data ) { |
| 108 |
$user_data = $wpdb->get_row( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 109 |
$wpdb->prepare( |
| 110 |
"SELECT ID, user_login, user_email FROM {$wpdb->users} |
| 111 |
WHERE user_activation_key = %s AND user_login = %s", |
| 112 |
$reset_key, |
| 113 |
$user_login |
| 114 |
) |
| 115 |
); |
| 116 |
|
| 117 |
wp_cache_set( 'user_data_' . $reset_key . '_' . $user_login, $user_data, 'user_data' ); |
| 118 |
} |
| 119 |
|
| 120 |
if ( ! empty( $user_data ) ) { |
| 121 |
$user_login = $user_data->user_login; |
| 122 |
$user_email = $user_data->user_email; |
| 123 |
|
| 124 |
if ( ! empty( $reset_key ) && ! empty( $user_data ) ) { |
| 125 |
$new_password = wp_generate_password( 7, false ); |
| 126 |
wp_set_password( $new_password, $user_data->ID ); |
| 127 |
// mailing the reset details to the user. |
| 128 |
$message = esc_html__( 'Your new password for the account at:', 'hello-wpstream' ) . "\r\n\r\n"; |
| 129 |
$message .= get_bloginfo( 'name' ) . "\r\n\r\n"; |
| 130 |
// translators: Username placeholder in email message. |
| 131 |
$message .= sprintf( esc_html__( 'Username: %s', 'hello-wpstream' ), $user_login ) . "\r\n\r\n"; |
| 132 |
// translators: Password placeholder in email message. |
| 133 |
$message .= sprintf( esc_html__( 'Password: %s', 'hello-wpstream' ), $new_password ) . "\r\n\r\n"; |
| 134 |
$message .= esc_html__( 'You can now login with your new password at: ', 'hello-wpstream' ) . get_option( 'siteurl' ) . '/' . "\r\n\r\n"; |
| 135 |
|
| 136 |
$headers = 'From: ' . wpstream_theme_return_sending_email() . "\r\n" . |
| 137 |
'Reply-To: ' . wpstream_theme_return_sending_email() . "\r\n" . |
| 138 |
'X-Mailer: PHP/' . phpversion(); |
| 139 |
|
| 140 |
$arguments = array( |
| 141 |
'user_pass' => $new_password, |
| 142 |
); |
| 143 |
|
| 144 |
$subject = esc_html__( 'Password Reseted', 'hello-wpstream' ); |
| 145 |
$message = 'Text will be editable from theme admin :your new pass ' . $new_password; |
| 146 |
$email_type = 'html'; |
| 147 |
wpstream_theme_send_emails( $user_email, $subject, $message, $email_type ); |
| 148 |
|
| 149 |
$mess = '<div class="login-alert">' . esc_html__( 'A new password was sent via email!', 'hello-wpstream' ) . '</div>'; |
| 150 |
|
| 151 |
} else { |
| 152 |
exit( 'Not a Valid Key.' ); |
| 153 |
} |
| 154 |
}// end if empty |
| 155 |
|
| 156 |
$mes = '<div class="login_alert_full">' . esc_html__( 'We have just sent you a new password. Please check your email!', 'hello-wpstream' ) . '</div>'; |
| 157 |
print esc_html( $mes ); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Forgot password |
| 163 |
*/ |
| 164 |
public function handle_forgot_pass() { |
| 165 |
check_ajax_referer( 'login_ajax_nonce', 'security' ); |
| 166 |
global $wpdb; |
| 167 |
|
| 168 |
if ( isset( $_POST['forgot_email'] ) ) { |
| 169 |
$forgot_email = sanitize_text_field( wp_unslash( $_POST['forgot_email'] ) ); |
| 170 |
} |
| 171 |
|
| 172 |
if ( '' === $forgot_email ) { |
| 173 |
echo wp_json_encode( |
| 174 |
array( |
| 175 |
'success' => false, |
| 176 |
'message' => esc_html__( |
| 177 |
'Email field is empty!', |
| 178 |
'hello-wpstream' |
| 179 |
), |
| 180 |
) |
| 181 |
); |
| 182 |
wp_die(); |
| 183 |
} |
| 184 |
|
| 185 |
$user_input = trim( $forgot_email ); |
| 186 |
|
| 187 |
if ( strpos( $user_input, '@' ) ) { |
| 188 |
$user_data = get_user_by( 'email', $user_input ); |
| 189 |
if ( empty( $user_data ) || isset( $user_data->caps['administrator'] ) ) { |
| 190 |
echo wp_json_encode( |
| 191 |
array( |
| 192 |
'success' => false, |
| 193 |
'message' => esc_html__( |
| 194 |
'Invalid E-mail address!', |
| 195 |
'hello-wpstream' |
| 196 |
), |
| 197 |
) |
| 198 |
); |
| 199 |
wp_die(); |
| 200 |
} |
| 201 |
} else { |
| 202 |
$user_data = get_user_by( 'login', $user_input ); |
| 203 |
if ( empty( $user_data ) || isset( $user_data->caps['administrator'] ) ) { |
| 204 |
echo wp_json_encode( |
| 205 |
array( |
| 206 |
'success' => false, |
| 207 |
'message' => esc_html__( |
| 208 |
'We did not found a username with this email!', |
| 209 |
'hello-wpstream' |
| 210 |
), |
| 211 |
) |
| 212 |
); |
| 213 |
wp_die(); |
| 214 |
} |
| 215 |
} |
| 216 |
$user_login = $user_data->user_login; |
| 217 |
$user_email = $user_data->user_email; |
| 218 |
|
| 219 |
$key = wp_cache_get( 'user_activation_key_' . $user_login, 'users' ); |
| 220 |
if ( false === $key ) { |
| 221 |
// generate reset key. |
| 222 |
$key = wp_generate_password( 20, false ); |
| 223 |
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $key ), array( 'user_login' => $user_login ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
| 224 |
wp_cache_set( 'user_activation_key_' . $user_login, $key, 'users' ); |
| 225 |
} |
| 226 |
|
| 227 |
$reset_link = $this->wpstream_tg_validate_url() . "action=reset_pwd&key=$key&login=" . rawurlencode( $user_login ); |
| 228 |
|
| 229 |
$subject = esc_html__( 'Password Reset Request', 'hello-wpstream' ); |
| 230 |
$message = 'Text will be editable from theme admin - > your reset link ' . $reset_link; |
| 231 |
$email_type = 'html'; |
| 232 |
wpstream_theme_send_emails( $user_email, $subject, $message, $email_type, $reply_to = '', $extra_headers = '' ); |
| 233 |
|
| 234 |
echo wp_json_encode( |
| 235 |
array( |
| 236 |
'success' => true, |
| 237 |
'message' => esc_html__( |
| 238 |
'We have just sent you an email with Password reset instructions.', |
| 239 |
'hello-wpstream' |
| 240 |
), |
| 241 |
) |
| 242 |
); |
| 243 |
wp_die(); |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Tg validate url |
| 248 |
*/ |
| 249 |
public function wpstream_tg_validate_url() { |
| 250 |
|
| 251 |
$page_url = esc_url( home_url( '/' ) ); |
| 252 |
$urlget = strpos( $page_url, '?' ); |
| 253 |
if ( false === $urlget ) { |
| 254 |
$concate = '?'; |
| 255 |
} else { |
| 256 |
$concate = '&'; |
| 257 |
} |
| 258 |
return $page_url . $concate; |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Handle register |
| 263 |
*/ |
| 264 |
public function handle_register() { |
| 265 |
check_ajax_referer( 'login_ajax_nonce', 'security' ); |
| 266 |
if ( is_user_logged_in() ) { |
| 267 |
echo wp_json_encode( |
| 268 |
array( |
| 269 |
'success' => true, |
| 270 |
'message' => esc_html__( |
| 271 |
'You are already logged in! redirecting...', |
| 272 |
'hello-wpstream' |
| 273 |
), |
| 274 |
) |
| 275 |
); |
| 276 |
wp_die(); |
| 277 |
} |
| 278 |
|
| 279 |
$use_captcha = 'no'; |
| 280 |
if ( 'yes' === $use_captcha ) { |
| 281 |
if ( ! isset( $_POST['captcha'] ) || '' === $_POST['captcha'] ) { |
| 282 |
|
| 283 |
echo wp_json_encode( |
| 284 |
array( |
| 285 |
'success' => false, |
| 286 |
'message' => esc_html__( 'Wrong captcha', 'hello-wpstream' ), |
| 287 |
) |
| 288 |
); |
| 289 |
wp_die(); |
| 290 |
} |
| 291 |
|
| 292 |
$secret = 'from optpms'; |
| 293 |
$cappval = sanitize_text_field( wp_unslash( $_POST['captcha'] ) ); |
| 294 |
$response = $this->wpstream_theme_return_recapthca( $secret, $cappval ); |
| 295 |
|
| 296 |
if ( false === $response['success'] ) { |
| 297 |
echo wp_json_encode( |
| 298 |
array( |
| 299 |
'register' => false, |
| 300 |
'message' => esc_html__( 'Captcha Invalidated - Refresh and try again.', 'hello-wpstream' ), |
| 301 |
) |
| 302 |
); |
| 303 |
wp_die(); |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
if ( isset( $_POST['user_email_register'] ) ) { |
| 308 |
$user_email = trim( sanitize_text_field( wp_unslash( $_POST['user_email_register'] ) ) ); |
| 309 |
} |
| 310 |
|
| 311 |
if ( isset( $_POST['user_login_register'] ) ) { |
| 312 |
$user_name = trim( sanitize_text_field( wp_unslash( $_POST['user_login_register'] ) ) ); |
| 313 |
} |
| 314 |
|
| 315 |
$enable_user_pass_status = 'yes'; |
| 316 |
|
| 317 |
if ( preg_match( '/^[0-9A-Za-z_]+$/', $user_name ) === 0 ) { |
| 318 |
echo wp_json_encode( |
| 319 |
array( |
| 320 |
'success' => false, |
| 321 |
'message' => esc_html__( 'Invalid username (do not use special characters or spaces)!', 'hello-wpstream' ), |
| 322 |
) |
| 323 |
); |
| 324 |
wp_die(); |
| 325 |
} |
| 326 |
|
| 327 |
if ( '' === $user_email || '' === $user_name ) { |
| 328 |
echo wp_json_encode( |
| 329 |
array( |
| 330 |
'success' => false, |
| 331 |
'message' => esc_html__( 'Username and/or Email field is empty!', 'hello-wpstream' ), |
| 332 |
) |
| 333 |
); |
| 334 |
wp_die(); |
| 335 |
} |
| 336 |
|
| 337 |
if ( filter_var( $user_email, FILTER_VALIDATE_EMAIL ) === false ) { |
| 338 |
echo wp_json_encode( |
| 339 |
array( |
| 340 |
'success' => false, |
| 341 |
'message' => esc_html__( 'The email doesn\'t look right !', 'hello-wpstream' ), |
| 342 |
) |
| 343 |
); |
| 344 |
wp_die(); |
| 345 |
} |
| 346 |
|
| 347 |
$domain = mb_substr( strrchr( $user_email, '@' ), 1 ); |
| 348 |
if ( '' !== $domain && ! checkdnsrr( $domain ) ) { |
| 349 |
echo wp_json_encode( |
| 350 |
array( |
| 351 |
'success' => false, |
| 352 |
'message' => esc_html__( 'The email\'s domain doesn\'t look right.', 'hello-wpstream' ), |
| 353 |
) |
| 354 |
); |
| 355 |
wp_die(); |
| 356 |
} |
| 357 |
|
| 358 |
$user_id = username_exists( $user_name ); |
| 359 |
if ( $user_id ) { |
| 360 |
echo wp_json_encode( |
| 361 |
array( |
| 362 |
'success' => false, |
| 363 |
'message' => esc_html__( 'Username already exists. Please choose a new one.', 'hello-wpstream' ), |
| 364 |
) |
| 365 |
); |
| 366 |
wp_die(); |
| 367 |
} |
| 368 |
|
| 369 |
if ( 'yes' === $enable_user_pass_status ) { |
| 370 |
if ( isset( $_POST['user_pass'] ) ) { |
| 371 |
$user_pass = trim( sanitize_text_field( wp_unslash( $_POST['user_pass'] ) ) ); |
| 372 |
} |
| 373 |
|
| 374 |
if ( isset( $_POST['user_pass_retype'] ) ) { |
| 375 |
$user_pass_retype = trim( sanitize_text_field( wp_unslash( $_POST['user_pass_retype'] ) ) ); |
| 376 |
} |
| 377 |
|
| 378 |
if ( '' === $user_pass || '' === $user_pass_retype ) { |
| 379 |
echo wp_json_encode( |
| 380 |
array( |
| 381 |
'success' => false, |
| 382 |
'message' => esc_html__( 'One of the password field is empty!', 'hello-wpstream' ), |
| 383 |
) |
| 384 |
); |
| 385 |
wp_die(); |
| 386 |
} |
| 387 |
|
| 388 |
if ( $user_pass !== $user_pass_retype ) { |
| 389 |
echo wp_json_encode( |
| 390 |
array( |
| 391 |
'success' => false, |
| 392 |
'message' => esc_html__( 'Passwords do not match', 'hello-wpstream' ), |
| 393 |
) |
| 394 |
); |
| 395 |
wp_die(); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
if ( ! $user_id && email_exists( $user_email ) === false ) { |
| 400 |
if ( 'yes' === $enable_user_pass_status ) { |
| 401 |
$user_password = $user_pass; // no so random now!. |
| 402 |
} else { |
| 403 |
$user_password = wp_generate_password( $length = 12, $include_standard_special_chars = false ); //phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found |
| 404 |
} |
| 405 |
|
| 406 |
$user_id = wp_create_user( $user_name, $user_password, $user_email ); |
| 407 |
|
| 408 |
if ( is_wp_error( $user_id ) ) { |
| 409 |
echo wp_json_encode( |
| 410 |
array( |
| 411 |
'success' => false, |
| 412 |
'message' => esc_html__( 'Something went wrong. Please try again or check with site administrator!', 'hello-wpstream' ), |
| 413 |
) |
| 414 |
); |
| 415 |
wp_die(); |
| 416 |
} elseif ( 'yes' === $enable_user_pass_status ) { |
| 417 |
echo wp_json_encode( |
| 418 |
array( |
| 419 |
'success' => true, |
| 420 |
'message' => esc_html__( 'Your account was created and you can login now!', 'hello-wpstream' ), |
| 421 |
) |
| 422 |
); |
| 423 |
wp_die(); |
| 424 |
} else { |
| 425 |
echo wp_json_encode( |
| 426 |
array( |
| 427 |
'success' => true, |
| 428 |
'message' => esc_html__( 'An email with the generated password was sent!', 'hello-wpstream' ), |
| 429 |
) |
| 430 |
); |
| 431 |
wp_die(); |
| 432 |
} |
| 433 |
} else { |
| 434 |
|
| 435 |
echo wp_json_encode( |
| 436 |
array( |
| 437 |
'register' => false, |
| 438 |
'message' => esc_html__( 'Email already exists. Please choose a new one.', 'hello-wpstream' ), |
| 439 |
) |
| 440 |
); |
| 441 |
wp_die(); |
| 442 |
} |
| 443 |
|
| 444 |
wp_die(); |
| 445 |
} |
| 446 |
|
| 447 |
/** |
| 448 |
* Return reCAPTCHA verification result. |
| 449 |
* |
| 450 |
* @param string $secret The secret key for reCAPTCHA. |
| 451 |
* @param string $captcha The reCAPTCHA response from the user. |
| 452 |
* @return array|null Returns an array containing the verification result or null on failure. |
| 453 |
*/ |
| 454 |
public function wpstream_theme_return_recapthca( $secret, $captcha ) { |
| 455 |
$remoteip = sanitize_text_field( wp_unslash( wpstream_get_ip_address() ) ); |
| 456 |
|
| 457 |
$url = 'https://www.google.com/recaptcha/api/siteverify'; |
| 458 |
$post_data = http_build_query( |
| 459 |
array( |
| 460 |
'secret' => $secret, |
| 461 |
'response' => $captcha, |
| 462 |
'remoteip' => $remoteip, |
| 463 |
), |
| 464 |
'', |
| 465 |
'&' |
| 466 |
); |
| 467 |
|
| 468 |
$response = wp_safe_remote_post( |
| 469 |
$url, |
| 470 |
array( |
| 471 |
'body' => $post_data, |
| 472 |
'headers' => array( |
| 473 |
'Content-Type' => 'application/x-www-form-urlencoded', |
| 474 |
), |
| 475 |
) |
| 476 |
); |
| 477 |
|
| 478 |
if ( is_wp_error( $response ) ) { |
| 479 |
return array( 'success' => false, 'error' => $response->get_error_message() ); |
| 480 |
} |
| 481 |
|
| 482 |
$response_body = wp_remote_retrieve_body( $response ); |
| 483 |
$resulting = json_decode( $response_body, true ); |
| 484 |
|
| 485 |
return $resulting; |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
// This function checks multiple server variables for the IP address and validates it, providing a more robust and secure way to get the user's IP address. |
| 492 |
public function wpstream_get_ip_address() { |
| 493 |
$ip_keys = array( |
| 494 |
'HTTP_CLIENT_IP', |
| 495 |
'HTTP_X_FORWARDED_FOR', |
| 496 |
'HTTP_X_FORWARDED', |
| 497 |
'HTTP_X_CLUSTER_CLIENT_IP', |
| 498 |
'HTTP_FORWARDED_FOR', |
| 499 |
'HTTP_FORWARDED', |
| 500 |
'REMOTE_ADDR' |
| 501 |
); |
| 502 |
|
| 503 |
foreach ($ip_keys as $key) { |
| 504 |
if (array_key_exists($key, $_SERVER) === true) { |
| 505 |
foreach (explode(',', $_SERVER[$key]) as $ip) { |
| 506 |
$ip = trim($ip); |
| 507 |
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { |
| 508 |
return $ip; |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
return ''; // If no valid IP is found |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
/** |
| 522 |
* Handle login |
| 523 |
*/ |
| 524 |
public function handle_login() { |
| 525 |
check_ajax_referer( 'login_ajax_nonce', 'security' ); |
| 526 |
if ( is_user_logged_in() ) { |
| 527 |
echo wp_json_encode( |
| 528 |
array( |
| 529 |
'success' => true, |
| 530 |
'message' => esc_html__( |
| 531 |
'You are already logged in! redirecting...', |
| 532 |
'hello-wpstream' |
| 533 |
), |
| 534 |
) |
| 535 |
); |
| 536 |
wp_die(); |
| 537 |
} |
| 538 |
|
| 539 |
if ( isset( $_POST['login_user'] ) ) { |
| 540 |
$login_user = sanitize_text_field( wp_unslash( $_POST['login_user'] ) ); |
| 541 |
} |
| 542 |
|
| 543 |
if ( isset( $_POST['login_pwd'] ) ) { |
| 544 |
$login_pwd = sanitize_text_field( wp_unslash( $_POST['login_pwd'] ) ); |
| 545 |
} |
| 546 |
|
| 547 |
if ( isset( $_POST['ispop'] ) ) { |
| 548 |
$ispop = intval( $_POST['ispop'] ); |
| 549 |
} |
| 550 |
|
| 551 |
if ( '' === $login_user || '' === $login_pwd ) { |
| 552 |
echo wp_json_encode( |
| 553 |
array( |
| 554 |
'success' => false, |
| 555 |
'message' => esc_html__( |
| 556 |
'Username and/or Password field is empty!', |
| 557 |
'hello-wpstream' |
| 558 |
), |
| 559 |
) |
| 560 |
); |
| 561 |
wp_die(); |
| 562 |
} |
| 563 |
|
| 564 |
$vsessionid = session_id(); |
| 565 |
if ( empty( $vsessionid ) ) { |
| 566 |
session_name( 'PHPSESSID' ); |
| 567 |
session_start(); |
| 568 |
} |
| 569 |
|
| 570 |
wp_clear_auth_cookie(); |
| 571 |
$info = array(); |
| 572 |
$info['user_login'] = $login_user; |
| 573 |
$info['user_password'] = $login_pwd; |
| 574 |
$info['remember'] = false; |
| 575 |
$user_signon = wp_signon( $info, true ); |
| 576 |
|
| 577 |
if ( is_wp_error( $user_signon ) ) { |
| 578 |
echo wp_json_encode( |
| 579 |
array( |
| 580 |
'success' => false, |
| 581 |
'message' => esc_html__( |
| 582 |
'Wrong username or password!', |
| 583 |
'hello-wpstream' |
| 584 |
), |
| 585 |
) |
| 586 |
); |
| 587 |
} else { |
| 588 |
wp_set_current_user( $user_signon->ID ); |
| 589 |
do_action( 'set_current_user' ); |
| 590 |
wp_get_current_user(); |
| 591 |
echo wp_json_encode( |
| 592 |
array( |
| 593 |
'success' => true, |
| 594 |
'ispop' => $ispop, |
| 595 |
'newuser' => $user_signon->ID, |
| 596 |
'message' => esc_html__( 'Login successful, redirecting...', 'hello-wpstream' ), |
| 597 |
) |
| 598 |
); |
| 599 |
|
| 600 |
} |
| 601 |
|
| 602 |
wp_die(); |
| 603 |
} |
| 604 |
|
| 605 |
/** |
| 606 |
* Generate login register forgot form |
| 607 |
*/ |
| 608 |
public function generate_login_register_forgot_form() { |
| 609 |
$retun_string = '<div class="login_register_forgot_wrapper">'; |
| 610 |
$retun_string .= $this->generate_login_form(); |
| 611 |
$retun_string .= $this->generate_register_form(); |
| 612 |
$retun_string .= $this->generate_forgot_form(); |
| 613 |
$retun_string .= '<input type="hidden" class="wpstream-theme_security-login-topbar" name="security-login-topbar" value="' . wp_create_nonce( 'login_ajax_nonce' ) . '">'; |
| 614 |
$retun_string .= '</div>'; |
| 615 |
|
| 616 |
return $retun_string; |
| 617 |
} |
| 618 |
|
| 619 |
/** |
| 620 |
* Section controls |
| 621 |
*/ |
| 622 |
private function section_controls() { |
| 623 |
$display_string = ''; |
| 624 |
ob_start(); |
| 625 |
?> |
| 626 |
<div class="login_sections_control"> |
| 627 |
<div class="wpstream-theme_register_link"><?php esc_html_e( 'Register here!', 'hello-wpstream' ); ?></div> |
| 628 |
<div class="wpstream-theme_forgot_pass_link"><?php esc_html_e( 'Forgot password?', 'hello-wpstream' ); ?></div> |
| 629 |
<div class="wpstream-theme_login_link"><?php esc_html_e( 'Back to login', 'hello-wpstream' ); ?></div> |
| 630 |
|
| 631 |
<input type="hidden" name="loginpop" id="loginpop" value="0"> |
| 632 |
</div> |
| 633 |
<?php |
| 634 |
$display_string = ob_get_contents(); |
| 635 |
ob_end_clean(); |
| 636 |
return $display_string; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
/** |
| 641 |
* Login form |
| 642 |
*/ |
| 643 |
private function generate_login_form() { |
| 644 |
|
| 645 |
$display_string = ''; |
| 646 |
ob_start(); |
| 647 |
?> |
| 648 |
<div class="wpstream-theme_login_form"> |
| 649 |
<span class="h5 offcanvas-title wpstream-offcanvas-title"><?php esc_html_e( 'Log In to WpStream', 'hello-wpstream' ); ?></span> |
| 650 |
|
| 651 |
<div class="wpstream-theme_login-div-title-topbar"> |
| 652 |
<?php esc_html_e( 'Don’t have an account yet?', 'hello-wpstream' ); ?> |
| 653 |
|
| 654 |
<div class="wpstream-theme_register_link"><?php esc_html_e( 'Sign Up for free', 'hello-wpstream' ); ?></div> |
| 655 |
</div> |
| 656 |
|
| 657 |
<div class="wpstream-theme_login_alert"></div> |
| 658 |
|
| 659 |
<input type="text" class="form-control wpstream-theme_login_user" name="log" |
| 660 |
autofocus |
| 661 |
placeholder="<?php esc_attr_e( 'Username', 'hello-wpstream' ); ?>"/> |
| 662 |
|
| 663 |
<div class="password_holder"> |
| 664 |
<input type="password" class="form-control wpstream-theme_login_pwd" |
| 665 |
name="pwd" |
| 666 |
placeholder="<?php esc_attr_e( 'Password', 'hello-wpstream' ); ?>"/> |
| 667 |
<div class="show_hide_password hide"> |
| 668 |
<i class=" far fa-eye-slash "></i> |
| 669 |
</div> |
| 670 |
</div> |
| 671 |
<input type="hidden" name="loginpop" id="loginpop_wd" value="0"> |
| 672 |
|
| 673 |
<div class="wpstream-theme_forgot_pass_link_wrap"> |
| 674 |
<div class="wpstream-theme_forgot_pass_link"><?php esc_html_e( 'Forgot password?', 'hello-wpstream' ); ?></div> |
| 675 |
</div> |
| 676 |
|
| 677 |
<button class="wpstream_submit_button wpstream-theme_wp_login_button"> |
| 678 |
<?php esc_html_e( 'Login', 'hello-wpstream' ); ?> |
| 679 |
</button> |
| 680 |
|
| 681 |
<div class="login-links"> |
| 682 |
|
| 683 |
<?php |
| 684 |
if ( 'yes' === $this->facebook_status || 'yes' === $this->google_status || 'yes' === $this->twiter_status ) { |
| 685 |
echo '<div class="or_social">' . esc_html__( 'or', 'hello-wpstream' ) . '</div>'; |
| 686 |
if ( class_exists( 'wpstream_theme_Social_Login' ) ) { |
| 687 |
global $wpstream_theme_social_login; |
| 688 |
$wpstream_theme_social_login->display_form( 'topbar', 0 ); |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
?> |
| 693 |
</div> |
| 694 |
</div> |
| 695 |
|
| 696 |
<?php |
| 697 |
|
| 698 |
$display_string = ob_get_contents(); |
| 699 |
ob_end_clean(); |
| 700 |
return $display_string; |
| 701 |
} |
| 702 |
|
| 703 |
/** |
| 704 |
* Register form |
| 705 |
*/ |
| 706 |
public function generate_register_form() { |
| 707 |
|
| 708 |
$display_string = ''; |
| 709 |
ob_start(); |
| 710 |
?> |
| 711 |
|
| 712 |
<div class="wpstream-theme_register_form"> |
| 713 |
<span class="h5 offcanvas-title wpstream-offcanvas-title"><?php esc_html_e( 'Create an Account', 'hello-wpstream' ); ?></span> |
| 714 |
|
| 715 |
<div class="wpstream-theme_register-div-title"> |
| 716 |
<?php esc_html_e( 'Have an account?', 'hello-wpstream' ); ?> |
| 717 |
<div class="wpstream-theme_login_link"><?php esc_html_e( 'Log in', 'hello-wpstream' ); ?></div> |
| 718 |
</div> |
| 719 |
|
| 720 |
<div class="wpstream-theme_register_alert"></div> |
| 721 |
|
| 722 |
<input type="text" name="user_login_register" |
| 723 |
class="form-control wpstream-theme_user_login_register" |
| 724 |
autofocus placeholder="<?php esc_attr_e( 'Username', 'hello-wpstream' ); ?>"/> |
| 725 |
<input type="email" name="user_email_register" |
| 726 |
class="form-control wpstream-theme_user_email_register" |
| 727 |
placeholder="<?php esc_attr_e( 'Email', 'hello-wpstream' ); ?>"/> |
| 728 |
|
| 729 |
<?php |
| 730 |
|
| 731 |
if ( 'yes' === $this->enable_user_pass_status ) { |
| 732 |
?> |
| 733 |
<div class="password_holder"> |
| 734 |
<input type="password" name="user_password" |
| 735 |
class="wpstream-theme_user_password form-control" |
| 736 |
placeholder="<?php esc_attr_e( 'Password', 'hello-wpstream' ); ?>"/> |
| 737 |
|
| 738 |
<div class="show_hide_password hide"> |
| 739 |
<i class=" far fa-eye-slash "></i> |
| 740 |
</div> |
| 741 |
</div> |
| 742 |
|
| 743 |
<div class="password_holder"> |
| 744 |
<input type="password" name="user_password_retype" |
| 745 |
class="wpstream-theme_user_password_retype form-control" |
| 746 |
placeholder="<?php esc_attr_e( 'Retype Password', 'hello-wpstream' ); ?>"/> |
| 747 |
|
| 748 |
<div class="show_hide_password hide"> |
| 749 |
<i class=" far fa-eye-slash "></i> |
| 750 |
</div> |
| 751 |
</div> |
| 752 |
|
| 753 |
<?php |
| 754 |
} |
| 755 |
?> |
| 756 |
|
| 757 |
|
| 758 |
<input type="checkbox" name="terms" class="wpstream-theme_user_terms_register"/> |
| 759 |
<label id="user_terms_register_label" for="wpstream-theme_user_terms_register"> |
| 760 |
<?php esc_html_e( 'I agree with ', 'hello-wpstream' ); ?> |
| 761 |
<a href="<?php print esc_url( $this->terms_conditions_link ); ?>" target="_blank" |
| 762 |
class="wpstream-theme_user_terms_register_link"> |
| 763 |
<?php esc_html_e( 'terms & conditions', 'hello-wpstream' ); ?> |
| 764 |
</a> |
| 765 |
</label> |
| 766 |
|
| 767 |
<?php |
| 768 |
if ( 'yes' === $this->use_captcha ) { |
| 769 |
print '<div id="top_register_menu" style="float:left;transform:scale(0.75);-webkit-transform:scale(0.75);transform-origin:0 0;-webkit-transform-origin:0 0;"></div>'; |
| 770 |
} |
| 771 |
?> |
| 772 |
|
| 773 |
<?php if ( 'yes' !== $this->enable_user_pass_status ) { ?> |
| 774 |
<p id="reg_passmail"><?php esc_html_e( 'A password will be e-mailed to you', 'hello-wpstream' ); ?></p> |
| 775 |
<?php } ?> |
| 776 |
|
| 777 |
<button class="wpstream_submit_button wpstream-theme_wp_register_button"> |
| 778 |
<?php esc_html_e( 'Register', 'hello-wpstream' ); ?> |
| 779 |
</button> |
| 780 |
|
| 781 |
</div> |
| 782 |
|
| 783 |
<?php |
| 784 |
$display_string = ob_get_contents(); |
| 785 |
ob_end_clean(); |
| 786 |
return $display_string; |
| 787 |
} |
| 788 |
|
| 789 |
/** |
| 790 |
* Forgot form |
| 791 |
*/ |
| 792 |
public function generate_forgot_form() { |
| 793 |
$display_string = ''; |
| 794 |
ob_start(); |
| 795 |
?> |
| 796 |
|
| 797 |
|
| 798 |
<div class="wpstream-theme_forgot_form"> |
| 799 |
<span class="h5 offcanvas-title wpstream-offcanvas-title"><?php esc_html_e( 'Reset Password', 'hello-wpstream' ); ?></span> |
| 800 |
|
| 801 |
<div class="wpstream-theme_forgot-div-title"> |
| 802 |
<?php esc_html_e( 'Back to', 'hello-wpstream' ); ?> |
| 803 |
<div class="wpstream-theme_login_link"><?php esc_html_e( 'Log in', 'hello-wpstream' ); ?></div> |
| 804 |
</div> |
| 805 |
|
| 806 |
<div class="wpstream-theme_forgot_alert"></div> |
| 807 |
|
| 808 |
<input type="email" class="form-control wpstream-theme_forgot_email" |
| 809 |
name="forgot_email" |
| 810 |
autofocus placeholder="<?php esc_attr_e( 'Enter Your Email Address', 'hello-wpstream' ); ?>" |
| 811 |
size="20"/> |
| 812 |
|
| 813 |
<input type="hidden" class="wpstream-theme_forgot_email_postid" value=" |
| 814 |
<?php |
| 815 |
if ( isset( $post->ID ) ) { |
| 816 |
echo intval( $post->ID ); |
| 817 |
} |
| 818 |
?> |
| 819 |
"> |
| 820 |
|
| 821 |
<button class="wpstream_submit_button wpstream-theme_wp_forgot_button"> |
| 822 |
<?php esc_html_e( 'Reset Password', 'hello-wpstream' ); ?> |
| 823 |
</button> |
| 824 |
</div> |
| 825 |
|
| 826 |
<?php |
| 827 |
$display_string = ob_get_contents(); |
| 828 |
ob_end_clean(); |
| 829 |
return $display_string; |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
global $login_register_object; |
| 834 |
$login_register_object = WpStream_Login_Register::get_instance(); |
| 835 |
|