aboutsummaryrefslogtreecommitdiff
path: root/lib/helpers.php
diff options
context:
space:
mode:
authorCash Costello <cash.costello@gmail.com>2011-12-15 22:00:20 -0500
committerCash Costello <cash.costello@gmail.com>2011-12-15 22:00:20 -0500
commitbc56428d493d99576ff274611df3b029e7e47e0a (patch)
tree7867e8cdc71cc8b0f70dbbf254dff7d0dc06753c /lib/helpers.php
parent49bb5234e9dbef676476bab2936344d8345065c9 (diff)
downloadelgg-bc56428d493d99576ff274611df3b029e7e47e0a.tar.gz
elgg-bc56428d493d99576ff274611df3b029e7e47e0a.tar.bz2
added some registration code for first time users
Diffstat (limited to 'lib/helpers.php')
-rw-r--r--lib/helpers.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/helpers.php b/lib/helpers.php
new file mode 100644
index 000000000..c7158235a
--- /dev/null
+++ b/lib/helpers.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Helper functions for the OpenID client plugin
+ */
+
+/**
+ * Serves a page to the new user to determine account values
+ *
+ * This should only be called after validating the OpenID response.
+ *
+ * @param array $data Key value pairs extracted from the response
+ * @return bool
+ */
+function openid_client_registration_page_handler(array $data) {
+
+ if (!is_array($data)) {
+ return false;
+ }
+
+ $title = 'register';
+
+ $vars = openid_client_prepare_registration_vars($data);
+ $content = elgg_view('openid_client/register', $vars);
+
+ $body = elgg_view_layout('one_column', array('content' => $content));
+ echo elgg_view_page($title, $body);
+
+ return true;
+}
+
+/**
+ * Create the form vars for registration
+ *
+ * @param array $data
+ * @return array
+ */
+function openid_client_prepare_registration_vars(array $data) {
+ $vars = array();
+
+ $vars['openid_identifier'] = $data['openid_identifier'];
+
+ // username
+ if (isset($data['username'])) {
+ $vars['username'] = $data['username'];
+ } else if (isset($data['email'])) {
+ $vars['username'] = array_pop(explode('@', $data['email']));
+ } else {
+ $vars['username'] = null;
+ }
+
+ // is the username available
+ $vars['is_username_available'] = true;
+
+ // is the username valid
+ try {
+ $vars['is_username_valid'] = validate_username($vars['username']);
+ } catch (RegistrationException $e) {
+ $vars['is_username_valid'] = false;
+ }
+
+ // the rest
+ $vars['email'] = elgg_extract('email', $data);
+ $vars['name'] = elgg_extract('name', $data);
+
+ return $vars;
+}