]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Refactor User_username object creation to reuse code
authorCraig Andrews <candrews@integralblue.com>
Fri, 13 Nov 2009 18:11:28 +0000 (13:11 -0500)
committerCraig Andrews <candrews@integralblue.com>
Fri, 13 Nov 2009 18:11:28 +0000 (13:11 -0500)
plugins/Authentication/AuthenticationPlugin.php
plugins/Authentication/User_username.php

index f061e456d1e65f36c512cdeae31ecc8426e3fcf0..a76848b04e09f5bb4fe4a0473b840a971e9de35c 100644 (file)
@@ -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;
                         }
                     }
index 79adeb1892dbf08c7788bb01292fba4c5bbbfe54..f30f60d839a6462bd706d49c1548188e827ba9ae 100644 (file)
@@ -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;
+        }
+    }
 }