예제 #1
0
/**
 * Process the registration form submission
 *
 * @return null
 */
function hma_register_submitted()
{
    $hm_return = hma_new_user(array('user_login' => $_POST['user_login'], 'user_email' => $_POST['user_email'], 'use_password' => true, 'user_pass' => $_POST['user_pass'], 'user_pass2' => $_POST['user_pass_1'], 'use_tos' => false, 'unique_email' => true, 'do_redirect' => false, 'send_email' => true, 'override_nonce' => true));
    if (is_wp_error($hm_return)) {
        if (isset($_REQUEST['register_source']) && $_REQUEST['register_source'] == 'popup') {
            wp_redirect(get_bloginfo('register_inline_url', 'display') . '?message=' . $hm_return->get_error_code());
        } else {
            wp_redirect(get_bloginfo('register_url', 'display') . '?message=' . $hm_return->get_error_code());
        }
        exit;
    } else {
        do_action('hma_register_completed', $hm_return);
        if ($_POST['redirect_to']) {
            $redirect = $_POST['redirect_to'];
        } elseif ($_POST['referer']) {
            $redirect = $_POST['referer'];
        } elseif (wp_get_referer()) {
            $redirect = wp_get_referer();
        } else {
            $redirect = get_bloginfo('edit_profile_url', 'display');
        }
        wp_redirect($redirect);
        exit;
    }
}
예제 #2
0
 public function register()
 {
     // Check if the SSO has already been registered with a WP account, if so then login them in and be done
     if (($result = $this->login()) && !is_wp_error($result)) {
         return $result;
     }
     if ($this->usingSession && !empty($_SESSION['twitter_oauth_token'])) {
         $this->access_token = $_SESSION['twitter_oauth_token'];
         unset($_SESSION['twitter_oauth_token']);
     } elseif (!empty($_COOKIE['twitter_oauth_token'])) {
         $this->access_token = unserialize(base64_decode($_COOKIE['twitter_oauth_token']));
         setcookie('twitter_oauth_token', '', time() - 100, COOKIEPATH);
     }
     $_info = $this->get_twitter_user_info();
     $info = $this->get_user_info();
     if (empty($info['_twitter_uid'])) {
         hm_error_message('There was a problem communication with Twitter, please try again.', 'register');
         return new WP_Error('twitter-connection-error');
     }
     $userdata = apply_filters('hma_register_user_data_from_sso', $info, $_info, &$this);
     if (!empty($_POST['user_login'])) {
         $userdata['user_login'] = esc_attr($_POST['user_login']);
     } else {
         $userdata['user_login'] = hma_unique_username($this->user_info->screen_name);
     }
     if (!empty($_POST['user_email'])) {
         $userdata['user_email'] = esc_attr($_POST['user_email']);
     }
     //Don't use such strict validation for registration via twitter
     add_action('hma_registration_info', array(&$this, '_validate_hma_new_user_for_twitter'), 11);
     $userdata['override_nonce'] = true;
     $userdata['do_login'] = true;
     $userdata['_twitter_access_token'] = $this->access_token;
     $userdata['_twitter_oauth_token'] = $this->access_token['oauth_token'];
     $userdata['_twitter_oauth_token_secret'] = $this->access_token['oauth_token_secret'];
     $userdata['do_redirect'] = false;
     $userdata['unique_email'] = false;
     $userdata['send_email'] = true;
     $userdata['location'] = $_info->location;
     $userdata['_twitter_data'] = (array) $_info;
     // Lets us skip email check from wp_insert_user()
     define('WP_IMPORTING', true);
     $result = hma_new_user($userdata);
     // Set_user() will wide access token
     $token = $this->access_token;
     $user = get_userdata($result);
     $this->set_user($user);
     $this->access_token = $token;
     $this->update_user_twitter_information();
     //set the avatar to their twitter avatar if registration completed
     if (!is_wp_error($result) && is_numeric($result)) {
         $this->avatar_option = new HMA_Twitter_Avatar_Option(&$this);
         update_user_meta($result, 'user_avatar_option', $this->avatar_option->service_id);
     }
     wp_set_auth_cookie($user->ID, false);
     wp_set_current_user($user->ID);
     return $result;
 }
예제 #3
0
 public function register()
 {
     // Check if the SSO has already been registered with a WP account, if so then login them in and be done
     if (($result = $this->login()) && !is_wp_error($result)) {
         return $result;
     }
     try {
         $fb_profile_data = $this->get_user_info();
         $_fb_profile_data = $this->get_facebook_user_info();
     } catch (Exception $e) {
         return new WP_Error('facebook-exception', $e->getMessage());
     }
     $userdata = apply_filters('hma_register_user_data_from_sso', $fb_profile_data, $_fb_profile_data, &$this);
     if (!empty($_POST['user_login'])) {
         $userdata['user_login'] = esc_attr($_POST['user_login']);
     }
     if (!empty($_POST['user_email'])) {
         $userdata['user_email'] = esc_attr($_POST['user_email']);
     } elseif (!empty($this->user_info['email'])) {
         $userdata['user_email'] = $this->user_info['email'];
     }
     //Don't use such strict validation for registration via facebook
     add_action('hma_registration_info', array(&$this, '_validate_hma_new_user'), 11);
     $userdata['override_nonce'] = true;
     $userdata['do_login'] = true;
     $userdata['do_redirect'] = false;
     $userdata['unique_email'] = false;
     $userdata['send_email'] = true;
     $userdata['gender'] = $_fb_profile_data['gender'];
     $userdata['url'] = $_fb_profile_data['website'];
     $userdata['location'] = $_fb_profile_data['location']['name'];
     $userdata['age'] = (int) date('Y') - (int) date('Y', strtotime($_fb_profile_data['birthday']));
     // Lets us skip email check from wp_insert_user()
     define('WP_IMPORTING', true);
     $result = $user_id = hma_new_user($userdata);
     // Set_user() will wide access token
     $token = $this->access_token;
     $user = get_userdata($result);
     $this->set_user(get_userdata($result));
     $this->access_token = $token;
     $this->update_user_facebook_information();
     //set the avatar to their twitter avatar if registration completed
     if (!is_wp_error($result) && is_numeric($result) && $this->is_authenticated()) {
         $this->avatar_option = new HMA_Facebook_Avatar_Option(&$this);
         update_user_meta($result, 'user_avatar_option', $this->avatar_option->service_id);
     }
     return $result;
 }