| 1 |
<?php |
| 2 |
|
| 3 |
function login_validate() { |
| 4 |
if (isset($_POST['option']) and $_POST['option'] == "ap_user_login") { |
| 5 |
|
| 6 |
$nonce_check = (get_option('nonce_check_on_login') == 'Yes' ? true : false); |
| 7 |
if ($nonce_check) { |
| 8 |
if (!isset($_POST['login_widget_field']) || !wp_verify_nonce($_POST['login_widget_field'], 'login_widget_action')) { |
| 9 |
wp_die(__('Sorry, your nonce did not verify.', 'login-sidebar-widget')); |
| 10 |
exit; |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
global $aperror; |
| 15 |
$lla = new Login_Log_Adds; |
| 16 |
$aperror = new WP_Error; |
| 17 |
|
| 18 |
if ($_POST['userusername'] != "" and $_POST['userpassword'] != "") { |
| 19 |
$creds = array(); |
| 20 |
$creds['user_login'] = sanitize_text_field($_POST['userusername']); |
| 21 |
$creds['user_password'] = $_POST['userpassword']; |
| 22 |
|
| 23 |
if (isset($_POST['remember']) and $_POST['remember'] == "Yes") { |
| 24 |
$remember = true; |
| 25 |
} else { |
| 26 |
$remember = false; |
| 27 |
} |
| 28 |
$creds['remember'] = $remember; |
| 29 |
$user = wp_signon($creds, true); |
| 30 |
if (isset($user->ID) and $user->ID != '') { |
| 31 |
wp_set_auth_cookie($user->ID, $remember); |
| 32 |
$lla->log_add(apply_filters('lwws_log_ip', $_SERVER['REMOTE_ADDR']), 'Login success', date("Y-m-d H:i:s"), 'success'); |
| 33 |
wp_redirect(apply_filters('lwws_login_redirect', sanitize_text_field($_POST['redirect']), $user->ID)); |
| 34 |
exit; |
| 35 |
} else { |
| 36 |
$aperror->add("msg_class", "error_wid_login"); |
| 37 |
$aperror->add("msg", __(get_login_error_message_text($user), 'login-sidebar-widget')); |
| 38 |
do_action('ap_login_log_front', $user); |
| 39 |
} |
| 40 |
} else { |
| 41 |
$aperror->add("msg_class", "error_wid_login"); |
| 42 |
$aperror->add("msg", __('Username or password is empty!', 'login-sidebar-widget')); |
| 43 |
$lla->log_add(apply_filters('lwws_log_ip', $_SERVER['REMOTE_ADDR']), 'Username or password is empty', date("Y-m-d H:i:s"), 'failed'); |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
function forgot_pass_validate() { |
| 49 |
|
| 50 |
if (isset($_GET['key']) && isset($_GET['action']) && sanitize_text_field($_GET['action']) == "reset_pwd") { |
| 51 |
global $wpdb; |
| 52 |
$reset_key = sanitize_text_field($_GET['key']); |
| 53 |
$user_login = sanitize_text_field($_GET['login']); |
| 54 |
$user_data = $wpdb->get_row($wpdb->prepare("SELECT ID, user_login, user_email FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $reset_key, $user_login)); |
| 55 |
|
| 56 |
$login_sidebar_widget_from_email = get_option('login_sidebar_widget_from_email'); |
| 57 |
if ($login_sidebar_widget_from_email == '') { |
| 58 |
$login_sidebar_widget_from_email = 'no-reply@wordpress.com'; |
| 59 |
} |
| 60 |
|
| 61 |
if (!empty($reset_key) && !empty($user_data)) { |
| 62 |
$user_login = $user_data->user_login; |
| 63 |
$user_email = $user_data->user_email; |
| 64 |
|
| 65 |
$new_password = wp_generate_password(7, false); |
| 66 |
wp_set_password($new_password, $user_data->ID); |
| 67 |
//mailing reset details to the user |
| 68 |
$headers = 'From: ' . get_bloginfo('name') . ' <' . $login_sidebar_widget_from_email . '>' . "\r\n"; |
| 69 |
$message = nl2br(get_option('new_password_mail_body')); |
| 70 |
$message = str_replace(array('#site_url#', '#user_name#', '#user_password#'), array(site_url(), $user_login, $new_password), $message); |
| 71 |
$message = stripslashes(html_entity_decode($message)); |
| 72 |
add_filter('wp_mail_content_type', 'lsw_set_html_content_type'); |
| 73 |
if ($message && !wp_mail($user_email, stripslashes(get_option('new_password_mail_subject')), $message, $headers)) { |
| 74 |
wp_die(__('Email failed to send for some unknown reason.', 'login-sidebar-widget')); |
| 75 |
exit; |
| 76 |
} else { |
| 77 |
wp_die(__('New Password successfully sent to your email address.', 'login-sidebar-widget')); |
| 78 |
exit; |
| 79 |
} |
| 80 |
remove_filter('wp_mail_content_type', 'lsw_set_html_content_type'); |
| 81 |
} else { |
| 82 |
wp_die(__('Not a valid key.', 'login-sidebar-widget')); |
| 83 |
exit; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
if (isset($_POST['option']) and sanitize_text_field($_POST['option']) == "ap_forgot_pass") { |
| 88 |
|
| 89 |
if (!isset($_POST['login_widget_field']) || !wp_verify_nonce($_POST['login_widget_field'], 'login_widget_action')) { |
| 90 |
wp_die(__('Sorry, your nonce did not verify.', 'login-sidebar-widget')); |
| 91 |
exit; |
| 92 |
} |
| 93 |
|
| 94 |
global $aperror; |
| 95 |
global $wpdb; |
| 96 |
$aperror = new WP_Error; |
| 97 |
|
| 98 |
$user_login = ''; |
| 99 |
$user_email = ''; |
| 100 |
$msg = ''; |
| 101 |
|
| 102 |
if (empty($_POST['userusername'])) { |
| 103 |
$msg .= __('Email is empty!', 'login-sidebar-widget'); |
| 104 |
} |
| 105 |
|
| 106 |
$user_username = esc_sql(trim(sanitize_text_field($_POST['userusername']))); |
| 107 |
|
| 108 |
$user_data = get_user_by('email', $user_username); |
| 109 |
if (empty($user_data)) { |
| 110 |
$msg .= __('Invalid E-mail address!', 'login-sidebar-widget'); |
| 111 |
} |
| 112 |
|
| 113 |
if (isset($user_data->data->user_login) and isset($user_data->data->user_email)) { |
| 114 |
$user_login = $user_data->data->user_login; |
| 115 |
$user_email = $user_data->data->user_email; |
| 116 |
} |
| 117 |
|
| 118 |
if ($user_email) { |
| 119 |
$key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login)); |
| 120 |
if (empty($key)) { |
| 121 |
$key = wp_generate_password(10, false); |
| 122 |
$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login)); |
| 123 |
} |
| 124 |
|
| 125 |
$login_sidebar_widget_from_email = get_option('login_sidebar_widget_from_email'); |
| 126 |
if ($login_sidebar_widget_from_email == '') { |
| 127 |
$login_sidebar_widget_from_email = 'no-reply@wordpress.com'; |
| 128 |
} |
| 129 |
|
| 130 |
//mailing reset details to the user |
| 131 |
$headers = 'From: ' . get_bloginfo('name') . ' <' . $login_sidebar_widget_from_email . '>' . "\r\n"; |
| 132 |
$resetlink = site_url() . "?action=reset_pwd&key=$key&login=" . rawurlencode($user_login); |
| 133 |
$message = nl2br(get_option('forgot_password_link_mail_body')); |
| 134 |
$message = str_replace(array('#site_url#', '#user_name#', '#resetlink#'), array(site_url(), $user_login, $resetlink), $message); |
| 135 |
$message = stripslashes(html_entity_decode($message)); |
| 136 |
add_filter('wp_mail_content_type', 'lsw_set_html_content_type'); |
| 137 |
|
| 138 |
if (!wp_mail($user_email, stripslashes(get_option('forgot_password_link_mail_subject')), $message, $headers)) { |
| 139 |
$aperror->add("reg_msg_class", "error_wid_login"); |
| 140 |
$aperror->add("reg_error_msg", __('Email failed to send for some unknown reason.', 'login-sidebar-widget')); |
| 141 |
} else { |
| 142 |
$aperror->add("reg_msg_class", "error_wid_login"); |
| 143 |
$aperror->add("reg_error_msg", __('We have just sent you an email with Password reset instructions.', 'login-sidebar-widget')); |
| 144 |
} |
| 145 |
remove_filter('wp_mail_content_type', 'lsw_set_html_content_type'); |
| 146 |
} else { |
| 147 |
$aperror->add("reg_msg_class", "error_wid_login"); |
| 148 |
$aperror->add("reg_error_msg", $msg); |
| 149 |
} |
| 150 |
} |
| 151 |
} |