shane-tomlinson / browserid-wordpress

Wordpress plugin that adds Persona authentication
23 stars 16 forks source link

Plugin does not allow registration of new users #2

Closed micahwalter closed 11 years ago

micahwalter commented 11 years ago

Would be great if setting in WP is set to allow anyone to register if logging in via the plugin would auto-register the new user.

micahwalter commented 11 years ago

I saw this comment here http://wordpress.org/support/topic/plugin-mozilla-browserid-buddypress

Ok there is one problem though. If a user is not already registered to a wordpress site with their email, the BrowserID login will fail, because it looks for the corresponding email in the wordpress database. Upon not finding it, it gives a "fail" error message. In order to make the user experience more smooth, it would be a very very good idea to register a user who attempts to login to the wordpress site for the first time using BrowserID, if they are not already registered, in order to avoid a "fail" error message which in the end obliges them to register to the wordpress site anyway.

So in order to get around this obstacle, I added a few lines of code to the plugin, I added an "else" condition in the function "Login_by_email()" which registers a new user with a random password and using the first part of the email address as username, when this email is not yet registered to the wordpress website:

// Login user using e-mail address function Login_by_email($email, $rememberme) { global $user; $user = null;

$userdata = get_user_by('email', $email);
if ($userdata) {
    $user = new WP_User($userdata->ID);
    wp_set_current_user($userdata->ID, $userdata->user_login);
    wp_set_auth_cookie($userdata->ID, $rememberme);
    do_action('wp_login', $userdata->user_login);
}
else{
    $random_password = wp_generate_password(12, false);
        $user_name= explode("@",$email);
    wp_create_user($user_name[0], $random_password, $email);
    $user = self::Login_by_email($email, $rememberme);
}
return $user;

}

shane-tomlinson commented 11 years ago

Thanks for the suggestion and the PR!

I have already implemented this in the GitHub version of the plugin, using the full email address as the username, but I was hoping to have a cleaner solution. Using the local portion of the email address (the portion before the @) does not offer sufficient global uniqueness as somebody registering with shane@gmail.com and somebody else with shane@yahoo.com would try to sign up with the same username.

Can you look at: https://github.com/shane-tomlinson/browserid-wordpress/blob/master/browserid.php#L344? I think we are thinking along the same lines.

micahwalter commented 11 years ago

Shane, Yeah, I thought about that issue. Might be fine to just create wordpress usernames like shane-12345 ( where 12345 is their unique user-ID ).

Thing is, it would be great to allow for a full user registration and login experience via the plugin. Might also be interesting to try and dissable to part of the login form that is normally there ( so login with persona only, or something ) but that may be tricky if you want to always have a admin be able to manually log in...

m

shane-tomlinson commented 11 years ago

@micahwalter - If you try the latest dev version, I have taken a different approach to this. You go to the "registration" page, where it asks the user for their username and then asks them to verify their email address using Persona. Once the user verifies with Persona, it sends them to the profile. To see this in action, in Settings, you have to set "Disable non-Persona logins" to be checked.

shane-tomlinson commented 11 years ago

Closing since this feature is now added in v0.43