diff options
-rw-r--r-- | actions/openid_client/login.php | 10 | ||||
-rw-r--r-- | classes/ElggOpenIDConsumer.php | 20 | ||||
-rw-r--r-- | languages/en.php | 1 | ||||
-rw-r--r-- | start.php | 28 | ||||
-rw-r--r-- | views/default/forms/openid_client/login.php | 13 | ||||
-rw-r--r-- | views/default/openid_client/js.php | 18 | ||||
-rw-r--r-- | views/default/openid_client/login.php | 6 |
7 files changed, 84 insertions, 12 deletions
diff --git a/actions/openid_client/login.php b/actions/openid_client/login.php index 74a8de8f6..cf991ea0f 100644 --- a/actions/openid_client/login.php +++ b/actions/openid_client/login.php @@ -5,8 +5,12 @@ elgg_load_library('openid_consumer'); +$provider = get_input('openid_provider'); +$username = get_input('openid_username'); + $consumer = new ElggOpenIDConsumer($store); -$consumer->setProvider(get_input('provider')); +$consumer->setProvider($provider); +$consumer->setUsername($username); $consumer->setReturnURL(elgg_get_site_url() . 'mod/openid_client/return.php'); $html = $consumer->requestAuthentication(); @@ -14,5 +18,7 @@ if ($html) { echo $html; exit; } else { - register_error('oops'); + $provider_name = elgg_echo("openid_client:provider:$provider"); + register_error(elgg_echo('openid_client:error:no_html', array($provider_name))); + forward(); } diff --git a/classes/ElggOpenIDConsumer.php b/classes/ElggOpenIDConsumer.php index 864e47d41..3918086ab 100644 --- a/classes/ElggOpenIDConsumer.php +++ b/classes/ElggOpenIDConsumer.php @@ -142,13 +142,17 @@ class ElggOpenIDConsumer { $url = "http://$username.blogspot.com/"; break; case 'wordpress': - $url = ""; + // username is actually the blog name + $url = "http://$username.wordpress.com/"; + break; + case 'livejournal': + $url = "http://$username.livejournal.com/"; break; case 'aol': - $url = "http://openid.aol.com/$username"; + $url = "https://openid.aol.com/"; break; case 'verisign': - $url = "http://username.pip.verisignlabs.com/"; + $url = "https://pip.verisignlabs.com/ "; break; case 'myopenid': $url = 'https://myopenid.com/'; @@ -204,6 +208,8 @@ class ElggOpenIDConsumer { * the provider. If JavaScript is not enabled, a plain html form with a * continue button is displayed. * + * This also supports OpenID 1.x but has not been tested as thoroughly. + * * @return mixed */ protected function getForm() { @@ -213,7 +219,13 @@ class ElggOpenIDConsumer { return $html; } else { // OpenID 1.x - return false; + $redirect_url = $this->request->redirectURL(elgg_get_site_url(), $this->returnURL); + + if (Auth_OpenID::isFailure($redirect_url)) { + return false; + } else { + forward($redirect_url); + } } } diff --git a/languages/en.php b/languages/en.php index 4efb59463..8c5beff1b 100644 --- a/languages/en.php +++ b/languages/en.php @@ -19,6 +19,7 @@ $english = array( 'openid_client:success:register' => 'Your account has been created.',
'openid_client:error:bad_register' => 'Unable to create an account. Please contact a site administrator.',
'openid_client:error:bad_response' => 'Bad response from the OpenID server',
+ 'openid_client:error:no_html' => 'An error occurred trying to contact %s',
'openid_client:warning:username_not_available' => 'The username %s is not available. Please pick another.',
'openid_client:warning:username_valid' => 'The username %s is not valid as this site. Please pick another.',
'openid_client:warning:email_not_available' => 'The email address %s is not available. Please pick another.',
@@ -13,6 +13,7 @@ elgg_register_event_handler('init', 'system', 'openid_client_init'); */
function openid_client_init() {
elgg_extend_view('css/elgg', 'openid_client/css');
+ elgg_extend_view('js/elgg', 'openid_client/js');
elgg_extend_view('core/account/login_box', 'openid_client/login');
elgg_register_plugin_hook_handler('register', 'menu:openid_login', 'openid_client_setup_menu');
@@ -58,24 +59,39 @@ function openid_client_set_subtype($event, $type, $user) { function openid_client_setup_menu($hook, $type, $menu, $params) {
$items = array(
- 'large' => array('google', 'yahoo'),
- 'small' => array('blogger', 'wordpress'),
+ 'large' => array(
+ 'google' => '',
+ 'yahoo' => '',
+ ),
+ 'small' => array(
+ 'blogger' => 'toggle',
+ 'wordpress' => 'toggle',
+ ),
);
$items = elgg_trigger_plugin_hook('register', 'openid_login', null, $items);
$priority = 100;
foreach ($items as $type => $providers) {
- foreach ($providers as $provider) {
+ foreach ($providers as $provider => $toggle) {
$provider_name = elgg_echo("openid_client:provider:$provider");
- $menu[] = ElggMenuItem::factory(array(
+
+ $options = array(
'name' => $provider,
'text' => '<span></span>',
'title' => elgg_echo('openid_client:login:instructs', array($provider_name)),
- 'href' => "action/openid_client/login?provider=$provider",
+ 'href' => "action/openid_client/login?openid_provider=$provider",
'is_action' => true,
'section' => $type,
'priority' => $priority,
- ));
+ );
+
+ if ($toggle) {
+ $options['link_class'] = 'openid-client-toggle';
+ $options['rel'] = $provider;
+ }
+
+ $menu[] = ElggMenuItem::factory($options);
+
$priority += 10;
}
}
diff --git a/views/default/forms/openid_client/login.php b/views/default/forms/openid_client/login.php new file mode 100644 index 000000000..eba6dbe4b --- /dev/null +++ b/views/default/forms/openid_client/login.php @@ -0,0 +1,13 @@ +<?php +/** + * OpenID login if username or full url required + */ + +echo '<label>'; +echo elgg_echo('username'); +echo '</label>'; +echo elgg_view('input/text', array('name' => 'openid_username', 'class' => 'mbs')); + +echo elgg_view('input/hidden', array('name' => 'openid_provider')); + +echo elgg_view('input/submit', array('value' => elgg_echo('submit')));
\ No newline at end of file diff --git a/views/default/openid_client/js.php b/views/default/openid_client/js.php new file mode 100644 index 000000000..175577719 --- /dev/null +++ b/views/default/openid_client/js.php @@ -0,0 +1,18 @@ +<?php +/** + * OpenID JavaScript + */ + +?> + +// OpenID toggle +elgg.register_hook_handler('init', 'system', function() { + $(".openid-client-toggle").click(function(event) { + $("#openid-client-login-form").slideDown(); + + var provider_input = $("#openid-client-login-form input[name=openid_provider]"); + provider_input.attr('value', $(this).attr('rel')); + + event.preventDefault(); + }); +}); diff --git a/views/default/openid_client/login.php b/views/default/openid_client/login.php index 7e71b8bab..30685fe51 100644 --- a/views/default/openid_client/login.php +++ b/views/default/openid_client/login.php @@ -10,3 +10,9 @@ echo elgg_view_menu('openid_login', array( 'class' => 'elgg-menu-hz', 'sort_by' => 'priority', )); + +$form_vars = array( + 'class' => 'hidden', + 'id' => 'openid-client-login-form', +); +echo elgg_view_form('openid_client/login', $form_vars); |