/**
  * Internal AutoRegister event handler
  * @param nickname
  * @param provider_name
  * @param user - the newly registered user
  */
 function onAutoRegister($nickname, $provider_name, &$user)
 {
     if ($provider_name == $this->provider_name && $this->autoregistration) {
         $suggested_nickname = $this->suggestNicknameForUsername($nickname);
         $test_user = User::staticGet('nickname', $suggested_nickname);
         if ($test_user) {
             //someone already exists with the suggested nickname, so used the passed 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($nickname, $suggested_nickname);
             if ($user) {
                 User_username::register($user, $nickname, $this->provider_name);
                 return false;
             }
         }
     }
 }
Example #2
0
function common_url_to_nickname($url)
{
    static $bad = array('query', 'user', 'password', 'port', 'fragment');
    $parts = parse_url($url);
    # If any of these parts exist, this won't work
    foreach ($bad as $badpart) {
        if (array_key_exists($badpart, $parts)) {
            return null;
        }
    }
    # We just have host and/or path
    # If it's just a host...
    if (array_key_exists('host', $parts) && (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0)) {
        $hostparts = explode('.', $parts['host']);
        # Try to catch common idiom of nickname.service.tld
        if (count($hostparts) > 2 && strlen($hostparts[count($hostparts) - 2]) > 3 && strcmp($hostparts[0], 'www') != 0) {
            return common_nicknamize($hostparts[0]);
        } else {
            # Do the whole hostname
            return common_nicknamize($parts['host']);
        }
    } else {
        if (array_key_exists('path', $parts)) {
            # Strip starting, ending slashes
            $path = preg_replace('@/$@', '', $parts['path']);
            $path = preg_replace('@^/@', '', $path);
            $path = basename($path);
            if ($path) {
                return common_nicknamize($path);
            }
        }
    }
    return null;
}
Example #3
0
 public static function getActivityObjectNickname(ActivityObject $object, array $hints = array())
 {
     if ($object->poco) {
         if (!empty($object->poco->preferredUsername)) {
             return common_nicknamize($object->poco->preferredUsername);
         }
     }
     if (!empty($object->nickname)) {
         return common_nicknamize($object->nickname);
     }
     if (array_key_exists('nickname', $hints)) {
         return $hints['nickname'];
     }
     // Try the profile url (like foo.example.com or example.com/user/foo)
     if (!empty($object->link)) {
         $profileUrl = $object->link;
     } else {
         if (!empty($hints['profileurl'])) {
             $profileUrl = $hints['profileurl'];
         }
     }
     if (!empty($profileUrl)) {
         $nickname = self::nicknameFromURI($profileUrl);
     }
     // Try the URI (may be a tag:, http:, acct:, ...
     if (empty($nickname)) {
         $nickname = self::nicknameFromURI($object->id);
     }
     // Try a Webfinger if one was passed (way) down
     if (empty($nickname)) {
         if (array_key_exists('webfinger', $hints)) {
             $nickname = self::nicknameFromURI($hints['webfinger']);
         }
     }
     // Try the name
     if (empty($nickname)) {
         $nickname = common_nicknamize($object->title);
     }
     return $nickname;
 }
Example #4
0
 function nicknamize($str)
 {
     return common_nicknamize($str);
 }
Example #5
0
function common_url_to_nickname($url)
{
    static $bad = array('query', 'user', 'password', 'port', 'fragment');
    $parts = parse_url($url);
    // If any of these parts exist, this won't work
    foreach ($bad as $badpart) {
        if (array_key_exists($badpart, $parts)) {
            return null;
        }
    }
    // We just have host and/or path
    // If it's just a host...
    if (array_key_exists('host', $parts) && (!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0)) {
        $hostparts = explode('.', $parts['host']);
        // Try to catch common idiom of nickname.service.tld
        if (count($hostparts) > 2 && strlen($hostparts[count($hostparts) - 2]) > 3 && strcmp($hostparts[0], 'www') != 0) {
            return common_nicknamize($hostparts[0]);
        } else {
            // Do the whole hostname
            return common_nicknamize($parts['host']);
        }
    } else {
        if (array_key_exists('path', $parts)) {
            // Strip starting, ending slashes
            $path = preg_replace('@/$@', '', $parts['path']);
            $path = preg_replace('@^/@', '', $path);
            $path = basename($path);
            // Hack for MediaWiki user pages, in the form:
            // http://example.com/wiki/User:Myname
            // ('User' may be localized.)
            if (strpos($path, ':')) {
                $parts = array_filter(explode(':', $path));
                $path = $parts[count($parts) - 1];
            }
            if ($path) {
                return common_nicknamize($path);
            }
        }
    }
    return null;
}
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
$shortoptions = "e:";
$helptext = <<<END_OF_REGISTERBYEMAIL_HELP
USAGE: registerbyemail.php
Registers a new user by email address and sends a confirmation email

  -e email     Email to register

END_OF_REGISTERBYEMAIL_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$email = get_option_value('e', 'email');
$parts = explode('@', $email);
$nickname = common_nicknamize($parts[0]);
$user = User::getKV('nickname', $nickname);
if (!empty($user)) {
    $confirm = new Confirm_address();
    $confirm->user_id = $user->id;
    $confirm->address_type = 'email';
    if ($confirm->find(true)) {
        $url = common_local_url('confirmfirstemail', array('code' => $confirm->code));
        print "{$url}\n";
    } else {
        print "User not waiting for confirmation.\n";
    }
    exit;
}
$user = User::register(array('nickname' => $nickname, 'password' => null));
$confirm = new Confirm_address();
 function xriToNickname($xri)
 {
     $base = $this->xriBase($xri);
     if (!$base) {
         return null;
     } else {
         // =evan.prodromou
         // or @gratis*evan.prodromou
         $parts = explode('*', substr($base, 1));
         return common_nicknamize(array_pop($parts));
     }
 }
 function suggestNicknameForUsername($username)
 {
     $entry = $this->ldapCommon->get_user($username, $this->attributes);
     if (!$entry) {
         //this really shouldn't happen
         $nickname = $username;
     } else {
         $nickname = $entry->getValue($this->attributes['nickname'], 'single');
         if (!$nickname) {
             $nickname = $username;
         }
     }
     return common_nicknamize($nickname);
 }