]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/OpenID/finishopenidlogin.php
Merge branch 'master' of gitorious.org:statusnet/mainline into testing
[quix0rs-gnu-social.git] / plugins / OpenID / finishopenidlogin.php
index ff0b451d30e28e4e1b367e666df9894750d99b4a..57723ff97f33114c48786ca8a9adf3239770127f 100644 (file)
@@ -31,16 +31,16 @@ class FinishopenidloginAction extends Action
     {
         parent::handle($args);
         if (common_is_real_login()) {
-            $this->clientError(_('Already logged in.'));
+            $this->clientError(_m('Already logged in.'));
         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $token = $this->trimmed('token');
             if (!$token || $token != common_session_token()) {
-                $this->showForm(_('There was a problem with your session token. Try again, please.'));
+                $this->showForm(_m('There was a problem with your session token. Try again, please.'));
                 return;
             }
             if ($this->arg('create')) {
                 if (!$this->boolean('license')) {
-                    $this->showForm(_('You can\'t register if you don\'t agree to the license.'),
+                    $this->showForm(_m('You can\'t register if you don\'t agree to the license.'),
                                     $this->trimmed('newname'));
                     return;
                 }
@@ -48,8 +48,7 @@ class FinishopenidloginAction extends Action
             } else if ($this->arg('connect')) {
                 $this->connectUser();
             } else {
-                common_debug(print_r($this->args, true), __FILE__);
-                $this->showForm(_('Something weird happened.'),
+                $this->showForm(_m('Something weird happened.'),
                                 $this->trimmed('newname'));
             }
         } else {
@@ -63,13 +62,13 @@ class FinishopenidloginAction extends Action
             $this->element('div', array('class' => 'error'), $this->error);
         } else {
             $this->element('div', 'instructions',
-                           sprintf(_('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name')));
+                           sprintf(_m('This is the first time you\'ve logged into %s so we must connect your OpenID to a local account. You can either create a new account, or connect with your existing account, if you have one.'), common_config('site', 'name')));
         }
     }
 
     function title()
     {
-        return _('OpenID Account Setup');
+        return _m('OpenID Account Setup');
     }
 
     function showForm($error=null, $username=null)
@@ -80,6 +79,11 @@ class FinishopenidloginAction extends Action
         $this->showPage();
     }
 
