From bc56428d493d99576ff274611df3b029e7e47e0a Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Thu, 15 Dec 2011 22:00:20 -0500 Subject: added some registration code for first time users --- start.php | 119 ++++++++++++++++++++++++-------------------------------------- 1 file changed, 46 insertions(+), 73 deletions(-) (limited to 'start.php') diff --git a/start.php b/start.php index afbd7e49d..d335d6e55 100644 --- a/start.php +++ b/start.php @@ -1,88 +1,61 @@ - * @copyright Curverider Ltd 2008-2009 - * @link http://elgg.com/ */ - - global $CONFIG; - - set_include_path(get_include_path() . PATH_SEPARATOR . $CONFIG->pluginspath . 'openid_client/models'); + +elgg_register_event_handler('init', 'system', 'openid_client_init'); /** - * OpenID client initialisation - * - * These parameters are required for the event API, but we won't use them: - * - * @param unknown_type $event - * @param unknown_type $object_type - * @param unknown_type $object + * OpenID client initialization */ - function openid_client_init() { - - elgg_extend_view("login/extend", "openid_client/forms/login"); - - // Extend system CSS with our own styles - elgg_extend_view('css','openid_client/css'); - - // Register a page handler, so we can have nice URLs - register_page_handler('openid_client','openid_client_page_handler'); - -} - -function openid_client_pagesetup() - { - if (get_context() == 'admin' && isadminloggedin()) { - global $CONFIG; - add_submenu_item(elgg_echo('openid_client:admin_title'), $CONFIG->wwwroot . 'pg/openid_client/admin'); - } -} + elgg_extend_view('core/account/login_box', 'openid_client/login'); + + $base = elgg_get_plugins_path() . 'openid_client/actions/openid_client'; + elgg_register_action('openid_client/login', "$base/login.php", 'public'); + elgg_register_action('openid_client/register', "$base/register.php", 'public'); -function openid_client_can_edit($hook_name, $entity_type, $return_value, $parameters) { - $entity = $parameters['entity']; - $context = get_context(); - if ($context == 'openid' && $entity->getSubtype() == "openid") { - // should be able to do anything with OpenID user data - return true; - } - return null; + $base = elgg_get_plugins_path() . 'openid_client/lib'; + elgg_register_library('openid_client', "$base/helpers.php"); + + elgg_register_event_handler('create', 'user', 'openid_client_set_subtype', 1); + + elgg_register_page_handler('openid_client', 'openid_client_page_handler'); } -function openid_client_page_handler($page) { - if (isset($page[0])) { - if ($page[0] == 'admin') { - include(dirname(__FILE__) . "/pages/admin.php"); - return true; - } else if ($page[0] == 'confirm') { - include(dirname(__FILE__) . "/pages/confirm.php"); - return true; - } else if ($page[0] == 'sso') { - include(dirname(__FILE__) . "/pages/sso.php"); - return true; - } else if ($page[0] == 'reset') { - include(dirname(__FILE__) . "/pages/reset.php"); - return true; - } - } - return false; +/** + * Set the correct subtype for OpenID users + * + * @param string $event Event name + * @param string $type Object type + * @param ElggUser $user New user + */ +function openid_client_set_subtype($event, $type, $user) { + $db_prefix = elgg_get_config('dbprefix'); + $guid = (int)$user->getGUID(); + $subtype_id = (int)add_subtype('user', 'openid'); + + $query = "UPDATE {$db_prefix}entities SET subtype = $subtype_id WHERE guid = $guid"; + update_data($query); } -register_elgg_event_handler('init','system','openid_client_init'); -register_elgg_event_handler('pagesetup','system','openid_client_pagesetup'); +/** + * OpenID client page handler + * + * @param type $page Array of URL segments + * @return bool + */ +function openid_client_page_handler($page) { -register_plugin_hook('permissions_check','user','openid_client_can_edit'); + // this is test code for right now + elgg_load_library('openid_client'); + openid_client_registration_page_handler(array( + 'username' => 'john', + 'email' => 'john@example.org', + 'name' => 'John Doe', + 'openid_identifier' => 'abcdefghijklmnopqrstuvwxyz', + )); -// Register actions -global $CONFIG; -register_action("openid_client/login",true,$CONFIG->pluginspath . "openid_client/actions/login.php"); -register_action("openid_client/return",true,$CONFIG->pluginspath . "openid_client/actions/return.php"); -register_action("openid_client/admin",false,$CONFIG->pluginspath . "openid_client/actions/admin.php"); -//register_action("openid_client/confirm",false,$CONFIG->pluginspath . "openid_client/actions/confirm.php"); -register_action("openid_client/missing",false,$CONFIG->pluginspath . "openid_client/actions/missing.php"); -register_action("openid_client/sync",false,$CONFIG->pluginspath . "openid_client/actions/sync.php"); + return true; +} -- cgit v1.2.3