]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/register.php
XMPP sub/unsub and help commands
[quix0rs-gnu-social.git] / actions / register.php
index 76e6ede5541e00d2b5d103599631dda1839da96a..e6b1931cef6de26752c7d9bbd1ed7abfaba02146 100644 (file)
@@ -24,7 +24,9 @@ class RegisterAction extends Action {
        function handle($args) {
                parent::handle($args);
 
-               if (common_logged_in()) {
+               if (common_config('site', 'closed')) {
+                       common_user_error(_('Registration not allowed.'));
+               } else if (common_logged_in()) {
                        common_user_error(_('Already logged in.'));
                } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
                        $this->try_register();
@@ -80,7 +82,9 @@ class RegisterAction extends Action {
                        return;
                } else if ($password != $confirm) {
                        $this->show_form(_('Passwords don\'t match.'));
-               } else if ($user = $this->register_user($nickname, $password, $email, $fullname, $homepage, $bio, $location)) {
+               } else if ($user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email,
+                                                                                               'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 
+                                                                                               'location' => $location))) {
                        if (!$user) {
                                $this->show_form(_('Invalid username or password.'));
                                return;
@@ -96,6 +100,8 @@ class RegisterAction extends Action {
                                common_debug('Adding rememberme cookie for ' . $nickname);
                                common_rememberme($user);
                        }
+                       # Re-init language env in case it changed (not yet, but soon)
+                       common_init_language();
                        $this->show_success();
                } else {
                        $this->show_form(_('Invalid username or password.'));
@@ -117,74 +123,6 @@ class RegisterAction extends Action {
                return ($user !== false);
        }
 
-       function register_user($nickname, $password, $email, $fullname, $homepage, $bio, $location) {
-
-               $profile = new Profile();
-
-               $profile->query('BEGIN');
-
-               $profile->nickname = $nickname;
-               $profile->profileurl = common_profile_url($nickname);
-               if ($fullname) {
-                       $profile->fullname = $fullname;
-               }
-               if ($homepage) {
-                       $profile->homepage = $homepage;
-               }
-               if ($bio) {
-                       $profile->bio = $bio;
-               }
-               if ($location) {
-                       $profile->location = $location;
-               }
-               $profile->created = DB_DataObject_Cast::dateTime(); # current time
-               
-               $id = $profile->insert();
-
-               if (!$id) {
-                       common_log_db_error($profile, 'INSERT', __FILE__);
-                   return FALSE;
-               }
-               $user = new User();
-               $user->id = $id;
-               $user->nickname = $nickname;
-               $user->password = common_munge_password($password, $id);
-               $user->created =  DB_DataObject_Cast::dateTime(); # current time
-               $user->uri = common_user_uri($user);
-
-               $result = $user->insert();
-
-               if (!$result) {
-                       common_log_db_error($user, 'INSERT', __FILE__);
-                       return FALSE;
-               }
-
-               if ($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__);
-                               return FALSE;
-                       }
-               }
-
-               $profile->query('COMMIT');
-
-               if ($email) {
-                       mail_confirm_address($confirm->code,
-                                                                $profile->nickname,
-                                                                $email);
-               }
-
-               return $user;
-       }
-
        function show_top($error=NULL) {
                if ($error) {
                        common_element('p', 'error', $error);
@@ -225,10 +163,14 @@ class RegisterAction extends Action {
                                                $this->boolean('rememberme'),
                                _('Automatically login in the future; not for shared computers!'));
                common_element_start('p');
-               common_element('input', array('type' => 'checkbox',
-                                                                         'id' => 'license',
-                                                                         'name' => 'license',
-                                                                         'value' => ($this->boolean('license')) ? 'true' : 'false'));
+               $attrs = array('type' => 'checkbox',
+                                          'id' => 'license',
+                                          'name' => 'license',
+                                          'value' => 'true');
+               if ($this->boolean('license')) {
+                       $attrs['checked'] = 'checked';
+               }
+               common_element('input', $attrs);
            common_text(_('My text and files are available under '));
                common_element('a', array(href => $config['license']['url']),
                                           $config['license']['title']);
@@ -243,21 +185,23 @@ class RegisterAction extends Action {
                $nickname = $this->arg('nickname');
                common_show_header(_('Registration successful'));
                common_element_start('div', 'success');
-               $instr = sprintf(_('Congratulations, %s! And welcome to %%site.name%%. From here, you may want to...' .
-                                                  '* Go to [your profile](%s) and post your first message.' .
-                                                  '* Add a [Jabber/GTalk address](%%action.imsettings%%) so you can send notices through instant messages.' .
-                                                  '* (Search for people)[%%action.peoplesearch%%] that you may know or that share your interests. ' .
-                                                  '* Update your [profile settings](%%action.profilesettings%%) to tell others more about you. ' .
-                                                  '* Read over the [online docs](%%doc.help%%) for features you may have missed. ' .
+               $instr = sprintf(_('Congratulations, %s! And welcome to %%%%site.name%%%%. From here, you may want to...'. "\n\n" .
+                                                  '* Go to [your profile](%s) and post your first message.' .  "\n" .
+                                                  '* Add a [Jabber/GTalk address](%%%%action.imsettings%%%%) so you can send notices through instant messages.' . "\n" .
+                                                  '* [Search for people](%%%%action.peoplesearch%%%%) that you may know or that share your interests. ' . "\n" .
+                                                  '* Update your [profile settings](%%%%action.profilesettings%%%%) to tell others more about you. ' . "\n" .
+                                                  '* Read over the [online docs](%%%%doc.help%%%%) for features you may have missed. ' . "\n\n" .
                                                   'Thanks for signing up and we hope you enjoy using this service.'),
                                                 $nickname, common_local_url('showstream', array('nickname' => $nickname)));
                common_raw(common_markup_to_html($instr));
                $have_email = $this->trimmed('email');
                if ($have_email) {
-                       $emailinstr = _t('(You should receive a message by email momentarily, with ' .
-                                                        'instructions on how to confirm your email address.)');
+                       $emailinstr = _('(You should receive a message by email momentarily, with ' .
+                                                       'instructions on how to confirm your email address.)');
                        common_raw(common_markup_to_html($emailinstr));
                }
+               common_element_end('div');
+               common_show_footer();
        }
                                                
 }