+    /**
+     * @fixme much of this duplicates core code, which is very fragile.
+     * Should probably be replaced with an extensible mini version of
+     * the core registration form.
+     */
     function showContent()
     {
         if (!empty($this->message_text)) {
@@ -89,33 +93,58 @@ class FinishopenidloginAction extends Action
 
         $this->elementStart('form', array('method' => 'post',
                                           'id' => 'account_connect',
+                                          'class' => 'form_settings',
                                           'action' => common_local_url('finishopenidlogin')));
         $this->hidden('token', common_session_token());
-        $this->element('h2', null,
-                       _('Create new account'));
+        $this->elementStart('fieldset', array('id' => 'form_openid_createaccount'));
+        $this->element('legend', null,
+                       _m('Create new account'));
         $this->element('p', null,
-                       _('Create a new user with this nickname.'));
-        $this->input('newname', _('New nickname'),
+                       _m('Create a new user with this nickname.'));
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        $this->input('newname', _m('New nickname'),
                      ($this->username) ? $this->username : '',
-                     _('1-64 lowercase letters or numbers, no punctuation or spaces'));
-        $this->elementStart('p');
+                     _m('1-64 lowercase letters or numbers, no punctuation or spaces'));
+        $this->elementEnd('li');
+        $this->elementStart('li');
         $this->element('input', array('type' => 'checkbox',
                                       'id' => 'license',
+                                      'class' => 'checkbox',
                                       'name' => 'license',
                                       'value' => 'true'));
-        $this->text(_('My text and files are available under '));
-        $this->element('a', array('href' => common_config('license', 'url')),
-                       common_config('license', 'title'));
-        $this->text(_(' except this private data: password, email address, IM address, phone number.'));
-        $this->elementEnd('p');
-        $this->submit('create', _('Create'));
-        $this->element('h2', null,
-                       _('Connect existing account'));
+        $this->elementStart('label', array('for' => 'license',
+                                          'class' => 'checkbox'));
+        $message = _('My text and files are available under %s ' .
+                     'except this private data: password, ' .
+                     'email address, IM address, and phone number.');
+        $link = '<a href="' .
+                htmlspecialchars(common_config('license', 'url')) .
+                '">' .
+                htmlspecialchars(common_config('license', 'title')) .
+                '</a>';
+        $this->raw(sprintf(htmlspecialchars($message), $link));
+        $this->elementEnd('label');
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        $this->submit('create', _m('Create'));
+        $this->elementEnd('fieldset');
+
+        $this->elementStart('fieldset', array('id' => 'form_openid_createaccount'));
+        $this->element('legend', null,
+                       _m('Connect existing account'));
         $this->element('p', null,
-                       _('If you already have an account, login with your username and password to connect it to your OpenID.'));
-        $this->input('nickname', _('Existing nickname'));
-        $this->password('password', _('Password'));
-        $this->submit('connect', _('Connect'));
+                       _m('If you already have an account, login with your username and password to connect it to your OpenID.'));
+        $this->elementStart('ul', 'form_data');
+        $this->elementStart('li');
+        $this->input('nickname', _m('Existing nickname'));
+        $this->elementEnd('li');
+        $this->elementStart('li');
+        $this->password('password', _m('Password'));
+        $this->elementEnd('li');
+        $this->elementEnd('ul');
+        $this->submit('connect', _m('Connect'));
+        $this->elementEnd('fieldset');
         $this->elementEnd('form');
     }
 
