Ejemplo n.º 1
0
/**
 * Process Login Form
 *
 * @since 1.0
 *
 * @param array $data Data sent from the login form
 *
 * @return void
 */
function give_process_login_form($data)
{
    if (wp_verify_nonce($data['give_login_nonce'], 'give-login-nonce')) {
        $user_data = get_user_by('login', $data['give_user_login']);
        if (!$user_data) {
            $user_data = get_user_by('email', $data['give_user_login']);
        }
        if ($user_data) {
            $user_ID = $user_data->ID;
            $user_email = $user_data->user_email;
            if (wp_check_password($data['give_user_pass'], $user_data->user_pass, $user_data->ID)) {
                give_log_user_in($user_data->ID, $data['give_user_login'], $data['give_user_pass']);
            } else {
                give_set_error('password_incorrect', __('The password you entered is incorrect', 'give'));
            }
        } else {
            give_set_error('username_incorrect', __('The username you entered does not exist', 'give'));
        }
        // Check for errors and redirect if none present
        $errors = give_get_errors();
        if (!$errors) {
            $redirect = apply_filters('give_login_redirect', $data['give_redirect'], $user_ID);
            wp_redirect($redirect);
            give_die();
        }
    }
}
Ejemplo n.º 2
0
 /**
  * Test that the give_log_user_in() function successfully logs the user in.
  *
  * @since 1.3.2
  */
 public function test_log_user_in_return()
 {
     $this->assertNull(give_log_user_in(0, '', ''));
 }
Ejemplo n.º 3
0
/**
 * Get Purchase Form User
 *
 * @param array $valid_data
 *
 * @access  private
 * @since   1.0
 * @return  array
 */
function give_get_purchase_form_user($valid_data = array())
{
    // Initialize user
    $user = false;
    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
    if ($is_ajax) {
        // Do not create or login the user during the ajax submission (check for errors only)
        return true;
    } else {
        if (is_user_logged_in()) {
            // Set the valid user as the logged in collected data
            $user = $valid_data['logged_in_user'];
        } else {
            if ($valid_data['need_new_user'] === true || $valid_data['need_user_login'] === true) {
                // New user registration
                if ($valid_data['need_new_user'] === true) {
                    // Set user
                    $user = $valid_data['new_user_data'];
                    // Register and login new user
                    $user['user_id'] = give_register_and_login_new_user($user);
                    // User login
                } else {
                    if ($valid_data['need_user_login'] === true && !$is_ajax) {
                        /*
                         * The login form is now processed in the give_process_purchase_login() function.
                         * This is still here for backwards compatibility.
                         * This also allows the old login process to still work if a user removes the
                         * checkout login submit button.
                         *
                         * This also ensures that the donor is logged in correctly if they click "Purchase"
                         * instead of submitting the login form, meaning the donor is logged in during the purchase process.
                         */
                        // Set user
                        $user = $valid_data['login_user_data'];
                        // Login user
                        give_log_user_in($user['user_id'], $user['user_login'], $user['user_pass']);
                    }
                }
            }
        }
    }
    // Check guest checkout
    if (false === $user && false === give_logged_in_only($_POST['give-form-id'])) {
        // Set user
        $user = $valid_data['guest_user_data'];
    }
    // Verify we have an user
    if (false === $user || empty($user)) {
        // Return false
        return false;
    }
    // Get user first name
    if (!isset($user['user_first']) || strlen(trim($user['user_first'])) < 1) {
        $user['user_first'] = isset($_POST['give_first']) ? strip_tags(trim($_POST['give_first'])) : '';
    }
    // Get user last name
    if (!isset($user['user_last']) || strlen(trim($user['user_last'])) < 1) {
        $user['user_last'] = isset($_POST['give_last']) ? strip_tags(trim($_POST['give_last'])) : '';
    }
    // Get the user's billing address details
    $user['address'] = array();
    $user['address']['line1'] = !empty($_POST['card_address']) ? sanitize_text_field($_POST['card_address']) : false;
    $user['address']['line2'] = !empty($_POST['card_address_2']) ? sanitize_text_field($_POST['card_address_2']) : false;
    $user['address']['city'] = !empty($_POST['card_city']) ? sanitize_text_field($_POST['card_city']) : false;
    $user['address']['state'] = !empty($_POST['card_state']) ? sanitize_text_field($_POST['card_state']) : false;
    $user['address']['country'] = !empty($_POST['billing_country']) ? sanitize_text_field($_POST['billing_country']) : false;
    $user['address']['zip'] = !empty($_POST['card_zip']) ? sanitize_text_field($_POST['card_zip']) : false;
    if (empty($user['address']['country'])) {
        $user['address'] = false;
    }
    // Country will always be set if address fields are present
    if (!empty($user['user_id']) && $user['user_id'] > 0 && !empty($user['address'])) {
        // Store the address in the user's meta so the donation form can be pre-populated with it on return purchases
        update_user_meta($user['user_id'], '_give_user_address', $user['address']);
    }
    // Return valid user
    return $user;
}