/** * Show the registration form * * @return void */ function showFormContent() { $code = $this->trimmed('code'); $invite = null; if ($code) { $invite = Invitation::getKV($code); } if (common_config('site', 'inviteonly') && !($code && $invite)) { // TRANS: Client error displayed when trying to register to an invite-only site without an invitation. $this->clientError(_('Sorry, only invited people can register.')); } $this->elementStart('form', array('method' => 'post', 'id' => 'form_register', 'class' => 'form_settings', 'action' => common_local_url('register'))); $this->elementStart('fieldset'); // TRANS: Fieldset legend on accout registration page. $this->element('legend', null, 'Account settings'); $this->hidden('token', common_session_token()); if ($this->code) { $this->hidden('code', $this->code); } $this->elementStart('ul', 'form_data'); if (Event::handle('StartRegistrationFormData', array($this))) { $this->elementStart('li'); // TRANS: Field label on account registration page. $this->input('nickname', _('Nickname'), $this->trimmed('nickname'), _('1-64 lowercase letters or numbers, no punctuation or spaces.')); $this->elementEnd('li'); $this->elementStart('li'); // TRANS: Field label on account registration page. $this->password('password', _('Password'), _('6 or more characters.')); $this->elementEnd('li'); $this->elementStart('li'); // TRANS: Field label on account registration page. In this field the password has to be entered a second time. $this->password('confirm', _m('PASSWORD', 'Confirm'), _('Same as password above.')); $this->elementEnd('li'); $this->elementStart('li'); if ($this->invite && $this->invite->address_type == 'email') { // TRANS: Field label on account registration page. $this->input('email', _m('LABEL', 'Email'), $this->invite->address, _('Used only for updates, announcements, ' . 'and password recovery.')); } else { // TRANS: Field label on account registration page. $this->input('email', _m('LABEL', 'Email'), $this->trimmed('email'), _('Used only for updates, announcements, ' . 'and password recovery.')); } $this->elementEnd('li'); $this->elementStart('li'); // TRANS: Field label on account registration page. $this->input('fullname', _('Full name'), $this->trimmed('fullname'), _('Longer name, preferably your "real" name.')); $this->elementEnd('li'); $this->elementStart('li'); // TRANS: Field label on account registration page. $this->input('homepage', _('Homepage'), $this->trimmed('homepage'), _('URL of your homepage, blog, ' . 'or profile on another site.')); $this->elementEnd('li'); $this->elementStart('li'); $maxBio = Profile::maxBio(); if ($maxBio > 0) { // TRANS: Text area title in form for account registration. Plural // TRANS: is decided by the number of characters available for the // TRANS: biography (%d). $bioInstr = sprintf(_m('Describe yourself and your interests in %d character.', 'Describe yourself and your interests in %d characters.', $maxBio), $maxBio); } else { // TRANS: Text area title on account registration page. $bioInstr = _('Describe yourself and your interests.'); } // TRANS: Text area label on account registration page. $this->textarea('bio', _('Bio'), $this->trimmed('bio'), $bioInstr); $this->elementEnd('li'); $this->elementStart('li'); // TRANS: Field label on account registration page. $this->input('location', _('Location'), $this->trimmed('location'), _('Where you are, like "City, ' . 'State (or Region), Country".')); $this->elementEnd('li'); Event::handle('EndRegistrationFormData', array($this)); $this->elementStart('li', array('id' => 'settings_rememberme')); // TRANS: Checkbox label on account registration page. $this->checkbox('rememberme', _('Remember me'), $this->boolean('rememberme'), _('Automatically login in the future; ' . 'not for shared computers!')); $this->elementEnd('li'); $attrs = array('type' => 'checkbox', 'id' => 'license', 'class' => 'checkbox', 'name' => 'license', 'value' => 'true'); if ($this->boolean('license')) { $attrs['checked'] = 'checked'; } $this->elementStart('li'); $this->element('input', $attrs); $this->elementStart('label', array('class' => 'checkbox', 'for' => 'license')); $this->raw($this->licenseCheckbox()); $this->elementEnd('label'); $this->elementEnd('li'); } $this->elementEnd('ul'); // TRANS: Button text to register a user on account registration page. $this->submit('submit', _m('BUTTON', 'Register')); $this->elementEnd('fieldset'); $this->elementEnd('form'); }
public function onRouterInitialized($m) { $m->connect('api/qvitter/check_email.json', array('action' => 'ApiQvitterCheckEmail')); $m->connect('api/qvitter/:nickname/lists/:id/subscribers.json', array('action' => 'ApiQvitterListSubscribers', 'nickname' => '[a-zA-Z0-9]+', 'id' => '[a-zA-Z0-9]+')); $m->connect('api/qvitter/:nickname/lists/:id/members.json', array('action' => 'ApiQvitterListMembers', 'nickname' => '[a-zA-Z0-9]+', 'id' => '[a-zA-Z0-9]+')); $m->connect('api/qvitter/:nickname/lists/:id/statuses.json', array('action' => 'ApiQvitterTimelineList', 'nickname' => '[a-zA-Z0-9]+', 'id' => '[a-zA-Z0-9]+')); $m->connect('api/qvitter/blocks.json', array('action' => 'ApiQvitterBlocks')); $m->connect('api/qvitter/hello.json', array('action' => 'ApiQvitterHello')); $m->connect('api/qvitter/mark_all_notifications_as_seen.json', array('action' => 'ApiQvitterMarkAllNotificationsAsSeen')); $m->connect('api/qvitter/favs_and_repeats/:notice_id.json', array('action' => 'ApiFavsAndRepeats'), array('notice_id' => '[0-9]+')); $m->connect('api/statuses/public_and_external_timeline.:format', array('action' => 'ApiTimelinePublicAndExternal', 'format' => '(xml|json|rss|atom|as)')); $m->connect('api/qvitter/update_bookmarks.json', array('action' => 'ApiQvitterUpdateBookmarks')); $m->connect('api/qvitter/set_profile_pref.json', array('action' => 'ApiQvitterSetProfilePref')); $m->connect('api/qvitter/update_link_color.json', array('action' => 'apiqvitterupdatelinkcolor')); $m->connect('api/qvitter/update_background_color.json', array('action' => 'apiqvitterupdatebackgroundcolor')); $m->connect('api/qvitter/checklogin.json', array('action' => 'apiqvitterchecklogin')); $m->connect('api/qvitter/allfollowing/:id.json', array('action' => 'apiqvitterallfollowing', 'id' => Nickname::INPUT_FMT)); $m->connect('api/qvitter/update_cover_photo.json', array('action' => 'ApiUpdateCoverPhoto')); $m->connect('api/qvitter/update_background_image.json', array('action' => 'ApiUpdateBackgroundImage')); $m->connect('api/qvitter/update_avatar.json', array('action' => 'ApiUpdateAvatar')); $m->connect('api/qvitter/upload_image.json', array('action' => 'ApiUploadImage')); $m->connect('api/qvitter/external_user_show.json', array('action' => 'ApiExternalUserShow')); $m->connect('api/qvitter/toggle_qvitter.json', array('action' => 'ApiToggleQvitter')); $m->connect('api/qvitter/statuses/notifications.json', array('action' => 'apiqvitternotifications')); $m->connect(':nickname/notifications', array('action' => 'qvitter', 'nickname' => Nickname::INPUT_FMT)); $m->connect('settings/qvitter', array('action' => 'qvittersettings')); $m->connect('panel/qvitter', array('action' => 'qvitteradminsettings')); $m->connect('main/qlogin', array('action' => 'qvitterlogin')); URLMapperOverwrite::overwrite_variable($m, 'api/statuses/update.:format', array('action' => 'ApiStatusesUpdate'), array('format' => '(xml|json)'), 'ApiQvitterStatusesUpdate'); // check if we should reroute UI to qvitter, and which home-stream the user wants (hide-replies or normal) $scoped = Profile::current(); $qvitter_enabled_by_user = 0; $qvitter_disabled_by_user = 0; if ($scoped instanceof Profile) { $qvitter_enabled_by_user = (int) $scoped->getPref('qvitter', 'enable_qvitter', false); $qvitter_disabled_by_user = (int) $scoped->getPref('qvitter', 'disable_qvitter', false); $this->qvitter_hide_replies = $scoped->getPref('qvitter', 'hide_replies', false); } // reroute to qvitter if we're logged out and qvitter is enabled by default if (static::settings('enabledbydefault') === true && is_null($scoped)) { $this->hijack_ui = true; } elseif (static::settings('enabledbydefault') === true && $qvitter_disabled_by_user == 0) { $this->hijack_ui = true; } elseif (static::settings('enabledbydefault') === false && $qvitter_enabled_by_user == 1) { $this->hijack_ui = true; } if ($this->hijack_ui === true) { // other plugins might want to reroute to qvitter Event::handle('QvitterHijackUI', array($m)); $m->connect('', array('action' => 'qvitter')); $m->connect('main/all', array('action' => 'qvitter')); $m->connect('main/public', array('action' => 'qvitter')); $m->connect('search/notice', array('action' => 'qvitter')); // if the user wants the twitter style home stream with hidden replies to non-friends if ($this->qvitter_hide_replies == 1) { URLMapperOverwrite::overwrite_variable($m, 'api/statuses/friends_timeline.:format', array('action' => 'ApiTimelineFriends'), array('format' => '(xml|json|rss|atom|as)'), 'ApiTimelineFriendsHiddenReplies'); } URLMapperOverwrite::overwrite_variable($m, ':nickname', array('action' => 'showstream'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/', array('action' => 'showstream'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/all', array('action' => 'all'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/subscriptions', array('action' => 'subscriptions'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/subscribers', array('action' => 'subscribers'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/groups', array('action' => 'usergroups'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/replies', array('action' => 'replies'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/favorites', array('action' => 'showfavorites'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'group/:nickname', array('action' => 'showgroup'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'group/:nickname/members', array('action' => 'groupmembers'), array('nickname' => Nickname::DISPLAY_FMT), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':nickname/all/:tag', array('action' => 'showprofiletag'), array('nickname' => Nickname::DISPLAY_FMT, 'tag' => Router::REGEX_TAG), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':tagger/all/:tag/tagged', array('action' => 'peopletagged'), array('tagger' => Nickname::DISPLAY_FMT, 'tag' => Router::REGEX_TAG), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, ':tagger/all/:tag/subscribers', array('action' => 'peopletagsubscribers'), array('tagger' => Nickname::DISPLAY_FMT, 'tag' => Router::REGEX_TAG), 'qvitter'); $m->connect('group/:nickname/admins', array('action' => 'qvitter'), array('nickname' => Nickname::DISPLAY_FMT)); URLMapperOverwrite::overwrite_variable($m, 'tag/:tag', array('action' => 'showstream'), array('tag' => Router::REGEX_TAG), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'notice/:notice', array('action' => 'shownotice'), array('notice' => '[0-9]+'), 'qvitter'); URLMapperOverwrite::overwrite_variable($m, 'conversation/:id', array('action' => 'conversation'), array('id' => '[0-9]+'), 'qvitter'); } // if qvitter is opt-out, disable the default register page (if we don't have a valid invitation code) $valid_code = isset($_POST['code']) ? Invitation::getKV('code', $_POST['code']) : null; if (self::settings('enabledbydefault') && empty($valid_code)) { $m->connect('main/register', array('action' => 'qvitter')); } // add user arrays for some urls, to use to build profile cards // this way we don't have to request this in a separate http request if (isset($_GET['withuserarray'])) { switch (getPath($_REQUEST)) { case 'api/statuses/followers.json': case 'api/statuses/friends.json': case 'api/statusnet/groups/list.json': case 'api/statuses/mentions.json': case 'api/favorites.json': case 'api/statuses/friends_timeline.json': case 'api/statuses/user_timeline.json': // add logged in user's user array if (common_logged_in() && !isset($_GET['screen_name']) && !isset($_GET['id'])) { $profilecurrent = Profile::current(); header('Qvitter-User-Array: ' . json_encode($this->qvitterTwitterUserArray($profilecurrent))); } elseif (isset($_GET['screen_name']) || isset($_GET['id'])) { if (isset($_GET['screen_name'])) { $user = User::getKV('nickname', $_GET['screen_name']); } elseif (isset($_GET['id'])) { $user = User::getKV('id', $_GET['id']); } if ($user instanceof User) { header('Qvitter-User-Array: ' . json_encode($this->qvitterTwitterUserArray($user->getProfile()))); } } break; } } }
function createNewUser() { // FIXME: save invite code before redirect, and check here if (!Event::handle('StartRegistrationTry', array($this))) { return; } if (common_config('site', 'closed')) { // TRANS: OpenID plugin message. No new user registration is allowed on the site. $this->clientError(_m('Registration not allowed.')); } $invite = null; if (common_config('site', 'inviteonly')) { $code = $_SESSION['invitecode']; if (empty($code)) { // TRANS: OpenID plugin message. No new user registration is allowed on the site without an invitation code, and none was provided. $this->clientError(_m('Registration not allowed.')); } $invite = Invitation::getKV($code); if (empty($invite)) { // TRANS: OpenID plugin message. No new user registration is allowed on the site without an invitation code, and the one provided was not valid. $this->clientError(_m('Not a valid invitation code.')); } } try { $nickname = Nickname::normalize($this->trimmed('newname'), true); } catch (NicknameException $e) { $this->showForm($e->getMessage()); return; } list($display, $canonical, $sreg) = $this->getSavedValues(); if (!$display || !$canonical) { // TRANS: OpenID plugin server error. A stored OpenID cannot be retrieved. $this->serverError(_m('Stored OpenID not found.')); } // Possible race condition... let's be paranoid $other = oid_get_user($canonical); if ($other) { // TRANS: OpenID plugin server error. $this->serverError(_m('Creating new account for OpenID that already has a user.')); } Event::handle('StartOpenIDCreateNewUser', array($canonical, &$sreg)); $location = ''; if (!empty($sreg['country'])) { if ($sreg['postcode']) { // XXX: use postcode to get city and region // XXX: also, store postcode somewhere -- it's valuable! $location = $sreg['postcode'] . ', ' . $sreg['country']; } else { $location = $sreg['country']; } } if (!empty($sreg['fullname']) && mb_strlen($sreg['fullname']) <= 255) { $fullname = $sreg['fullname']; } else { $fullname = ''; } $email = $this->getEmail(); // XXX: add language // XXX: add timezone $args = array('nickname' => $nickname, 'email' => $email, 'fullname' => $fullname, 'location' => $location); if (!empty($invite)) { $args['code'] = $invite->code; } $user = User::register($args); $result = oid_link_user($user->id, $canonical, $display); Event::handle('EndOpenIDCreateNewUser', array($user, $canonical, $sreg)); oid_set_last($display); common_set_user($user); common_real_login(true); if (isset($_SESSION['openid_rememberme']) && $_SESSION['openid_rememberme']) { common_rememberme($user); } unset($_SESSION['openid_rememberme']); Event::handle('EndRegistrationTry', array($this)); common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), 303); }
function createNewUser() { if (!Event::handle('StartRegistrationTry', array($this))) { return; } if (common_config('site', 'closed')) { // TRANS: Client error trying to register with registrations not allowed. $this->clientError(_m('Registration not allowed.')); } $invite = null; if (common_config('site', 'inviteonly')) { $code = $_SESSION['invitecode']; if (empty($code)) { // TRANS: Client error trying to register with registrations 'invite only'. $this->clientError(_m('Registration not allowed.')); } $invite = Invitation::getKV($code); if (empty($invite)) { // TRANS: Client error trying to register with an invalid invitation code. $this->clientError(_m('Not a valid invitation code.')); } } try { $nickname = Nickname::normalize($this->trimmed('newname'), true); } catch (NicknameException $e) { $this->showForm($e->getMessage()); return; } $args = array('nickname' => $nickname, 'fullname' => $this->fbuser->name, 'homepage' => $this->fbuser->website, 'location' => $this->fbuser->location->name); // It's possible that the email address is already in our // DB. It's a unique key, so we need to check if ($this->isNewEmail($this->fbuser->email)) { $args['email'] = $this->fbuser->email; if (isset($this->fuser->verified) && $this->fuser->verified == true) { $args['email_confirmed'] = true; } } if (!empty($invite)) { $args['code'] = $invite->code; } $user = User::register($args); $result = $this->flinkUser($user->id, $this->fbuid); if (!$result) { // TRANS: Server error displayed when connecting to Facebook fails. $this->serverError(_m('Error connecting user to Facebook.')); } // Add a Foreign_user record Facebookclient::addFacebookUser($this->fbuser); $this->setAvatar($user); common_set_user($user); common_real_login(true); common_log(LOG_INFO, sprintf('Registered new user %s (%d) from Facebook user %s, (fbuid %d)', $user->nickname, $user->id, $this->fbuser->name, $this->fbuid), __FILE__); Event::handle('EndRegistrationTry', array($this)); $this->goHome($user->nickname); }
function prepare($argarray) { parent::prepare($argarray); if (common_config('site', 'closed')) { // TRANS: Client exception trown when registration by e-mail is not allowed. throw new ClientException(_m('Registration not allowed.'), 403); } if ($this->isPost()) { $this->checkSessionToken(); $this->email = $this->trimmed('email'); if (!empty($this->email)) { if (common_config('site', 'inviteonly')) { // TRANS: Client exception trown when trying to register without an invitation. throw new ClientException(_m('Sorry, only invited people can register.'), 403); } $this->email = common_canonical_email($this->email); $this->state = self::NEWEMAIL; } else { $this->state = self::SETPASSWORD; $this->code = $this->trimmed('code'); if (empty($this->code)) { // TRANS: Client exception thrown when no confirmation code was provided. throw new ClientException(_m('No confirmation code.')); } $this->invitation = Invitation::getKV('code', $this->code); if (!empty($this->invitation)) { if (!empty($this->invitation->registered_user_id)) { // TRANS: Client exception trown when using an invitation multiple times. throw new ClientException(_m('Invitation already used.'), 403); } } else { $this->confirmation = Confirm_address::getKV('code', $this->code); if (empty($this->confirmation)) { // TRANS: Client exception thrown when given confirmation code was not issued. throw new ClientException(_m('No such confirmation code.'), 403); } } $this->nickname = Nickname::normalize($this->trimmed('nickname')); $this->password1 = $this->trimmed('password1'); $this->password2 = $this->trimmed('password2'); $this->tos = $this->boolean('tos'); } } else { // GET $this->code = $this->trimmed('code'); if (empty($this->code)) { if (common_config('site', 'inviteonly')) { // TRANS: Client exception trown when trying to register without an invitation. throw new ClientException(_m('Sorry, only invited people can register.'), 403); } $this->state = self::NEWREGISTER; } else { $this->invitation = Invitation::getKV('code', $this->code); if (!empty($this->invitation)) { if (!empty($this->invitation->registered_user_id)) { // TRANS: Client exception trown when using an invitation multiple times. throw new ClientException(_m('Invitation already used.'), 403); } $this->state = self::CONFIRMINVITE; } else { $this->state = self::CONFIRMREGISTER; $this->confirmation = Confirm_address::getKV('code', $this->code); if (empty($this->confirmation)) { // TRANS: Client exception thrown when given confirmation code was not issued. throw new ClientException(_m('No such confirmation code.'), 405); } } } } return true; }
/** * Register a new user account and profile and set up default subscriptions. * If a new-user welcome message is configured, this will be sent. * * @param array $fields associative array of optional properties * string 'bio' * string 'email' * bool 'email_confirmed' pass true to mark email as pre-confirmed * string 'fullname' * string 'homepage' * string 'location' informal string description of geolocation * float 'lat' decimal latitude for geolocation * float 'lon' decimal longitude for geolocation * int 'location_id' geoname identifier * int 'location_ns' geoname namespace to interpret location_id * string 'nickname' REQUIRED * string 'password' (may be missing for eg OpenID registrations) * string 'code' invite code * ?string 'uri' permalink to notice; defaults to local notice URL * @return User object * @throws Exception on failure */ static function register(array $fields) { // MAGICALLY put fields into current scope extract($fields); $profile = new Profile(); if (!empty($email)) { $email = common_canonical_email($email); } // Normalize _and_ check whether it is in use. Throw NicknameException on failure. $profile->nickname = Nickname::normalize($nickname, true); $profile->profileurl = common_profile_url($profile->nickname); if (!empty($fullname)) { $profile->fullname = $fullname; } if (!empty($homepage)) { $profile->homepage = $homepage; } if (!empty($bio)) { $profile->bio = $bio; } if (!empty($location)) { $profile->location = $location; $loc = Location::fromName($location); if (!empty($loc)) { $profile->lat = $loc->lat; $profile->lon = $loc->lon; $profile->location_id = $loc->location_id; $profile->location_ns = $loc->location_ns; } } $profile->created = common_sql_now(); $user = new User(); $user->nickname = $profile->nickname; $invite = null; // Users who respond to invite email have proven their ownership of that address if (!empty($code)) { $invite = Invitation::getKV($code); if ($invite instanceof Invitation && $invite->address && $invite->address_type == 'email' && $invite->address == $email) { $user->email = $invite->address; } } if (isset($email_confirmed) && $email_confirmed) { $user->email = $email; } // Set default-on options here, otherwise they'll be disabled // initially for sites using caching, since the initial encache // doesn't know about the defaults in the database. $user->emailnotifysub = 1; $user->emailnotifynudge = 1; $user->emailnotifymsg = 1; $user->emailnotifyattn = 1; $user->emailmicroid = 1; $user->emailpost = 1; $user->jabbermicroid = 1; $user->created = common_sql_now(); if (Event::handle('StartUserRegister', array($profile))) { $profile->query('BEGIN'); $id = $profile->insert(); if ($id === false) { common_log_db_error($profile, 'INSERT', __FILE__); $profile->query('ROLLBACK'); // TRANS: Profile data could not be inserted for some reason. throw new ServerException(_m('Could not insert profile data for new user.')); } $user->id = $id; if (!empty($uri)) { $user->uri = $uri; } else { $user->uri = common_user_uri($user); } if (!empty($password)) { // may not have a password for OpenID users $user->password = common_munge_password($password, $id); } $result = $user->insert(); if ($result === false) { common_log_db_error($user, 'INSERT', __FILE__); $profile->query('ROLLBACK'); // TRANS: User data could not be inserted for some reason. throw new ServerException(_m('Could not insert user data for new user.')); } // Everyone is subscribed to themself $subscription = new Subscription(); $subscription->subscriber = $user->id; $subscription->subscribed = $user->id; $subscription->created = $user->created; $result = $subscription->insert(); if (!$result) { common_log_db_error($subscription, 'INSERT', __FILE__); $profile->query('ROLLBACK'); // TRANS: Subscription data could not be inserted for some reason. throw new ServerException(_m('Could not insert subscription data for new user.')); } // Mark that this invite was converted if (!empty($invite)) { $invite->convert($user); } if (!empty($email) && !$user->email) { $confirm = new Confirm_address(); $confirm->code = common_confirmation_code(128); $confirm->user_id = $user->id; $confirm->address = $email; $confirm->address_type = 'email'; $result = $confirm->insert(); if (!$result) { common_log_db_error($confirm, 'INSERT', __FILE__); $profile->query('ROLLBACK'); // TRANS: Email confirmation data could not be inserted for some reason. throw new ServerException(_m('Could not insert email confirmation data for new user.')); } } if (!empty($code) && $user->email) { $user->emailChanged(); } // Default system subscription $defnick = common_config('newuser', 'default'); if (!empty($defnick)) { $defuser = User::getKV('nickname', $defnick); if (empty($defuser)) { common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick), __FILE__); } else { Subscription::ensureStart($profile, $defuser->getProfile()); } } $profile->query('COMMIT'); if (!empty($email) && !$user->email) { mail_confirm_address($user, $confirm->code, $profile->nickname, $email); } // Welcome message $welcome = common_config('newuser', 'welcome'); if (!empty($welcome)) { $welcomeuser = User::getKV('nickname', $welcome); if (empty($welcomeuser)) { common_log(LOG_WARNING, sprintf("Welcome user %s does not exist.", $defnick), __FILE__); } else { $notice = Notice::saveNew($welcomeuser->id, sprintf(_('Welcome to %1$s, @%2$s!'), common_config('site', 'name'), $user->nickname), 'system'); } } Event::handle('EndUserRegister', array($profile)); } if (!$user instanceof User) { throw new ServerException('User could not be registered. Probably an event hook that failed.'); } return $user; }
/** * Handle the request * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $nickname = $this->trimmed('nickname'); $email = $this->trimmed('email'); $fullname = $this->trimmed('fullname'); $homepage = $this->trimmed('homepage'); $bio = $this->trimmed('bio'); $location = $this->trimmed('location'); // We don't trim these... whitespace is OK in a password! $password = $this->arg('password'); $confirm = $this->arg('confirm'); if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { // TRANS: Client error displayed when trying to register to an invite-only site without an invitation. $this->clientError(_('Sorry, only invited people can register.'), 401); } if (!empty($this->code)) { $this->invite = Invitation::getKV('code', $this->code); if (empty($this->invite)) { // TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation. $this->clientError(_('Sorry, invalid invitation code.'), 401); } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } // Input scrubbing try { $nickname = Nickname::normalize($nickname, true); } catch (NicknameException $e) { // clientError handles Api exceptions with various formats and stuff $this->clientError($e->getMessage(), $e->getCode()); } $email = common_canonical_email($email); if ($email && !Validate::email($email, common_config('email', 'check_domain'))) { // TRANS: Form validation error displayed when trying to register without a valid e-mail address. $this->clientError(_('Not a valid email address.'), 400); } else { if ($this->emailExists($email)) { // TRANS: Form validation error displayed when trying to register with an already registered e-mail address. $this->clientError(_('Email address already exists.'), 400); } else { if (!is_null($homepage) && strlen($homepage) > 0 && !common_valid_http_url($homepage)) { // TRANS: Form validation error displayed when trying to register with an invalid homepage URL. $this->clientError(_('Homepage is not a valid URL.'), 400); } else { if (!is_null($fullname) && mb_strlen($fullname) > 255) { // TRANS: Form validation error displayed when trying to register with a too long full name. $this->clientError(_('Full name is too long (maximum 255 characters).'), 400); } else { if (Profile::bioTooLong($bio)) { // TRANS: Form validation error on registration page when providing too long a bio text. // TRANS: %d is the maximum number of characters for bio; used for plural. $this->clientError(sprintf(_m('Bio is too long (maximum %d character).', 'Bio is too long (maximum %d characters).', Profile::maxBio()), Profile::maxBio()), 400); } else { if (!is_null($location) && mb_strlen($location) > 255) { // TRANS: Form validation error displayed when trying to register with a too long location. $this->clientError(_('Location is too long (maximum 255 characters).'), 400); } else { if (strlen($password) < 6) { // TRANS: Form validation error displayed when trying to register with too short a password. $this->clientError(_('Password must be 6 or more characters.'), 400); } else { if ($password != $confirm) { // TRANS: Form validation error displayed when trying to register with non-matching passwords. $this->clientError(_('Passwords do not match.'), 400); } else { // annoy spammers sleep(7); try { $user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email, 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 'location' => $location, 'code' => $this->code)); Event::handle('EndRegistrationTry', array($this)); $this->initDocument('json'); $this->showJsonObjects($this->twitterUserArray($user->getProfile())); $this->endDocument('json'); } catch (Exception $e) { $this->clientError($e->getMessage(), 400); } } } } } } } } } }
function createNewUser() { if (!Event::handle('StartRegistrationTry', array($this))) { return; } if (common_config('site', 'closed')) { // TRANS: Client error displayed when trying to create a new user while creating new users is not allowed. $this->clientError(_m('Registration not allowed.')); } $invite = null; if (common_config('site', 'inviteonly')) { $code = $_SESSION['invitecode']; if (empty($code)) { // TRANS: Client error displayed when trying to create a new user while creating new users is not allowed. $this->clientError(_m('Registration not allowed.')); } $invite = Invitation::getKV($code); if (empty($invite)) { // TRANS: Client error displayed when trying to create a new user with an invalid invitation code. $this->clientError(_m('Not a valid invitation code.')); } } try { $nickname = Nickname::normalize($this->trimmed('newname'), true); } catch (NicknameException $e) { $this->showForm($e->getMessage()); return; } $fullname = trim($this->tw_fields['fullname']); $args = array('nickname' => $nickname, 'fullname' => $fullname); if (!empty($invite)) { $args['code'] = $invite->code; } $email = $this->getEmail(); if (!empty($email)) { $args['email'] = $email; } try { $user = User::register($args); } catch (Exception $e) { $this->serverError($e->getMessage()); } $result = $this->saveForeignLink($user->id, $this->twuid, $this->access_token); save_twitter_user($this->twuid, $this->tw_fields['screen_name']); if (!$result) { // TRANS: Server error displayed when connecting a user to a Twitter user has failed. $this->serverError(_m('Error connecting user to Twitter.')); } common_set_user($user); common_real_login(true); common_debug('TwitterBridge Plugin - ' . "Registered new user {$user->id} from Twitter user {$this->twuid}"); Event::handle('EndRegistrationTry', array($this)); common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), 303); }
protected function createNewUser() { common_debug('TwitterBridgeDebug - createNewUser'); if (!Event::handle('StartRegistrationTry', array($this))) { common_debug('TwitterBridgeDebug - StartRegistrationTry failed'); // TRANS: Client error displayed when trying to create a new user but a plugin aborted the process. throw new ClientException(_m('Registration of new user was aborted, maybe you failed a captcha?')); } if (common_config('site', 'closed')) { common_debug('TwitterBridgeDebug - site is closed for registrations'); // TRANS: Client error displayed when trying to create a new user while creating new users is not allowed. throw new ClientException(_m('Registration not allowed.')); } $invite = null; if (common_config('site', 'inviteonly')) { common_debug('TwitterBridgeDebug - site is inviteonly'); $code = $_SESSION['invitecode']; if (empty($code)) { // TRANS: Client error displayed when trying to create a new user while creating new users is not allowed. throw new ClientException(_m('Registration not allowed.')); } $invite = Invitation::getKV('code', $code); if (!$invite instanceof Invite) { common_debug('TwitterBridgeDebug - and we failed the invite code test'); // TRANS: Client error displayed when trying to create a new user with an invalid invitation code. throw new ClientException(_m('Not a valid invitation code.')); } } common_debug('TwitterBridgeDebug - trying our nickname: ' . $this->trimmed('newname')); // Nickname::normalize throws exception if the nickname is taken $nickname = Nickname::normalize($this->trimmed('newname'), true); $fullname = trim($this->tw_fields['fullname']); $args = array('nickname' => $nickname, 'fullname' => $fullname); if (!empty($invite)) { $args['code'] = $invite->code; } $email = $this->getEmail(); if (!empty($email)) { $args['email'] = $email; } common_debug('TwitterBridgeDebug - registering user with args:' . var_export($args, true)); $user = User::register($args); common_debug('TwitterBridgeDebug - registered the user and saving foreign link for ' . $user->id); $this->saveForeignLink($user->id, $this->twuid, $this->access_token); common_debug('TwitterBridgeDebug - saving twitter user after creating new local user ' . $user->id); save_twitter_user($this->twuid, $this->tw_fields['screen_name']); common_set_user($user); common_real_login(true); common_debug('TwitterBridge Plugin - ' . "Registered new user {$user->id} from Twitter user {$this->twuid}"); Event::handle('EndRegistrationTry', array($this)); common_redirect(common_local_url('showstream', array('nickname' => $user->nickname)), 303); }