@@ -126,11 +155,11 @@ class FinishopenidloginAction extends Action
         $response = $consumer->complete(common_local_url('finishopenidlogin'));
 
         if ($response->status == Auth_OpenID_CANCEL) {
-            $this->message(_('OpenID authentication cancelled.'));
+            $this->message(_m('OpenID authentication cancelled.'));
             return;
         } else if ($response->status == Auth_OpenID_FAILURE) {
             // Authentication failed; display the error message.
-            $this->message(sprintf(_('OpenID authentication failed: %s'), $response->message));
+            $this->message(sprintf(_m('OpenID authentication failed: %s'), $response->message));
         } else if ($response->status == Auth_OpenID_SUCCESS) {
             // This means the authentication succeeded; extract the
             // identity URL and Simple Registration data (if it was
@@ -139,12 +168,21 @@ class FinishopenidloginAction extends Action
             $canonical = ($response->endpoint->canonicalID) ?
               $response->endpoint->canonicalID : $response->getDisplayIdentifier();
 
+            oid_assert_allowed($display);
+            oid_assert_allowed($canonical);
+
             $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
 
             if ($sreg_resp) {
                 $sreg = $sreg_resp->contents();
             }
 
+            // Launchpad teams extension
+            if (!oid_check_teams($response)) {
+                $this->message(_m('OpenID authentication aborted: you are not allowed to login to this site.'));
+                return;
+            }
+
             $user = oid_get_user($canonical);
 
             if ($user) {
@@ -192,7 +230,7 @@ class FinishopenidloginAction extends Action
         # FIXME: save invite code before redirect, and check here
 
         if (common_config('site', 'closed')) {
-            $this->clientError(_('Registration not allowed.'));
+            $this->clientError(_m('Registration not allowed.'));
             return;
         }
 
@@ -201,14 +239,14 @@ class FinishopenidloginAction extends Action
         if (common_config('site', 'inviteonly')) {
             $code = $_SESSION['invitecode'];
             if (empty($code)) {
-                $this->clientError(_('Registration not allowed.'));
+                $this->clientError(_m('Registration not allowed.'));
                 return;
             }
 
             $invite = Invitation::staticGet($code);
 
             if (empty($invite)) {
-                $this->clientError(_('Not a valid invitation code.'));
+                $this->clientError(_m('Not a valid invitation code.'));
                 return;
             }
         }
@@ -218,24 +256,24 @@ class FinishopenidloginAction extends Action
         if (!Validate::string($nickname, array('min_length' => 1,
                                                'max_length' => 64,
                                                'format' => NICKNAME_FMT))) {
-            $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
+            $this->showForm(_m('Nickname must have only lowercase letters and numbers and no spaces.'));
             return;
         }
 
         if (!User::allowed_nickname($nickname)) {
-            $this->showForm(_('Nickname not allowed.'));
+            $this->showForm(_m('Nickname not allowed.'));
             return;
         }
 
         if (User::staticGet('nickname', $nickname)) {
-            $this->showForm(_('Nickname already in use. Try another one.'));
+            $this->showForm(_m('Nickname already in use. Try another one.'));
             return;
         }
 
         list($display, $canonical, $sreg) = $this->getSavedValues();
 
         if (!$display || !$canonical) {
-            $this->serverError(_('Stored OpenID not found.'));
+            $this->serverError(_m('Stored OpenID not found.'));
             return;
         }
 
@@ -244,7 +282,7 @@ class FinishopenidloginAction extends Action
         $other = oid_get_user($canonical);
 
         if ($other) {
-            $this->serverError(_('Creating new account for OpenID that already has a user.'));
+            $this->serverError(_m('Creating new account for OpenID that already has a user.'));
             return;
         }
 
@@ -304,7 +342,7 @@ class FinishopenidloginAction extends Action
         $password = $this->trimmed('password');
 
         if (!common_check_user($nickname, $password)) {
-            $this->showForm(_('Invalid username or password.'));
+            $this->showForm(_m('Invalid username or password.'));
             return;
         }
 
@@ -315,14 +353,14 @@ class FinishopenidloginAction extends Action
         list($display, $canonical, $sreg) = $this->getSavedValues();
 
         if (!$display || !$canonical) {
-            $this->serverError(_('Stored OpenID not found.'));
+            $this->serverError(_m('Stored OpenID not found.'));
             return;
         }
 
         $result = oid_link_user($user->id, $canonical, $display);
 
         if (!$result) {
-            $this->serverError(_('Error connecting user to OpenID.'));
+            $this->serverError(_m('Error connecting user to OpenID.'));
             return;
         }
 
@@ -343,6 +381,7 @@ class FinishopenidloginAction extends Action
         if ($url) {
             # We don't have to return to it again
             common_set_returnto(null);
+           $url = common_inject_session($url);
         } else {
             $url = common_local_url('all',
                                     array('nickname' =>
@@ -417,49 +456,7 @@ class FinishopenidloginAction extends Action
 
     function urlToNickname($openid)
     {
-        static $bad = array('query', 'user', 'password', 'port', 'fragment');
-
-        $parts = parse_url($openid);
-
-        # 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) && # try to skip .co.uk, .com.au
-                (strcmp($hostparts[0], 'www') != 0))
-            {
-                return $this->nicknamize($hostparts[0]);
-            } else {
-                # Do the whole hostname
-                return $this->nicknamize($parts['host']);
-            }
-        } else {
-            if (array_key_exists('path', $parts)) {
-                # Strip starting, ending slashes
-                $path = preg_replace('@/$@', '', $parts['path']);
-                $path = preg_replace('@^/@', '', $path);
-                if (strpos($path, '/') === false) {
-                    return $this->nicknamize($path);
-                }
-            }
-        }
-
-        return null;
+        return common_url_to_nickname($openid);
     }
 
     function xriToNickname($xri)
@@ -489,7 +486,6 @@ class FinishopenidloginAction extends Action
 
     function nicknamize($str)
     {
-        $str = preg_replace('/\W/', '', $str);
-        return strtolower($str);
+        return common_nicknamize($str);
     }
 }