]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/authenticationplugin.php
Merge branch 'master' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / lib / authenticationplugin.php
index 17237086c4f025cf0cd6e876e5d577d8d731652a..dbdf206298de4653b7f4a6eda078c8b88a24ae26 100644 (file)
@@ -22,6 +22,7 @@
  * @category  Plugin
  * @package   StatusNet
  * @author    Craig Andrews <candrews@integralblue.com>
+ * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -69,13 +70,17 @@ 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
+    * @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)
     */
-    function autoRegister($username)
+    function autoRegister($username, $nickname = null)
     {
+        if(is_null($nickname)){
+            $nickname = $username;
+        }
         $registration_data = array();
-        $registration_data['nickname'] = $username ;
+        $registration_data['nickname'] = $nickname;
         return User::register($registration_data);
     }
 
@@ -97,12 +102,14 @@ abstract class AuthenticationPlugin extends Plugin
     * Used during autoregistration
     * Useful if your usernames are ugly, and you want to suggest
     * nice looking nicknames when users initially sign on
+    * All nicknames returned by this function should be valid
+    *  implementations may want to use common_nicknamize() to ensure validity
     * @param username
     * @return string nickname
     */
     function suggestNicknameForUsername($username)
     {
-        return $username;
+        return common_nicknamize($username);
     }
 
     //------------Below are the methods that connect StatusNet to the implementing Auth plugin------------\\
@@ -125,14 +132,14 @@ abstract class AuthenticationPlugin extends Plugin
             $test_user = User::staticGet('nickname', $suggested_nickname);
             if($test_user) {
                 //someone already exists with the suggested nickname, so used the passed nickname
-                $suggested_nickname = $nickname;
+                $suggested_nickname = common_nicknamize($nickname);
             }
             $test_user = User::staticGet('nickname', $suggested_nickname);
             if($test_user) {
                 //someone already exists with the suggested nickname
                 //not much else we can do
             }else{
-                $user = $this->autoregister($suggested_nickname);
+                $user = $this->autoRegister($nickname, $suggested_nickname);
                 if($user){
                     User_username::register($user,$nickname,$this->provider_name);
                     return false;