From b9562cbb18a7b8f3f01bcbc8540933c4dfc10fb9 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 13 Nov 2009 12:54:27 -0500 Subject: autoregister returns the new user on success (not just true) --- plugins/Authentication/AuthenticationPlugin.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'plugins') diff --git a/plugins/Authentication/AuthenticationPlugin.php b/plugins/Authentication/AuthenticationPlugin.php index 99b61b808..f061e456d 100644 --- a/plugins/Authentication/AuthenticationPlugin.php +++ b/plugins/Authentication/AuthenticationPlugin.php @@ -70,7 +70,7 @@ abstract class AuthenticationPlugin extends Plugin * Automatically register a user when they attempt to login with valid credentials. * User::register($data) is a very useful method for this implementation * @param username - * @return boolean true if the user was created, false if not + * @return mixed instance of User, or false (if user couldn't be created) */ function autoRegister($username) { @@ -134,15 +134,18 @@ abstract class AuthenticationPlugin extends Plugin }else{ if($this->autoregistration){ $authenticated = $this->checkPassword($nickname, $password); - if($authenticated && $this->autoregister($nickname)){ - $authenticatedUser = User::staticGet('nickname', $nickname); - $user_username = new User_username(); - $user_username->user_id = $authenticatedUser->id; - $user_username->provider_name = $this->provider_name; - $user_username->username = $nickname; - $user_username->created = DB_DataObject_Cast::dateTime(); - $user_username->insert(); - return false; + if($authenticated){ + $user = $this->autoregister($nickname); + if($user){ + $authenticatedUser = $user; + $user_username = new User_username(); + $user_username->user_id = $authenticatedUser->id; + $user_username->provider_name = $this->provider_name; + $user_username->username = $nickname; + $user_username->created = DB_DataObject_Cast::dateTime(); + $user_username->insert(); + return false; + } } } } -- cgit v1.2.3-54-g00ecf From 5494eb61465595466b897fdd88efda250c1107e2 Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Fri, 13 Nov 2009 13:11:28 -0500 Subject: Refactor User_username object creation to reuse code --- plugins/Authentication/AuthenticationPlugin.php | 14 ++------------ plugins/Authentication/User_username.php | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) (limited to 'plugins') diff --git a/plugins/Authentication/AuthenticationPlugin.php b/plugins/Authentication/AuthenticationPlugin.php index f061e456d..a76848b04 100644 --- a/plugins/Authentication/AuthenticationPlugin.php +++ b/plugins/Authentication/AuthenticationPlugin.php @@ -122,12 +122,7 @@ abstract class AuthenticationPlugin extends Plugin $authenticated = $this->checkPassword($nickname, $password); if($authenticated){ $authenticatedUser = User::staticGet('nickname', $nickname); - $user_username = new User_username(); - $user_username->user_id = $authenticatedUser->id; - $user_username->provider_name = $this->provider_name; - $user_username->username = $nickname; - $user_username->created = DB_DataObject_Cast::dateTime(); - $user_username->insert(); + User_username::register($authenticatedUser,$nickname,$this->provider_name); return false; } } @@ -138,12 +133,7 @@ abstract class AuthenticationPlugin extends Plugin $user = $this->autoregister($nickname); if($user){ $authenticatedUser = $user; - $user_username = new User_username(); - $user_username->user_id = $authenticatedUser->id; - $user_username->provider_name = $this->provider_name; - $user_username->username = $nickname; - $user_username->created = DB_DataObject_Cast::dateTime(); - $user_username->insert(); + User_username::register($authenticatedUser,$nickname,$this->provider_name); return false; } } diff --git a/plugins/Authentication/User_username.php b/plugins/Authentication/User_username.php index 79adeb189..f30f60d83 100644 --- a/plugins/Authentication/User_username.php +++ b/plugins/Authentication/User_username.php @@ -22,4 +22,25 @@ class User_username extends Memcached_DataObject /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE + + /** + * Register a user with a username on a given provider + * @param User User object + * @param string username on the given provider + * @param provider_name string name of the provider + * @return mixed User_username instance if the registration succeeded, false if it did not + */ + static function register($user, $username, $provider_name) + { + $user_username = new User_username(); + $user_username->user_id = $user->id; + $user_username->provider_name = $provider_name; + $user_username->username = $username; + $user_username->created = DB_DataObject_Cast::dateTime(); + if($user_username->insert()){ + return $user_username; + }else{ + return false; + } + } } -- cgit v1.2.3-54-g00ecf