function wsl_process_login_new_users_gateway($provider, $redirect_to, $hybridauth_user_profile) { // HOOKABLE: do_action("wsl_process_login_new_users_gateway_start", $provider, $redirect_to, $hybridauth_user_profile); $assets_base_url = WORDPRESS_SOCIAL_LOGIN_PLUGIN_URL . '/assets/img/16x16/'; // remove wsl widget remove_action('register_form', 'wsl_render_auth_widget_in_wp_register_form'); $hybridauth_user_email = sanitize_email($hybridauth_user_profile->email); $hybridauth_user_login = sanitize_user($hybridauth_user_profile->displayName, true); $hybridauth_user_avatar = $hybridauth_user_profile->photoURL; $hybridauth_user_website = $hybridauth_user_profile->webSiteURL; $hybridauth_user_link = $hybridauth_user_profile->profileURL; $hybridauth_user_login = trim(str_replace(array(' ', '.'), '_', $hybridauth_user_login)); $hybridauth_user_login = trim(str_replace('__', '_', $hybridauth_user_login)); $requested_user_email = isset($_REQUEST["user_email"]) ? trim($_REQUEST["user_email"]) : $hybridauth_user_email; $requested_user_login = isset($_REQUEST["user_login"]) ? trim($_REQUEST["user_login"]) : $hybridauth_user_login; $requested_user_email = apply_filters('wsl_new_users_gateway_alter_requested_email', $requested_user_email); $requested_user_login = apply_filters('wsl_new_users_gateway_alter_requested_login', $requested_user_login); $user_id = 0; $shall_pass = false; $bouncer_account_linking = false; $account_linking_errors = array(); $bouncer_profile_completion = false; $profile_completion_errors = array(); $linking_enabled = get_option('wsl_settings_bouncer_accounts_linking_enabled'); // $linking_enabled = 2; // overide linking_enabled if (isset($_REQUEST["bouncer_account_linking"])) { if ($linking_enabled == 2) { return wsl_process_login_render_notice_page(_wsl__("Not tonight.", 'wordpress-social-login')); } $bouncer_account_linking = true; $username = isset($_REQUEST["user_login"]) ? trim($_REQUEST["user_login"]) : ''; $password = isset($_REQUEST["user_password"]) ? trim($_REQUEST["user_password"]) : ''; # http://codex.wordpress.org/Function_Reference/wp_authenticate $user = wp_authenticate($username, $password); // WP_Error object? if (is_wp_error($user)) { // we give no useful hint. $account_linking_errors[] = sprintf(_wsl__('<strong>ERROR</strong>: Invalid username or incorrect password. <a href="%s">Lost your password</a>?', 'wordpress-social-login'), wp_lostpassword_url(home_url())); } elseif (is_a($user, 'WP_User')) { $user_id = $user->ID; $shall_pass = true; } } elseif (isset($_REQUEST["bouncer_profile_completion"])) { $require_email = get_option('wsl_settings_bouncer_profile_completion_require_email'); $change_username = get_option('wsl_settings_bouncer_profile_completion_change_username'); $extra_fields = get_option('wsl_settings_bouncer_profile_completion_hook_extra_fields'); // Bouncer::Profile Completion enabled? // > if not enabled we just let the user pass if ($require_email == 2 && $change_username == 2 && $extra_fields == 2) { $shall_pass = true; } else { $bouncer_profile_completion = true; /** * Code based on wpmu_validate_user_signup() * * Ref: http://codex.wordpress.org/Function_Reference/wpmu_validate_user_signup */ # {{{ validate usermail if ($require_email == 1) { if (empty($requested_user_email)) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Please type your e-mail address.', 'wordpress-social-login'); } if (!is_email($requested_user_email)) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Please enter a valid email address.', 'wordpress-social-login'); } if (wsl_wp_email_exists($requested_user_email)) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Sorry, that email address is already used!', 'wordpress-social-login'); } } # }}} validate usermail # {{{ validate username (called login in wsl) if ($change_username == 1) { $illegal_names = array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator'); $illegal_names = apply_filters('wsl_new_users_gateway_alter_illegal_names', $illegal_names); if (in_array($requested_user_login, $illegal_names) == true) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: That username is not allowed.', 'wordpress-social-login'); } if (strlen($requested_user_login) < 4) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Username must be at least 4 characters.', 'wordpress-social-login'); } if (strpos(' ' . $requested_user_login, '_') != false) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Sorry, usernames may not contain the character “_”!', 'wordpress-social-login'); } if (preg_match('/^[0-9]*$/', $requested_user_login)) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Sorry, usernames must have letters too!', 'wordpress-social-login'); } if (username_exists($requested_user_login)) { $profile_completion_errors[] = _wsl__('<strong>ERROR</strong>: Sorry, that username already exists!', 'wordpress-social-login'); } } # }}} validate username # ... well, that was a lot of sorries. # {{{ extra fields if ($extra_fields == 1) { $errors = new WP_Error(); $errors = apply_filters('registration_errors', $errors, $requested_user_login, $requested_user_email); if ($errors = $errors->get_error_messages()) { foreach ($errors as $error) { $profile_completion_errors[] = $error; } } } # }}} extra fields $profile_completion_errors = apply_filters('wsl_new_users_gateway_alter_profile_completion_errors', $profile_completion_errors); // all check? if (!$profile_completion_errors) { $shall_pass = true; } } } if ($shall_pass == false) { ?> <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo get_bloginfo('name'); ?> </title> <style type="text/css"> html, body { height: 100%; margin: 0; padding: 0; } body { background: none repeat scroll 0 0 #f1f1f1; font-size: 14px; color: #444; font-family: "Open Sans",sans-serif; } hr { border-color: #eeeeee; border-style: none none solid; border-width: 0 0 1px; margin: 2px 0 0; } h4 { font-size: 14px; margin-bottom: 10px; } #login { width: 616px; margin: auto; padding: 114px 0 0; } #login-panel { background: none repeat scroll 0 0 #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13); margin: 2em auto; box-sizing: border-box; display: inline-block; padding: 70px 0 15px; position: relative; text-align: center; width: 100%; } #avatar { margin-left: -76px; top: -80px; left: 50%; padding: 4px; position: absolute; } #avatar img { background: none repeat scroll 0 0 #fff; border: 3px solid #f1f1f1; border-radius: 75px !important; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13); height: 145px; width: 145px; } #welcome { height: 55px; margin: 15px 20px 35px; } #idp-icon { position: absolute; margin-top: 2px; margin-left: -19px; } #login-form{ margin: 0; padding: 0; } .button-primary { background-color: #21759b; background-image: linear-gradient(to bottom, #2a95c5, #21759b); border-color: #21759b #21759b #1e6a8d; border-radius: 3px; border-style: solid; border-width: 1px; box-shadow: 0 1px 0 rgba(120, 200, 230, 0.5) inset; box-sizing: border-box; color: #fff; cursor: pointer; display: inline-block; float: none; font-size: 12px; height: 36px; line-height: 23px; margin: 0; padding: 0 10px 1px; text-decoration: none; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1); white-space: nowrap; } button-primary.focus, .button-primary:hover{ background:#1e8cbe; border-color:#0074a2; -webkit-box-shadow:inset 0 1px 0 rgba(120,200,230,.6); box-shadow:inset 0 1px 0 rgba(120,200,230,.6); color:#fff } input[type="text"]{ border: 1px solid #e5e5e5; box-shadow: 1px 1px 2px rgba(200, 200, 200, 0.2) inset; color: #555; font-size: 17px; height: 30px; line-height: 1; margin-bottom: 16px; margin-right: 6px; margin-top: 2px; outline: 0 none; padding: 3px; width: 100%; } input[type="text"]:focus{ border-color:#5b9dd9; -webkit-box-shadow:0 0 2px rgba(30,140,190,.8); box-shadow:0 0 2px rgba(30,140,190,.8) } input[type="submit"]{ float:right; } label{ color:#777; font-size:14px; cursor:pointer; vertical-align:middle; text-align: left; } table { width:355px; margin-left:auto; margin-right:auto; } #mapping-options { width:555px; } #mapping-authenticate { display:none; } #mapping-complete-info { display:none; } .error { display:none; background-color: #fff; border-left: 4px solid #dd3d36; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); margin: 0 21px; padding: 12px; text-align:left; } .back-to-options { float: left; margin: 7px 0px; } .back-to-home { font-size: 12px; margin-top: -18px; } .back-to-home a { color: #999; text-decoration: none; } <?php if ($linking_enabled == 2) { ?> #login {width: 400px;} #welcome, #mapping-options, #errors-account-linking, #mapping-complete-info {display: none;} #errors-profile-completion, #mapping-complete-info {display: block;} <?php } elseif ($bouncer_account_linking) { ?> #login {width: 400px;} #welcome, #mapping-options, #errors-profile-completion, #mapping-complete-info {display: none;} #errors-account-linking, #mapping-authenticate {display: block;} <?php } elseif ($bouncer_profile_completion) { ?> #login {width: 400px;} #welcome, #mapping-options, #errors-account-linking, #mapping-complete-info {display: none;} #errors-profile-completion, #mapping-complete-info {display: block;} <?php } ?> </style> <script> // good old time function toggleEl( el, display ) { if( el = document.getElementById( el ) ) { el.style.display = display; } } function toggleWidth( el, width ) { if( el = document.getElementById( el ) ) { el.style.width = width; } } function display_mapping_options() { toggleWidth( 'login', '616px' ); toggleEl( 'welcome' , 'block' ); toggleEl( 'mapping-options', 'block' ); toggleEl( 'errors-profile-completion', 'none' ); toggleEl( 'mapping-authenticate' , 'none' ); toggleEl( 'errors-account-linking', 'none' ); toggleEl( 'mapping-complete-info' , 'none' ); } function display_mapping_authenticate() { toggleWidth( 'login', '400px' ); toggleEl( 'welcome' , 'none' ); toggleEl( 'mapping-options', 'none' ); toggleEl( 'errors-account-linking', 'block' ); toggleEl( 'mapping-authenticate' , 'block' ); toggleEl( 'errors-profile-completion', 'none' ); toggleEl( 'mapping-complete-info' ,'none' ); } function display_mapping_complete_info() { toggleWidth( 'login', '400px' ); toggleEl( 'welcome' , 'none' ); toggleEl( 'mapping-options', 'none' ); toggleEl( 'errors-account-linking', 'none' ); toggleEl( 'mapping-authenticate' , 'none' ); toggleEl( 'errors-profile-completion', 'block' ); toggleEl( 'mapping-complete-info' , 'block' ); } </script> </head> <body> <div id="login"> <div id="login-panel"> <div id="avatar"> <img src="<?php echo $hybridauth_user_avatar; ?> "> </div> <div id="welcome"> <img id="idp-icon" src="<?php echo $assets_base_url . $provider; ?> .png" > <b><?php printf(_wsl__("Hi %s", 'wordpress-social-login'), htmlentities($hybridauth_user_profile->displayName)); ?> </b> <p><?php printf(_wsl__("You're now signed in with your %s account but you still one step away of getting into our website", 'wordpress-social-login'), $provider); ?> .</p> <hr /> </div> <table id="mapping-options" border="0"> <tr> <?php if ($linking_enabled == 1) { ?> <td valign="top" width="50%" style="text-align:center;"> <h4><?php _wsl_e("Already have an account", 'wordpress-social-login'); ?> ?</h4> <p style="font-size: 12px;"><?php printf(_wsl__("Link your existing account on our website to your %s ID.", 'wordpress-social-login'), $provider); ?> </p> </td> <?php } ?> <td valign="top" width="50%" style="text-align:center;"> <h4><?php _wsl_e("New to our website", 'wordpress-social-login'); ?> ?</h4> <p style="font-size: 12px;"><?php printf(_wsl__("Create a new account and it will be associated with your %s ID.", 'wordpress-social-login'), $provider); ?> </p> </td> </tr> <tr> <?php if ($linking_enabled == 1) { ?> <td valign="top" width="50%" style="text-align:center;"> <input type="button" value="<?php _wsl_e("Link my account", 'wordpress-social-login'); ?> " class="button-primary" onclick="display_mapping_authenticate();" > </td> <?php } ?> <td valign="top" width="50%" style="text-align:center;"> <input type="button" value="<?php _wsl_e("Create a new account", 'wordpress-social-login'); ?> " class="button-primary" onclick="display_mapping_complete_info();" > </td> </tr> </table> <?php if ($account_linking_errors) { echo '<div id="errors-account-linking" class="error">'; foreach ($account_linking_errors as $error) { ?> <p><?php echo $error; ?> </p><?php } echo '</div>'; } if ($profile_completion_errors) { echo '<div id="errors-profile-completion" class="error">'; foreach ($profile_completion_errors as $error) { ?> <p><?php echo $error; ?> </p><?php } echo '</div>'; } ?> <form method="post" action="<?php echo site_url('wp-login.php', 'login_post'); ?> " id="login-form"> <table id="mapping-authenticate" border="0"> <tr> <td valign="top" width="50%" style="text-align:center;"> <h4><?php _wsl_e("Already have an account", 'wordpress-social-login'); ?> ?</h4> <p><?php printf(_wsl__("Please enter your username and password of your existing account on our website. Once verified, it will linked to your % ID", 'wordpress-social-login'), ucfirst($provider)); ?> .</p> </td> </tr> <tr> <td valign="bottom" width="50%" style="text-align:left;"> <label> <?php _wsl_e("Username", 'wordpress-social-login'); ?> <br /> <input type="text" name="user_login" class="input" value="" size="25" placeholder="" /> </label> <label> <?php _wsl_e("Password", 'wordpress-social-login'); ?> <br /> <input type="text" name="user_password" class="input" value="" size="25" placeholder="" /> </label> <input type="submit" value="<?php _wsl_e("Continue", 'wordpress-social-login'); ?> " class="button-primary" > <a href="javascript:void(0);" onclick="display_mapping_options();" class="back-to-options"><?php _wsl_e("Back", 'wordpress-social-login'); ?> </a> </td> </tr> </table> <input type="hidden" id="redirect_to" name="redirect_to" value="<?php echo $redirect_to; ?> "> <input type="hidden" id="provider" name="provider" value="<?php echo $provider; ?> "> <input type="hidden" id="action" name="action" value="wordpress_social_account_linking"> <input type="hidden" id="bouncer_account_linking" name="bouncer_account_linking" value="1"> </form> <form method="post" action="<?php echo site_url('wp-login.php', 'login_post'); ?> " id="login-form"> <table id="mapping-complete-info" border="0"> <tr> <td valign="top" width="50%" style="text-align:center;"> <?php if ($linking_enabled == 1) { ?> <h4><?php _wsl_e("New to our website", 'wordpress-social-login'); ?> ?</h4> <?php } ?> <p><?php printf(_wsl__("Please fill in your information in the form below. Once completed, you will be able to automatically sign into our website through your %s ID", 'wordpress-social-login'), ucfirst($provider)); ?> .</p> </td> </tr> <tr> <td valign="bottom" width="50%" style="text-align:left;"> <label> <?php _wsl_e("Username", 'wordpress-social-login'); ?> <br /> <input type="text" name="user_name" class="input" value="<?php echo $requested_user_login; ?> " size="25" placeholder="" /> </label> <label> <?php _wsl_e("E-mail", 'wordpress-social-login'); ?> <br /> <input type="text" name="user_email" class="input" value="<?php echo $requested_user_email; ?> " size="25" placeholder="" /> </label> <?php /** * Fires following the 'E-mail' field in the user registration form. * * hopefully, this won't become a pain in future * * Ref: http://codex.wordpress.org/Plugin_API/Action_Reference/register_form */ $extra_fields = get_option('wsl_settings_bouncer_profile_completion_hook_extra_fields'); if ($extra_fields == 1) { do_action('register_form'); } ?> <input type="submit" value="<?php _wsl_e("Continue", 'wordpress-social-login'); ?> " class="button-primary" > <?php if ($linking_enabled == 1) { ?> <a href="javascript:void(0);" onclick="display_mapping_options();" class="back-to-options"><?php _wsl_e("Back", 'wordpress-social-login'); ?> </a> <?php } ?> </td> </tr> </table> <input type="hidden" id="redirect_to" name="redirect_to" value="<?php echo $redirect_to; ?> "> <input type="hidden" id="provider" name="provider" value="<?php echo $provider; ?> "> <input type="hidden" id="action" name="action" value="wordpress_social_account_linking"> <input type="hidden" id="bouncer_profile_completion" name="bouncer_profile_completion" value="1"> </form> </div> <p class="back-to-home"> <a href="<?php echo site_url(); ?> ">← <?php printf(_wsl__("Back to %s", 'wordpress-social-login'), get_bloginfo('name')); ?> </a> </p> </div> <?php // Development mode on? if (get_option('wsl_settings_development_mode_enabled')) { wsl_display_dev_mode_debugging_area(); } ?> </body> </html> <?php die; } return array($shall_pass, $user_id, $requested_user_login, $requested_user_email); }
/** * Returns user data after he authenticate via hybridauth * * Steps: * 1. Grab the user profile from hybridauth * 2. Run Bouncer::Filters if enabled (domains, emails, profiles urls) * 3. Check if user exist in database by looking for the couple (Provider name, Provider user ID) or verified email * 4. Deletegate detection of user id to custom functions / hooks * 5. If Bouncer::Profile Completion is enabled and user didn't exist, we require the user to complete the registration (user name & email) */ function wsl_process_login_get_user_data($provider, $redirect_to) { // HOOKABLE: do_action("wsl_process_login_get_user_data_start", $provider, $redirect_to); $user_id = null; $config = null; $hybridauth = null; $adapter = null; $hybridauth_user_profile = null; $requested_user_login = ''; $requested_user_email = ''; $wordpress_user_id = 0; /* 1. Grab the user profile from social network */ if (!(isset($_SESSION['wsl::userprofile']) && $_SESSION['wsl::userprofile'] && ($hybridauth_user_profile = json_decode($_SESSION['wsl::userprofile'])))) { $hybridauth_user_profile = wsl_process_login_request_user_social_profile($provider); $_SESSION['wsl::userprofile'] = json_encode($hybridauth_user_profile); } $adapter = wsl_process_login_get_provider_adapter($provider); $hybridauth_user_email = sanitize_email($hybridauth_user_profile->email); /* 2. Run Bouncer::Filters if enabled (domains, emails, profiles urls) */ // Bouncer::Filters by emails domains name if (get_option('wsl_settings_bouncer_new_users_restrict_domain_enabled') == 1) { if (empty($hybridauth_user_email)) { return wsl_process_login_render_notice_page(_wsl__(get_option('wsl_settings_bouncer_new_users_restrict_domain_text_bounce'), 'wordpress-social-login')); } $list = get_option('wsl_settings_bouncer_new_users_restrict_domain_list'); $list = preg_split('/$\\R?^/m', $list); $current = strstr($hybridauth_user_email, '@'); $shall_pass = false; foreach ($list as $item) { if (trim(strtolower("@{$item}")) == strtolower($current)) { $shall_pass = true; } } if (!$shall_pass) { return wsl_process_login_render_notice_page(_wsl__(get_option('wsl_settings_bouncer_new_users_restrict_domain_text_bounce'), 'wordpress-social-login')); } } // because instagram doesn't (do any?) have an email, we need to check if the option "require email" is set and then get the email from // the user BEFORE we filter by email address /* 4 Deletegate detection of user id to custom filters hooks */ $user_id = (int) wsl_get_stored_hybridauth_user_id_by_provider_and_provider_uid($provider, $hybridauth_user_profile->identifier); /* 5. If Bouncer::Profile Completion is enabled and user didn't exist, we require the user to complete the registration (user name & email) */ if (!$user_id) { // Bouncer :: Accept new registrations? if (get_option('wsl_settings_bouncer_registration_enabled') == 2) { return wsl_process_login_render_notice_page(_wsl__("Registration is now closed.", 'wordpress-social-login')); } // Bouncer::Accounts linking/mapping // > > not implemented yet! Planned for WSL 2.3 if (get_option('wsl_settings_bouncer_accounts_linking_enabled') == 1) { do { list($shall_pass, $user_id, $requested_user_login, $requested_user_email) = wsl_process_login_new_users_gateway($provider, $redirect_to, $hybridauth_user_profile); } while (!$shall_pass); $wordpress_user_id = $user_id; } elseif (get_option('wsl_settings_bouncer_profile_completion_require_email') == 1 && empty($hybridauth_user_email) || get_option('wsl_settings_bouncer_profile_completion_change_username') == 1) { do { list($shall_pass, $user_id, $requested_user_login, $requested_user_email) = wsl_process_login_new_users_gateway($provider, $redirect_to, $hybridauth_user_profile); } while (!$shall_pass); } } else { $wordpress_user_id = $user_id; } $hybridauth_user_email = $requested_user_email; // Bouncer::Filters by e-mails addresses if (get_option('wsl_settings_bouncer_new_users_restrict_email_enabled') == 1) { error_log(__METHOD__ . ' start wsl_settings_bouncer_new_users_restrict_email_enabled.'); error_log(__METHOD__ . ' hybridauth_user_email is ' . $hybridauth_user_email); if (empty($hybridauth_user_email)) { return wsl_process_login_render_notice_page(_wsl__(get_option('wsl_settings_bouncer_new_users_restrict_email_text_bounce'), 'wordpress-social-login')); } $list = get_option('wsl_settings_bouncer_new_users_restrict_email_list'); $list = preg_split('/$\\R?^/m', $list); $shall_pass = false; foreach ($list as $item) { if (trim(strtolower($item)) == strtolower($hybridauth_user_email)) { $shall_pass = true; } } if (!$shall_pass) { return wsl_process_login_render_notice_page(_wsl__(get_option('wsl_settings_bouncer_new_users_restrict_email_text_bounce'), 'wordpress-social-login')); } } // Bouncer::Filters by profile urls if (get_option('wsl_settings_bouncer_new_users_restrict_profile_enabled') == 1) { error_log(__METHOD__ . ' start restrict_profile_enabled.'); $list = get_option('wsl_settings_bouncer_new_users_restrict_profile_list'); $list = preg_split('/$\\R?^/m', $list); error_log(__METHOD__ . ' $list is ' . print_r($list, true)); $shall_pass = false; foreach ($list as $item) { error_log(__METHOD__ . ' $item is ' . $item); error_log(__METHOD__ . ' $hybridauth_user_profile->profileURL is ' . $hybridauth_user_profile->profileURL); if (trim(strtolower($item)) == strtolower($hybridauth_user_profile->profileURL)) { $shall_pass = true; } } if (!$shall_pass) { return wsl_process_login_render_notice_page(_wsl__(get_option('wsl_settings_bouncer_new_users_restrict_profile_text_bounce'), 'wordpress-social-login')); } } /* 3. Check if user exist in database by looking for the couple (Provider name, Provider user ID) or verified email */ // check if user already exist in wslusersprofiles $user_id = (int) wsl_get_stored_hybridauth_user_id_by_provider_and_provider_uid($provider, $hybridauth_user_profile->identifier); // if not found in wslusersprofiles, then check his verified email if (!$user_id && !empty($hybridauth_user_profile->emailVerified)) { // check if the verified email exist in wp_users $user_id = (int) wsl_wp_email_exists($hybridauth_user_profile->emailVerified); // the user exists in Wordpress $wordpress_user_id = $user_id; // check if the verified email exist in wslusersprofiles if (!$user_id) { $user_id = (int) wsl_get_stored_hybridauth_user_id_by_email_verified($hybridauth_user_profile->emailVerified); } } /* 4 Deletegate detection of user id to custom filters hooks */ /* 6. returns user data */ return array($user_id, $adapter, $hybridauth_user_profile, $requested_user_login, $requested_user_email, $wordpress_user_id); }
function wsl_process_login_complete_registration($provider, $redirect_to, $hybridauth_user_profile) { // HOOKABLE: do_action("wsl_process_login_complete_registration_start", $provider, $redirect_to, $hybridauth_user_profile); $hybridauth_user_email = sanitize_email($hybridauth_user_profile->email); $hybridauth_user_login = sanitize_user($hybridauth_user_profile->displayName, true); $hybridauth_user_avatar = $hybridauth_user_profile->photoURL; $request_user_login = isset($_REQUEST["user_login"]) ? $_REQUEST["user_login"] : ''; $request_user_email = isset($_REQUEST["user_email"]) ? $_REQUEST["user_email"] : ''; $request_user_login = sanitize_user($request_user_login, true); $request_user_email = sanitize_email($request_user_email); $request_user_login = trim(str_replace(array(' ', '.'), '_', $request_user_login)); $request_user_login = trim(str_replace('__', '_', $request_user_login)); $request_user_login_exists = username_exists($request_user_login); $request_user_email_exists = wsl_wp_email_exists($request_user_email); $request_user_login_validate = validate_username($request_user_login); $request_user_email_validate = filter_var($request_user_email, FILTER_VALIDATE_EMAIL); if (empty($request_user_login)) { $request_user_login_validate = false; } if (empty($request_user_email)) { $request_user_email_validate = false; } if (empty($request_user_login)) { $request_user_login = $hybridauth_user_login; } if (empty($request_user_email)) { $request_user_email = $hybridauth_user_email; } $shall_pass = true; $shall_pass_errors = array(); // well until brain become able to compute again.. if (get_option('wsl_settings_bouncer_profile_completion_require_email') == 1) { if (!$request_user_email) { $shall_pass = false; $shall_pass_errors[_wsl__("E-mail is not valid!", 'wordpress-social-login')] = true; } if (!$request_user_email_validate) { $shall_pass = false; $shall_pass_errors[_wsl__("E-mail is not valid!", 'wordpress-social-login')] = true; } if ($request_user_email_exists) { $shall_pass = false; $shall_pass_errors[_wsl__("That E-mail is already registered!", 'wordpress-social-login')] = true; } } if (get_option('wsl_settings_bouncer_profile_completion_change_username') == 1) { if (!$request_user_login) { $shall_pass = false; $shall_pass_errors[_wsl__("Username is not valid!", 'wordpress-social-login')] = true; } if (!$request_user_login_validate) { $shall_pass = false; $shall_pass_errors[_wsl__("Username is not valid!", 'wordpress-social-login')] = true; } if ($request_user_login_exists) { $shall_pass = false; $shall_pass_errors[_wsl__("That Username is already registered!", 'wordpress-social-login')] = true; } } if (!$shall_pass) { ?> <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo get_bloginfo('name'); ?> </title> <head> <style> html, body { height: 100%; margin: 0; padding: 0; } body { background: none repeat scroll 0 0 #f1f1f1; font-size: 14px; color: #444; font-family: "Open Sans",sans-serif; } hr { border-color: #eeeeee; border-style: none none solid; border-width: 0 0 1px; margin: 2px 0 0; } h4 { font-size: 14px; margin-bottom: 10px; } #login { width: 585px; margin: auto; padding: 114px 0 0; } #login-panel { background: none repeat scroll 0 0 #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13); margin: 2em auto; box-sizing: border-box; display: inline-block; padding: 70px 0 15px; position: relative; text-align: center; width: 100%; } #avatar { margin-left: 213px; top: -82px; padding: 4px; position: absolute; } #avatar img { background: none repeat scroll 0 0 #fff; border: 3px solid #f1f1f1; border-radius: 75px !important; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.13); height: 145px; width: 145px; } #welcome { margin: 15px 20px 15px; } #idp-icon { position: absolute; margin-top: 2px; margin-left: -19px; } #login-form{ margin: 0; padding: 0; } .button-primary { background-color: #21759b; background-image: linear-gradient(to bottom, #2a95c5, #21759b); border-color: #21759b #21759b #1e6a8d; border-radius: 3px; border-style: solid; border-width: 1px; box-shadow: 0 1px 0 rgba(120, 200, 230, 0.5) inset; box-sizing: border-box; color: #fff; cursor: pointer; display: inline-block; float: none; font-size: 13px; height: 32px; line-height: 23px; margin: 0; padding: 0 10px 1px; text-decoration: none; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1); white-space: nowrap; } button-primary:focus, .button-primary:hover{ background:#1e8cbe; border-color:#0074a2; -webkit-box-shadow:inset 0 1px 0 rgba(120,200,230,.6); box-shadow:inset 0 1px 0 rgba(120,200,230,.6); color:#fff } input[type="text"]{ border: 1px solid #e5e5e5; box-shadow: 1px 1px 2px rgba(200, 200, 200, 0.2) inset; color: #555; font-size: 17px; height: 30px; line-height: 1; margin-bottom: 16px; margin-right: 6px; margin-top: 2px; outline: 0 none; padding: 3px; width: 99%; } input[type="text"]:focus{ border-color:#5b9dd9; -webkit-box-shadow:0 0 2px rgba(30,140,190,.8); box-shadow:0 0 2px rgba(30,140,190,.8) } input[type="submit"]{ float:right; } label{ color:#777; font-size:14px; cursor:pointer; vertical-align:middle; text-align: left; } table { width:485px; margin-left:auto; margin-right:auto; } table p{ margin-top:0; margin-bottom:0; } #mapping-complete-info { } #error { background-color: #fff; border: 1px solid #dd3d36; border-left: 4px solid #dd3d36; box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1); margin: 0 21px; margin: 0; margin-bottom:8px; padding: 12px; text-align: left; } .back-to-options { float: left; margin: 7px 0px; } .back-to-home { font-size: 12px; margin-top: -18px; } .back-to-home a { color: #999; text-decoration: none; } </style> <script> function init() { if( document.getElementById('user_login') ) document.getElementById('user_login').focus() if( document.getElementById('user_email') ) document.getElementById('user_email').focus() } </script> </head> <body onload="init();"> <div id="login"> <div id="login-panel"> <div id="avatar"> <img src="<?php echo $hybridauth_user_avatar; ?> "> </div> <div id="welcome"> <p> <?php printf(_wsl__("Hi %s, you're one step away from completing your account.", 'wordpress-social-login'), htmlentities($hybridauth_user_profile->displayName)); ?> </p> <p> <?php _wsl_e("Please, fill in your information in the form below to continue", 'wordpress-social-login'); ?> . </p> </div> <form method="post" action="<?php echo site_url('wp-login.php', 'login_post'); ?> " id="login-form"> <table id="mapping-complete-info" border="0"> <tr> <td> <?php if (isset($_REQUEST["bouncer_profile_completion"]) && $shall_pass_errors) { echo '<div id="error">'; foreach ($shall_pass_errors as $k => $v) { ?> <p><?php echo $k; ?> </p><?php } echo '</div>'; } ?> </td> </tr> <tr> <td valign="bottom" width="50%" style="text-align:left;"> <?php if (get_option('wsl_settings_bouncer_profile_completion_change_username') == 1) { ?> <p> <label for="user_login"><?php _wsl_e("Username", 'wordpress-social-login'); ?> <br><input type="text" name="user_login" id="user_login" class="input" value="<?php echo $request_user_login; ?> " size="25" /></label> </p> <?php } if (get_option('wsl_settings_bouncer_profile_completion_require_email') == 1) { ?> <p> <label for="user_email"><?php _wsl_e("E-mail", 'wordpress-social-login'); ?> <br><input type="text" name="user_email" id="user_email" class="input" value="<?php echo $request_user_email; ?> " size="25" /></label> </p> <?php } ?> <input type="submit" value="<?php _wsl_e("Continue", 'wordpress-social-login'); ?> " class="button-primary" > </td> </tr> </table> <input type="hidden" id="redirect_to" name="redirect_to" value="<?php echo $redirect_to; ?> "> <input type="hidden" id="provider" name="provider" value="<?php echo $provider; ?> "> <input type="hidden" id="action" name="action" value="wordpress_social_profile_completion"> <input type="hidden" id="bouncer_profile_completion" name="bouncer_profile_completion" value="1"> </form> </div> <p class="back-to-home"> <a href="<?php echo site_url(); ?> ">← <?php printf(_wsl__("Back to %s", 'wordpress-social-login'), get_bloginfo('name')); ?> </a> </p> </div> <?php // Development mode on? if (get_option('wsl_settings_development_mode_enabled')) { wsl_display_dev_mode_debugging_area(); } ?> </body> </html> <?php die; } return array($shall_pass, $request_user_login, $request_user_email); }
/** * Create a new wordpress user * * Ref: http://codex.wordpress.org/Function_Reference/wp_insert_user */ function wsl_process_login_create_wp_user($provider, $hybridauth_user_profile, $requested_user_login, $requested_user_email) { // HOOKABLE: do_action("wsl_process_login_create_wp_user_start", $provider, $hybridauth_user_profile, $requested_user_login, $requested_user_email); $user_login = ''; $user_email = ''; // if coming from "complete registration form" if ($requested_user_login) { $user_login = $requested_user_login; } if ($requested_user_email) { $user_email = $requested_user_email; } if (!$user_login) { // attempt to generate user_login from hybridauth user profile display name $user_login = $hybridauth_user_profile->displayName; // sanitize user login $user_login = sanitize_user($user_login, true); // remove spaces and dots $user_login = trim(str_replace(array(' ', '.'), '_', $user_login)); $user_login = trim(str_replace('__', '_', $user_login)); // if user profile display name is not provided if (empty($user_login)) { $user_login = strtolower($provider) . "_user"; } // user name should be unique if (username_exists($user_login)) { $i = 1; $user_login_tmp = $user_login; do { $user_login_tmp = $user_login . "_" . $i++; } while (username_exists($user_login_tmp)); $user_login = $user_login_tmp; } } if (!$user_email) { $user_email = $hybridauth_user_profile->email; // generate an email if none if (!isset($user_email) or !is_email($user_email)) { $user_email = strtolower($provider . "_user_" . $user_login) . '@example.com'; } // email should be unique if (wsl_wp_email_exists($user_email)) { do { $user_email = md5(uniqid(wp_rand(10000, 99000))) . '@example.com'; } while (wsl_wp_email_exists($user_email)); } } $display_name = $hybridauth_user_profile->displayName; if ($requested_user_login) { $display_name = sanitize_user($requested_user_login, true); } if (empty($display_name)) { $display_name = strtolower($provider) . "_user"; } $userdata = array('user_login' => $user_login, 'user_email' => $user_email, 'display_name' => $display_name, 'first_name' => $hybridauth_user_profile->firstName, 'last_name' => $hybridauth_user_profile->lastName, 'user_url' => $hybridauth_user_profile->profileURL, 'description' => $hybridauth_user_profile->description, 'user_pass' => wp_generate_password()); // Bouncer::Membership level $wsl_settings_bouncer_new_users_membership_default_role = get_option('wsl_settings_bouncer_new_users_membership_default_role'); // if level eq "default", we set role to wp default user role if ($wsl_settings_bouncer_new_users_membership_default_role == "default") { $userdata['role'] = get_option('default_role'); } elseif ($wsl_settings_bouncer_new_users_membership_default_role && $wsl_settings_bouncer_new_users_membership_default_role != 'wslnorole') { $userdata['role'] = $wsl_settings_bouncer_new_users_membership_default_role; } // Bouncer::User Moderation // > if Bouncer::User Moderation is enabled (Yield to Theme My Login), then we overwrite the user role to 'pending' # http://www.jfarthing.com/development/theme-my-login/user-moderation/ if (get_option('wsl_settings_bouncer_new_users_moderation_level') > 100) { $userdata['role'] = "pending"; } // HOOKABLE: change the user data $userdata = apply_filters('wsl_hook_process_login_alter_wp_insert_user_data', $userdata, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // $userdata = apply_filters( 'wsl_hook_process_login_alter_userdata', $userdata, $provider, $hybridauth_user_profile ); // HOOKABLE: This action runs just before creating a new wordpress user. do_action('wsl_hook_process_login_before_wp_insert_user', $userdata, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_before_insert_user', $userdata, $provider, $hybridauth_user_profile ); // HOOKABLE: This action runs just before creating a new wordpress user, it delegate user insert to a custom function. $user_id = apply_filters('wsl_hook_process_login_delegate_wp_insert_user', $userdata, $provider, $hybridauth_user_profile); // Create a new WordPress user if (!$user_id || !is_integer($user_id)) { $user_id = wp_insert_user($userdata); } // do not continue without user_id if (!$user_id || !is_integer($user_id)) { if (is_wp_error($user_id)) { return wsl_process_login_render_notice_page(_wsl__("An error occurred while creating a new user: "******"An error occurred while creating a new user!", 'wordpress-social-login')); } // Send notifications if (get_option('wsl_settings_users_notification') == 1) { wsl_admin_notification($user_id, $provider); } // HOOKABLE: This action runs just after a wordpress user has been created // > Note: At this point, the user has been added to wordpress database, but NOT CONNECTED. do_action('wsl_hook_process_login_after_wp_insert_user', $user_id, $provider, $hybridauth_user_profile); // DEPRECIATED: as of 2.2.3 // do_action( 'wsl_hook_process_login_after_create_wp_user', $user_id, $provider, $hybridauth_user_profile ); // returns the user created user id return $user_id; }
function test_wsl_wp_email_exists() { $this->assertEquals($this->someUserID, wsl_wp_email_exists($this->someUserMail)); }