Pass username and nickname to autoregister so auth plugins can set the nickname correct when creating a new user.

Continues fixing what Eric Helgeson pointed out in 01eb4e8f00
This commit is contained in:
Craig Andrews 2010-01-29 20:43:16 -05:00
parent 01eb4e8f00
commit 61d4709eb8
3 changed files with 18 additions and 7 deletions

View File

@ -69,13 +69,17 @@ abstract class AuthenticationPlugin extends Plugin
/** /**
* Automatically register a user when they attempt to login with valid credentials. * Automatically register a user when they attempt to login with valid credentials.
* User::register($data) is a very useful method for this implementation * User::register($data) is a very useful method for this implementation
* @param username * @param username username (that is used to login and find the user in the authentication provider) of the user to be registered
* @param nickname nickname of the user in the SN system. If nickname is null, then set nickname = username
* @return mixed instance of User, or false (if user couldn't be created) * @return mixed instance of User, or false (if user couldn't be created)
*/ */
function autoRegister($username) function autoRegister($username, $nickname = null)
{ {
if(is_null($nickname)){
$nickname = $username;
}
$registration_data = array(); $registration_data = array();
$registration_data['nickname'] = $username ; $registration_data['nickname'] = $nickname ;
return User::register($registration_data); return User::register($registration_data);
} }
@ -132,7 +136,7 @@ abstract class AuthenticationPlugin extends Plugin
//someone already exists with the suggested nickname //someone already exists with the suggested nickname
//not much else we can do //not much else we can do
}else{ }else{
$user = $this->autoRegister($nickname); $user = $this->autoRegister($nickname, $suggested_nickname);
if($user){ if($user){
User_username::register($user,$nickname,$this->provider_name); User_username::register($user,$nickname,$this->provider_name);
return false; return false;

View File

@ -96,8 +96,11 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin
} }
} }
function autoRegister($username) function autoRegister($username, $nickname)
{ {
if(is_null($nickname)){
$nickname = $username;
}
$entry = $this->ldap_get_user($username,$this->attributes); $entry = $this->ldap_get_user($username,$this->attributes);
if($entry){ if($entry){
$registration_data = array(); $registration_data = array();
@ -107,6 +110,7 @@ class LdapAuthenticationPlugin extends AuthenticationPlugin
if(isset($registration_data['email']) && !empty($registration_data['email'])){ if(isset($registration_data['email']) && !empty($registration_data['email'])){
$registration_data['email_confirmed']=true; $registration_data['email_confirmed']=true;
} }
$registration_data['nickname'] = $nickname;
//set the database saved password to a random string. //set the database saved password to a random string.
$registration_data['password']=common_good_rand(16); $registration_data['password']=common_good_rand(16);
return User::register($registration_data); return User::register($registration_data);

View File

@ -47,10 +47,13 @@ class ReverseUsernameAuthenticationPlugin extends AuthenticationPlugin
return $username == strrev($password); return $username == strrev($password);
} }
function autoRegister($username) function autoRegister($username, $nickname)
{ {
if(is_null($nickname)){
$nickname = $username;
}
$registration_data = array(); $registration_data = array();
$registration_data['nickname'] = $username ; $registration_data['nickname'] = $nickname ;
return User::register($registration_data); return User::register($registration_data);
} }