views
4 days ago
Dashboard.php
5 months ago
EditProfile.php
6 months ago
Login.php
5 months ago
PublicProfile.php
6 months ago
Register.php
6 months ago
User.php
2 months ago
UserController.php
4 months ago
Login.php
581 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace WPDM\User; |
| 5 | |
| 6 | use WPDM\__\__; |
| 7 | use WPDM\__\Crypt; |
| 8 | use WPDM\__\Email; |
| 9 | use WPDM\__\Session; |
| 10 | use WPDM\__\Template; |
| 11 | use WPDM\Form\Form; |
| 12 | |
| 13 | |
| 14 | if(!defined("ABSPATH")) die("Shit happens!"); |
| 15 | |
| 16 | class Login |
| 17 | { |
| 18 | private static $instance; |
| 19 | |
| 20 | public static function getInstance() |
| 21 | { |
| 22 | if (self::$instance === null) { |
| 23 | self::$instance = new self; |
| 24 | } |
| 25 | return self::$instance; |
| 26 | } |
| 27 | |
| 28 | private function __construct() |
| 29 | { |
| 30 | |
| 31 | add_action('init', [$this, 'process']); |
| 32 | |
| 33 | add_action("wp_ajax_nopriv_updatePassword", [$this, 'updatePassword']); |
| 34 | add_action("wp_ajax_nopriv_resetPassword", [$this, 'resetPassword']); |
| 35 | |
| 36 | // Login Form shortcode |
| 37 | add_shortcode('wpdm_login_form', [$this, 'form']); |
| 38 | // Modal Login form trigger button shortcode |
| 39 | add_shortcode('wpdm_modal_login_form', [$this, 'modalLoginFormBtn']); |
| 40 | // Logout url shortcode |
| 41 | add_shortcode('wpdm_logout_url', array($this, 'logoutURLShortcode')); |
| 42 | |
| 43 | //add_filter("login_url", [$this, 'loginURL'], 999999, 3); |
| 44 | //add_filter("logout_url", [$this, 'logoutURL'], 999999, 2); |
| 45 | //add_filter("init", [$this, 'loginURLRedirect']); |
| 46 | add_filter("template_include", [$this, 'interimLogin'], 9999); |
| 47 | add_filter('the_content', array($this, 'validateLoginPage')); |
| 48 | |
| 49 | add_filter('authenticate', [$this, 'verifyLoginEmail'], 999998, 3); |
| 50 | add_filter('authenticate', [$this, 'verifyUserStatus'], 999999, 3); |
| 51 | add_filter('authenticate', [$this, 'reCaptchaVerify'], 999999, 3); |
| 52 | |
| 53 | add_action("login_form", [$this, 'reCaptcha']); |
| 54 | |
| 55 | } |
| 56 | |
| 57 | |
| 58 | function reCpathcaActive() { |
| 59 | $active_captcha = (int)get_option('__wpdm_recaptcha_loginform', 0) === 1 && get_option('_wpdm_recaptcha_secret_key', '') != ''; |
| 60 | $active_captcha = apply_filters("signin_form_captcha", $active_captcha); |
| 61 | return $active_captcha; |
| 62 | } |
| 63 | |
| 64 | function reCaptcha() { |
| 65 | if($this->reCpathcaActive()) { |
| 66 | $form = new Form(['__recap' => [ |
| 67 | 'type' => 'reCaptcha', |
| 68 | 'attrs' => ['name' => '__recap', 'id' => '__recap'], |
| 69 | ]], ['noForm' => true]); |
| 70 | echo $form->render(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | function reCaptchaVerify($user, $user_login, $user_pass) { |
| 76 | if ($this->reCpathcaActive()) { |
| 77 | $ret = wpdm_recaptcha_enterprise_verify(wpdm_query_var('__recap'), 'LOGIN'); |
| 78 | if (!$ret['success']) { |
| 79 | return new \WP_Error( 'recaptcha_failed', __( '<strong>Error:</strong> Captcha verification failed!', 'download-manager' ) ); |
| 80 | } |
| 81 | } |
| 82 | return $user; |
| 83 | } |
| 84 | |
| 85 | function formFields($params = []) |
| 86 | { |
| 87 | $login_data_fields['__phash'] = ['type' => 'hidden', 'attrs' => ['name' => '__phash', 'id' => '__phash', 'value' => Crypt::encrypt($params)]]; |
| 88 | $login_data_fields['log'] = array( |
| 89 | 'label' => __("Login ID", "download-manager"), |
| 90 | 'type' => 'text', |
| 91 | 'attrs' => array('name' => 'wpdm_login[log]', 'id' => 'user_login', 'required' => 'required', 'placeholder' => __('Username or Email', "download-manager")), |
| 92 | ); |
| 93 | $login_data_fields['password'] = array( |
| 94 | 'label' => __("Password", "download-manager"), |
| 95 | 'type' => 'password', |
| 96 | 'attrs' => array('name' => 'wpdm_login[pwd]', 'id' => 'password', 'required' => 'required', 'placeholder' => __("Enter Password", "download-manager"), 'strength' => 0), |
| 97 | ); |
| 98 | /*if (!isset($params['captcha']) || $params['captcha'] === true) { |
| 99 | $show_captcha = (int)get_option('__wpdm_recaptcha_loginform', 0) === 1 && get_option('_wpdm_recaptcha_secret_key', '') != ''; |
| 100 | $show_captcha = apply_filters("signin_form_captcha", $show_captcha); |
| 101 | if ($show_captcha) { |
| 102 | $login_data_fields['__recap'] = array( |
| 103 | 'type' => 'reCaptcha', |
| 104 | 'attrs' => array('name' => '__recap', 'id' => '__recap'), |
| 105 | ); |
| 106 | } |
| 107 | }*/ |
| 108 | $login_data_fields = apply_filters("wpdm_login_form_fields", $login_data_fields); |
| 109 | $form = new Form($login_data_fields, ['name' => 'wpdm_login_form', 'id' => 'wpdm_login_form', 'method' => 'POST', 'action' => '', 'submit_button' => [], 'noForm' => true]); |
| 110 | return $form->render(); |
| 111 | |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @usage Short-code callback function for login form |
| 116 | * @return string |
| 117 | */ |
| 118 | function form($params = array()) |
| 119 | { |
| 120 | |
| 121 | global $current_user; |
| 122 | |
| 123 | if (!isset($params) || !is_array($params)) $params = array(); |
| 124 | |
| 125 | if (isset($params) && is_array($params)) |
| 126 | extract($params); |
| 127 | if (!isset($redirect)) $redirect = get_permalink(get_option('__wpdm_user_dashboard')); |
| 128 | |
| 129 | $_social_only = isset($params['social_only']) && ($params['social_only'] === 'true' || (int)$params['social_only'] === 1) ? true : false; |
| 130 | $_show_captcha = !isset($params['captcha']) || ($params['captcha'] === 'true' || (int)$params['captcha'] === 1) ? true : false; |
| 131 | |
| 132 | if (!isset($regurl)) { |
| 133 | $regurl = get_option('__wpdm_register_url'); |
| 134 | if ($regurl > 0) |
| 135 | $regurl = get_permalink($regurl); |
| 136 | } |
| 137 | $log_redirect = __::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'escs']); |
| 138 | if (isset($params['redirect'])) $log_redirect = wpdm_valueof($params, 'redirect'); |
| 139 | if (isset($_GET['redirect_to'])) $log_redirect = wpdm_query_var('redirect_to'); |
| 140 | $log_redirect = urldecode($log_redirect); |
| 141 | $up = parse_url($log_redirect); |
| 142 | if (isset($up['host']) && $up['host'] != $_SERVER['SERVER_NAME']) $log_redirect = __::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'escs']); |
| 143 | |
| 144 | $log_redirect = wp_validate_redirect($log_redirect, home_url('/')); |
| 145 | |
| 146 | if (!isset($params['logo'])) $params['logo'] = get_site_icon_url(); |
| 147 | |
| 148 | $__wpdm_social_login = get_option('__wpdm_social_login'); |
| 149 | $__wpdm_social_login = is_array($__wpdm_social_login) ? $__wpdm_social_login : array(); |
| 150 | |
| 151 | ob_start(); |
| 152 | |
| 153 | if (is_user_logged_in()) |
| 154 | $template = Template::locate("already-logged-in.php", __DIR__.'/views'); |
| 155 | else { |
| 156 | if (__::query_var('action') === 'lostpassword') |
| 157 | $template = Template::locate('lost-password-form.php', __DIR__.'/views'); |
| 158 | else if (__::query_var('action') === 'rp') { |
| 159 | $template = Template::locate( 'reset-password-form.php', __DIR__ . '/views' ); |
| 160 | } |
| 161 | else |
| 162 | $template = Template::locate('login-form.php', __DIR__.'/views'); |
| 163 | } |
| 164 | |
| 165 | include($template); |
| 166 | |
| 167 | $content = ob_get_clean(); |
| 168 | $content = apply_filters("wpdm_login_form_html", $content); |
| 169 | |
| 170 | return $content; |
| 171 | } |
| 172 | |
| 173 | function process() |
| 174 | { |
| 175 | |
| 176 | global $wp_query, $post, $wpdb; |
| 177 | if (!isset($_POST['wpdm_login'])) return; |
| 178 | |
| 179 | $shortcode_params = Crypt::decrypt(wpdm_query_var('__phash'), true); |
| 180 | |
| 181 | $login_try = (int)Session::get('login_try'); |
| 182 | $login_try++; |
| 183 | Session::set('login_try', $login_try); |
| 184 | |
| 185 | if ($login_try > 30) wp_die("Slow Down!"); |
| 186 | |
| 187 | Session::clear('login_error'); |
| 188 | $creds = array(); |
| 189 | $creds['user_login'] = isset($_POST['wpdm_login']['log']) ? $_POST['wpdm_login']['log'] : ''; |
| 190 | $creds['user_password'] = isset($_POST['wpdm_login']['pwd']) ? $_POST['wpdm_login']['pwd'] : ''; |
| 191 | $creds['remember'] = isset($_POST['rememberme']) ? $_POST['rememberme'] : false; |
| 192 | $user = wp_signon($creds, false); |
| 193 | if (is_wp_error($user)) { |
| 194 | $login_error = $user->get_error_message(); |
| 195 | if (wpdm_is_ajax()) |
| 196 | wp_send_json(array('success' => false, 'message' => $login_error)); |
| 197 | |
| 198 | Session::set('login_error', $login_error); |
| 199 | wp_safe_redirect(wpdm_valueof($_SERVER, 'HTTP_REFERER', home_url('/'))); |
| 200 | die(); |
| 201 | } else { |
| 202 | wp_set_auth_cookie($user->ID); |
| 203 | wp_set_current_user($user->ID); |
| 204 | update_user_meta($user->ID, '__wpdm_last_login_time', time()); |
| 205 | Session::set('login_try', 0); |
| 206 | //do_action('wp_login', $creds['user_login'], $user); |
| 207 | |
| 208 | if (wpdm_is_ajax()) |
| 209 | wp_send_json(array('success' => true, 'message' => __("Success! Redirecting...", "download-manager"))); |
| 210 | |
| 211 | wp_safe_redirect(wpdm_query_var('redirect_to', 'url')); |
| 212 | die(); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Handles password reset request |
| 218 | */ |
| 219 | function resetPassword() |
| 220 | { |
| 221 | if (wpdm_query_var('__wpdm_reset_pass')) { |
| 222 | |
| 223 | if (empty($_POST['user_login'])) { |
| 224 | die('error'); |
| 225 | } elseif (strpos($_POST['user_login'], '@')) { |
| 226 | $user_data = get_user_by('email', trim(wp_unslash($_POST['user_login']))); |
| 227 | if (empty($user_data)) |
| 228 | die('error'); |
| 229 | } else { |
| 230 | $login = trim($_POST['user_login']); |
| 231 | $user_data = get_user_by('login', $login); |
| 232 | } |
| 233 | if (Session::get('__reset_time') && time() - Session::get('__reset_time') < 60) { |
| 234 | echo "toosoon"; |
| 235 | exit; |
| 236 | } |
| 237 | if (!is_object($user_data) || !isset($user_data->user_login)) die('error'); |
| 238 | $user_login = Crypt::encrypt($user_data->user_login); |
| 239 | $user_email = $user_data->user_email; |
| 240 | $key = get_password_reset_key($user_data); |
| 241 | |
| 242 | |
| 243 | $reseturl = add_query_arg(array('action' => 'rp', 'key' => $key, 'login' => $user_login), wpdm_login_url()); |
| 244 | |
| 245 | $params = array('reset_password' => $reseturl, 'to_email' => $user_email); |
| 246 | Email::send('password-reset', $params); |
| 247 | Session::set('__reset_time', time()); |
| 248 | echo 'ok'; |
| 249 | exit; |
| 250 | |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Set new password |
| 256 | * Security: Uses user-specific nonce and blocks admin password resets by default |
| 257 | */ |
| 258 | function updatePassword() |
| 259 | { |
| 260 | $pass = __::query_var('password', 'html'); |
| 261 | if ($pass == '') { |
| 262 | wp_send_json(array('success' => false, 'message' => __('Password cannot be empty.', 'download-manager'))); |
| 263 | } |
| 264 | |
| 265 | // Decrypt user data first |
| 266 | |
| 267 | $login = Crypt::decrypt(__::query_var('login')); |
| 268 | $user = check_password_reset_key(__::query_var('key'), $login); |
| 269 | |
| 270 | if (!is_object($user) || !isset($user->ID)) { |
| 271 | wp_send_json(array('success' => false, 'message' => apply_filters('wpdm_update_password_error', __('Session Expired! Please try again.', 'download-manager')))); |
| 272 | } |
| 273 | |
| 274 | // Verify user-specific nonce (prevents nonce reuse from other pages) |
| 275 | $nonce = wpdm_query_var('__wpdm_update_pass'); |
| 276 | if (!wp_verify_nonce($nonce, 'wpdm_password_reset_' . $user->ID)) { |
| 277 | wp_send_json(array('success' => false, 'message' => __('Security token expired. Please try again.', 'download-manager'))); |
| 278 | } |
| 279 | |
| 280 | // Block admin password resets by default (can be allowed with WPDM_ADMIN_ALLOW_RESET_PASS constant) |
| 281 | if (user_can($user->ID, 'manage_options')) { |
| 282 | if (!defined('WPDM_ADMIN_ALLOW_RESET_PASS') || constant('WPDM_ADMIN_ALLOW_RESET_PASS') !== true) { |
| 283 | wp_send_json(array( |
| 284 | 'success' => false, |
| 285 | 'message' => apply_filters('wpdm_update_password_error', __('Password update is disabled for admin users.', 'download-manager')) |
| 286 | )); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // Verify the user still exists in database |
| 291 | $db_user = get_userdata($user->ID); |
| 292 | if (!$db_user) { |
| 293 | wp_send_json(array('success' => false, 'message' => __('User not found.', 'download-manager'))); |
| 294 | } |
| 295 | |
| 296 | wp_set_current_user($user->ID, $db_user->user_login); |
| 297 | wp_set_auth_cookie($user->ID); |
| 298 | wp_set_password($pass, $user->ID); |
| 299 | wp_send_json(array('success' => true, 'message' => '')); |
| 300 | } |
| 301 | |
| 302 | /** |
| 303 | * Login url |
| 304 | * @param string $redirect |
| 305 | * @return string |
| 306 | */ |
| 307 | function url($redirect = '') |
| 308 | { |
| 309 | $id = get_option('__wpdm_login_url', 0); |
| 310 | if ($id > 0 && function_exists('get_page_link')) { |
| 311 | $page = get_post($id); |
| 312 | if ($page && get_post_type($page) === 'page' && $page->post_status == 'publish') { |
| 313 | $url = get_page_link($page); |
| 314 | //$url = $page->guid; |
| 315 | if ($redirect != '') |
| 316 | $url = add_query_arg(array('redirect_to' => $redirect), $url); |
| 317 | } else $url = wp_login_url($redirect); |
| 318 | } else $url = wp_login_url($redirect); |
| 319 | return $url; |
| 320 | } |
| 321 | |
| 322 | function lostPasswordURL() |
| 323 | { |
| 324 | return add_query_arg(array('action' => 'lostpassword'), $this->url()); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Alter default login url |
| 329 | * @param $login_url |
| 330 | * @param $redirect |
| 331 | * @param $force_reauth |
| 332 | * @return string |
| 333 | */ |
| 334 | function loginURL($login_url, $redirect, $force_reauth) |
| 335 | { |
| 336 | $id = get_option('__wpdm_login_url', 0); |
| 337 | if ($id > 0 && function_exists('get_page_link')) { |
| 338 | $page = get_post($id); |
| 339 | if ($page && $page->post_status == 'publish') { |
| 340 | $url = get_page_link($page); |
| 341 | //$url = $page->guid; |
| 342 | if ($redirect != '') |
| 343 | $url = add_query_arg(array('redirect_to' => urlencode($redirect)), $url); |
| 344 | } else $url = $login_url; |
| 345 | } else $url = $login_url; |
| 346 | return $url; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * @param array $params |
| 351 | * @return false|string |
| 352 | */ |
| 353 | function modalLoginFormBtn($params = array()) |
| 354 | { |
| 355 | if ((int)get_option('__wpdm_modal_login', 0) !== 1) return ""; |
| 356 | $defaults = array('class' => '', 'redirect' => '', 'logo' => '', 'label' => __('Login', 'download-manager'), 'id' => 'wpdmmodalloginbtn'); |
| 357 | $params = shortcode_atts($defaults, $params, 'wpdm_modal_login_form'); |
| 358 | $redirect = isset($params['redirect']) && $params['redirect'] !== '' ? "data-redirect='".esc_attr($params['redirect'])."'" : ''; |
| 359 | $logo = isset($params['logo']) && $params['logo'] !== '' ? "data-logo='".esc_attr($params['logo'])."'" : ''; |
| 360 | ob_start(); |
| 361 | ?> |
| 362 | <div class="w3eden d-inline-block"><a href="#" <?php echo $redirect; ?> <?php echo $logo; ?> type="button" |
| 363 | id="<?php echo esc_attr($params['id']); ?>" class="<?php echo esc_attr($params['class']); ?>" |
| 364 | data-toggle="modal" |
| 365 | data-target="#wpdmloginmodal"><?php echo __::sanitize_var($params['label'], 'kses'); ?></a></div> |
| 366 | <?php |
| 367 | $btncode = ob_get_clean(); |
| 368 | return $btncode; |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Modal login form |
| 373 | * @param array $params |
| 374 | * @return mixed|void |
| 375 | */ |
| 376 | function modalPopupForm($params = array()) |
| 377 | { |
| 378 | |
| 379 | global $current_user; |
| 380 | |
| 381 | if (!isset($params) || !is_array($params)) $params = array(); |
| 382 | |
| 383 | if (isset($params) && is_array($params)) |
| 384 | extract($params); |
| 385 | if (!isset($redirect)) $redirect = get_permalink(get_option('__wpdm_user_dashboard')); |
| 386 | |
| 387 | if (!isset($regurl)) { |
| 388 | $regurl = get_option('__wpdm_register_url'); |
| 389 | if ($regurl > 0) |
| 390 | $regurl = get_permalink($regurl); |
| 391 | } |
| 392 | $log_redirect = __::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'escs']); |
| 393 | if (isset($params['redirect'])) $log_redirect = esc_url($params['redirect']); |
| 394 | if (isset($_GET['redirect_to'])) $log_redirect = esc_url($_GET['redirect_to']); |
| 395 | |
| 396 | $up = parse_url($log_redirect); |
| 397 | if (isset($up['host']) && $up['host'] != $_SERVER['SERVER_NAME']) $log_redirect = __::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'escs']); |
| 398 | |
| 399 | $log_redirect = wp_validate_redirect($log_redirect, home_url('/')); |
| 400 | |
| 401 | if (!isset($params['logo']) || $params['logo'] == '') $params['logo'] = get_site_icon_url(); |
| 402 | |
| 403 | $__wpdm_social_login = get_option('__wpdm_social_login'); |
| 404 | $__wpdm_social_login = is_array($__wpdm_social_login) ? $__wpdm_social_login : array(); |
| 405 | |
| 406 | ob_start(); |
| 407 | //get_option('__wpdm_modal_login', 0) |
| 408 | |
| 409 | include(Template::locate('modal-login-form.php', __DIR__.'/views')); |
| 410 | |
| 411 | $content = ob_get_clean(); |
| 412 | $content = apply_filters("wpdm_login_modal_form_html", $content); |
| 413 | |
| 414 | return $content; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Logout url |
| 419 | * @param $logout_url |
| 420 | * @param $redirect |
| 421 | * @return string|void |
| 422 | */ |
| 423 | function logoutURL($logout_url, $redirect) |
| 424 | { |
| 425 | $id = get_option('__wpdm_login_url', 0); |
| 426 | if(!$id) return $logout_url; |
| 427 | $logout_url = wpdm_logout_url($redirect); |
| 428 | return $logout_url; |
| 429 | } |
| 430 | |
| 431 | function logoutURLShortcode($params) |
| 432 | { |
| 433 | $redirect = isset($params['r']) ? $params['r'] : ''; |
| 434 | return wpdm_logout_url($redirect); |
| 435 | } |
| 436 | |
| 437 | function loginURLRedirect() |
| 438 | { |
| 439 | if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET' && substr_count($_SERVER['REQUEST_URI'], 'wp-login.php') && !wpdm_query_var('skipwpdm', 'int') && wpdm_query_var('action', 'txt') !== 'rp') { |
| 440 | $id = get_option('__wpdm_login_url', 0); |
| 441 | if ($id > 0) { |
| 442 | $page = get_post($id); |
| 443 | if ($page->post_status == 'publish') { |
| 444 | if (is_user_logged_in()) { |
| 445 | wp_redirect(wpdm_user_dashboard_url()); |
| 446 | } else { |
| 447 | wp_redirect(add_query_arg($_GET, $this->url())); |
| 448 | } |
| 449 | die(); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | function interimLogin($template) |
| 456 | { |
| 457 | if (isset($_REQUEST['interim-login']) && !isset($_POST['wpdm_login'])) { |
| 458 | $template = Template::locate('clean.php', __DIR__.'/views'); |
| 459 | } |
| 460 | return $template; |
| 461 | } |
| 462 | |
| 463 | function verifyLoginEmail($user, $user_login, $user_pass) |
| 464 | { |
| 465 | |
| 466 | if((!is_object($user) || get_class($user) !== 'WP_User') && !$user_login) return $user; |
| 467 | |
| 468 | $user_email = null; |
| 469 | if(!is_email($user_login) && !$user) { |
| 470 | $_user = get_user_by('user_login', $user_login); |
| 471 | if($_user) |
| 472 | $user_email = $_user->user_email; |
| 473 | } else if(is_email($user_login)) |
| 474 | $user_email = $user_login; |
| 475 | else if($user && isset($user->user_email)) |
| 476 | $user_email = $user->user_email; |
| 477 | $cusr = $user ?: $_user; |
| 478 | if (is_email($user_email) && !wpdm_verify_email($user_email) && !user_can($cusr, 'manage_options')) { |
| 479 | $user = new \WP_Error(); |
| 480 | $emsg = esc_html(get_option('__wpdm_blocked_domain_msg')); |
| 481 | if (trim($emsg) === '') $emsg = esc_html__('Your email address is blocked!', 'download-manager'); |
| 482 | $user->add('blocked_email', $emsg); |
| 483 | } |
| 484 | return $user; |
| 485 | } |
| 486 | |
| 487 | function verifyUserStatus($user, $user_login, $user_pass) |
| 488 | { |
| 489 | |
| 490 | if((!is_object($user) || get_class($user) !== 'WP_User') && !$user_login) return $user; |
| 491 | |
| 492 | if($user_login && WPDM()->user->requiresApproval() && !WPDM()->user->isApproved($user->ID)) { |
| 493 | $status = WPDM()->user->getStatus($user->ID); |
| 494 | $user = new \WP_Error(); |
| 495 | if($status === 'pending') { |
| 496 | $pemsg = esc_html(get_option('__wpdm_pending_approval_msg')); |
| 497 | if (trim($pemsg) === '') $pemsg = esc_html__('Your signup is pending approval, we shall mail you as soon as your are approved!', 'download-manager'); |
| 498 | $user->add( 'pending_approval', $pemsg ); |
| 499 | } |
| 500 | else if($status === 'suspended') { |
| 501 | $pemsg = esc_html(get_option('__wpdm_suspended_acc_msg')); |
| 502 | if (trim($pemsg) === '') $pemsg = esc_html__('Your account has been suspended, you are not allowed to login!', 'download-manager'); |
| 503 | $user->add( 'pending_approval', $pemsg ); |
| 504 | } |
| 505 | else if($status === 'declined') { |
| 506 | $pdmsg = esc_html(get_option('__wpdm_declined_signup_msg')); |
| 507 | $pdmsg = str_replace("{status}", $status, $pdmsg); |
| 508 | if (trim($pdmsg) === '') $pdmsg = esc_html__("Your signup request was declined, you are not allowed to login!", 'download-manager'); |
| 509 | $user->add( 'pending_approval', $pdmsg ); |
| 510 | } |
| 511 | } |
| 512 | return $user; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * Modal login form |
| 517 | * @param array $params |
| 518 | * @return mixed|void |
| 519 | */ |
| 520 | function modalForm($params = array()) |
| 521 | { |
| 522 | |
| 523 | global $current_user; |
| 524 | |
| 525 | if (!isset($params) || !is_array($params)) $params = array(); |
| 526 | |
| 527 | if (isset($params) && is_array($params)) |
| 528 | extract($params); |
| 529 | if (!isset($redirect)) $redirect = get_permalink(get_option('__wpdm_user_dashboard')); |
| 530 | |
| 531 | if (!isset($regurl)) { |
| 532 | $regurl = get_option('__wpdm_register_url'); |
| 533 | if ($regurl > 0) |
| 534 | $regurl = get_permalink($regurl); |
| 535 | } |
| 536 | $log_redirect = __::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'escs']); |
| 537 | if (isset($params['redirect'])) $log_redirect = esc_url($params['redirect']); |
| 538 | if (isset($_GET['redirect_to'])) $log_redirect = esc_url($_GET['redirect_to']); |
| 539 | |
| 540 | $up = parse_url($log_redirect); |
| 541 | if (isset($up['host']) && $up['host'] != $_SERVER['SERVER_NAME']) $log_redirect = __::valueof($_SERVER, 'REQUEST_URI', ['validate' => 'escs']); |
| 542 | |
| 543 | $log_redirect = wp_validate_redirect($log_redirect, home_url('/')); |
| 544 | |
| 545 | if (!isset($params['logo']) || $params['logo'] == '') $params['logo'] = get_site_icon_url(); |
| 546 | |
| 547 | $__wpdm_social_login = get_option('__wpdm_social_login'); |
| 548 | $__wpdm_social_login = is_array($__wpdm_social_login) ? $__wpdm_social_login : array(); |
| 549 | |
| 550 | ob_start(); |
| 551 | //get_option('__wpdm_modal_login', 0) |
| 552 | |
| 553 | include(Template::locate('modal-login-form.php', __DIR__.'/views')); |
| 554 | |
| 555 | $content = ob_get_clean(); |
| 556 | $content = apply_filters("wpdm_login_modal_form_html", $content); |
| 557 | |
| 558 | return $content; |
| 559 | } |
| 560 | |
| 561 | /** |
| 562 | * If user select a page for login from wpdm setting without login form shortcode on that page, this functional will replace the page content with login form automatically |
| 563 | * @param $content |
| 564 | * @return mixed|string |
| 565 | */ |
| 566 | function validateLoginPage($content) |
| 567 | { |
| 568 | if (is_singular('page')) { |
| 569 | $id = get_option('__wpdm_login_url', 0); |
| 570 | if ($id > 0 && $id == get_the_ID()) { |
| 571 | if (!has_shortcode($content, 'wpdm_login_form') && !has_shortcode($content, 'wpdm_user_dashboard') && !has_shortcode($content, 'wpdm_author_dashboard')) { |
| 572 | $content = $this->form(); |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | return $content; |
| 577 | |
| 578 | } |
| 579 | |
| 580 | } |
| 581 |