aboutsummaryrefslogtreecommitdiff
path: root/mod/openid_client/actions
diff options
context:
space:
mode:
Diffstat (limited to 'mod/openid_client/actions')
-rw-r--r--mod/openid_client/actions/openid_client/login.php32
-rw-r--r--mod/openid_client/actions/openid_client/register.php35
2 files changed, 67 insertions, 0 deletions
diff --git a/mod/openid_client/actions/openid_client/login.php b/mod/openid_client/actions/openid_client/login.php
new file mode 100644
index 000000000..2a6896a61
--- /dev/null
+++ b/mod/openid_client/actions/openid_client/login.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * OpenID client login action
+ */
+
+elgg_load_library('openid_consumer');
+
+$provider = get_input('openid_provider');
+$persistent = get_input('persistent', false);
+
+if ($provider == 'others') {
+ $provider = get_input('openid_url');
+}
+
+$consumer = new ElggOpenIDConsumer($store);
+$consumer->setURL($provider);
+$consumer->setReturnURL(elgg_get_site_url() . "mod/openid_client/return.php?persistent=$persistent");
+
+$html = $consumer->requestAuthentication();
+if ($html) {
+ echo $html;
+ exit;
+} else {
+ $flipped_providers = array_flip(elgg_get_config('openid_providers'));
+ if (isset($flipped_providers[$provider])) {
+ $provider_name = $flipped_providers[$provider];
+ } else {
+ $provider_name = $provider;
+ }
+ register_error(elgg_echo('openid_client:error:no_html', array($provider_name)));
+ forward();
+}
diff --git a/mod/openid_client/actions/openid_client/register.php b/mod/openid_client/actions/openid_client/register.php
new file mode 100644
index 000000000..f0ad2a5fd
--- /dev/null
+++ b/mod/openid_client/actions/openid_client/register.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * Register OpenID user action
+ */
+
+elgg_set_context('openid_client');
+
+$username = get_input('username');
+$name = get_input('name');
+$email = get_input('email');
+$openid_identifier = get_input('openid_identifier');
+
+$password = generate_random_cleartext_password();
+
+try {
+ $guid = register_user($username, $password, $name, $email, false);
+} catch (RegistrationException $e) {
+ register_error($e->getMessage());
+ forward(REFERER);
+}
+$user = get_entity($guid);
+openid_client_set_subtype($user);
+
+$user->annotate('openid_identifier', $openid_identifier, ACCESS_PUBLIC);
+elgg_set_user_validation_status($guid, true, 'openid');
+
+if (!elgg_trigger_plugin_hook('register', 'user', array('user' => $user), true)) {
+ $user->delete();
+ register_error(elgg_echo('registerbad'));
+ forward(REFERER);
+}
+
+login($user);
+system_message(elgg_echo('openid_client:success:register'));
+forward();