diff --git a/README b/README index 240ffc9a5eb6a432eab6f21f2e6093d72db28b50..5ad5e6612a5114261b0ddb4aa7301215c871b66e 100644 --- a/README +++ b/README @@ -83,3 +83,9 @@ elgg/featured/ http://its-gforge.unl.edu/svn/unl_huskers/trunk/ All patches are located in the /pathces directory. These include: /pathces/lowercase_post.diff + +******* +** Things to look out for when new versions of Elgg are released +******* +-- Are there changes to /elgg/actions/login.php and /elgg/actions/logout.php ????? + We have overridden those actions with our own in the cas_auth_unl plugin \ No newline at end of file diff --git a/plugins/cas_auth_unl/actions/login.php b/plugins/cas_auth_unl/actions/login.php index 39eda913df660b8e12db71428b62508e069b28df..1a573b885e57c3d1de505869ffaabb8ef4054733 100644 --- a/plugins/cas_auth_unl/actions/login.php +++ b/plugins/cas_auth_unl/actions/login.php @@ -38,9 +38,16 @@ $token = generate_action_token($ts); SimpleCAS::setURL('http://ucommrasmussen.unl.edu/workspace/UNL_Elgg/elgg/action/login?usecas=yes&__elgg_ts='.$ts.'&__elgg_token='.$token); $casObject->forceCas(); + } else { + $cas_user = $casObject->getUserCas(); + if ($user = $casObject->casAuthenticate($cas_user)) { + $result = login($user); + if ($result) + $_SESSION['loggedInWithCas'] = true; + } } - $casObject->poopoo(); + } // Set the system_message as appropriate diff --git a/plugins/cas_auth_unl/actions/logout.php b/plugins/cas_auth_unl/actions/logout.php new file mode 100644 index 0000000000000000000000000000000000000000..ac179290b15648aefb77157b459617b1d46766f3 --- /dev/null +++ b/plugins/cas_auth_unl/actions/logout.php @@ -0,0 +1,36 @@ +<?php + + /** + * Elgg logout action for use with UNL CAS + * + * @package Elgg + * @subpackage Core + * @overwritten cas_auth_unl/actions/logout.php + * @author Curverider Ltd + * @link http://elgg.org/ + */ + + // Save this session value since the next step wipes it out + $loggedInWithCas = $_SESSION['loggedInWithCas']; + + // Log out + $result = logout(); + + // Set the system_message as appropriate + + if ($result) { + system_message(elgg_echo('logoutok')); + } else { + register_error(elgg_echo('logouterror')); + } + + // We've destoyed all the Elgg session data, now do CAS logout if neccessary + // Due to problems getting the SimpleCAS logout to work, we're just forwarding to the right URL since + // the Elgg logout function above took care of destroying the session, which is all the SimpleCAS logout + // was doing anyway. + + if ($loggedInWithCas) { + global $CONFIG; + forward('https://login.unl.edu/cas/logout?url='.$CONFIG->url); + } +?> \ No newline at end of file diff --git a/plugins/cas_auth_unl/start.php b/plugins/cas_auth_unl/start.php index b1794220cf26309ce2fe2e9fa2c23ba758b3a31e..332cf548514bb6f794411442333fb1f32f1f3c07 100644 --- a/plugins/cas_auth_unl/start.php +++ b/plugins/cas_auth_unl/start.php @@ -17,45 +17,18 @@ function cas_auth_unl_init() { - global $CONFIG; - - - - if ($_GET['loginwith'] == 'UNLlogin') { - if (checkCas()) { - $_SESSION['loggedWithCAS'] = true; - - $cas_user = getUserCas(); - if (casAuthenticate($cas_user)) { - system_message(elgg_echo('loginok')); - $cas_user = str_replace('-','_',$cas_user); - - //user is logged in now, this is the last step - forward based on whether they have logged in before - if (!$_SESSION['user']->last_login) - forward('mod/profile/edit.php?firstlogin=yes'); - else - forward("pg/profile/unl_" . $cas_user); - } else { - register_error(elgg_echo('loginerror')); - } - } else { - forceCas(); - } - } } - //*************->Start + register_action("getemail",true,$CONFIG->pluginspath . "cas_auth_unl/views/default/actions/getemail.php"); register_action("login",false,$CONFIG->pluginspath. "cas_auth_unl/actions/login.php"); + register_action("logout",false,$CONFIG->pluginspath. "cas_auth_unl/actions/logout.php"); // Fire up the plugin initialization using the elgg handler register_elgg_event_handler('init','system','cas_auth_unl_init'); - // Register CAS logout to main logout only if user logged with CAS - if (isset($_SESSION['loggedWithCAS']) && $_SESSION['loggedWithCAS']==true) { - // register_elgg_event_handler('logout', 'user', 'logoutCas'); - } + // Set up login page, this creates the url /pg/login to be used as our login page register_page_handler('login', 'login_page_handler'); @@ -82,57 +55,51 @@ class elggSimpleCas { function __construct() { if (!$this->casInitialized) { + // Elgg blows away $_GET at some point which SimpleCAS tries to use so we will reset it if ($ticket = get_input('ticket')) { $_GET['ticket'] = $ticket; } + // Setup CAS $config = find_plugin_settings('cas_auth_unl'); $options = array('hostname' => $config->casurl, 'port' => $config->casport, 'uri' => $config->casuri); $protocol = new SimpleCAS_Protocol_Version2($options); $request = $protocol->getRequest(); + // SSL doesn't work right on login.unl.edu $defaultClass = SimpleCAS_Protocol::DEFAULT_REQUEST_CLASS; if ($request instanceof $defaultClass) { $protocol->getRequest()->setConfig('ssl_verify_peer', false); } + // Create Our Client $this->client = SimpleCAS::client($protocol); $this->casInitialized = true; } return true; - } - - function poopoo(){ - header('Location: http://google.com');exit(); } - function forceCas() { + public function forceCas() { $this->client->forceAuthentication(); return true; } - function checkCas() { - if ($this->client->isAuthenticated()) { + public function checkCas() { + if ($this->client->isAuthenticated()) return true; - } else return false; } + + public function getUserCas() { + return $this->client->getUsername(); + } - function logoutCas() { - global $CONFIG; - phpCAS::logout($CONFIG->url.'/action/logout'); + public function logoutCas() { + $this->client->logout(); return true; } - - /** - * Perform the CAS Authentication - * - * @param string $username - * @return boolean - */ - function casAuthenticate($username){ - - + + public function casAuthenticate($username){ if (empty($username)) return false; @@ -150,8 +117,8 @@ class elggSimpleCas { $username = str_replace('-','_',$username); if ($user = get_user_by_username($username)) { - // User exists, login - return login($user); + // User exists, return the user object + return $user; } else { // Valid login but user doesn't exist $pf_user_info = peoplefinderServices($casusername); @@ -168,7 +135,7 @@ class elggSimpleCas { } try { - if ($user_guid = register_user($username, 'generic', $name, $email, false, 0, '', true)) { + if ($user_guid = register_user($username, generate_random_cleartext_password(), $name, $email, false, 0, '', true)) { $thisuser = get_user($user_guid); //pre-populate profile fields with data from Peoplefinder Services @@ -184,16 +151,14 @@ class elggSimpleCas { $thisuser->latitude = 40.82; } - return login($thisuser); + return $thisuser; } else { register_error(elgg_echo("registerbad")); } } catch (RegistrationException $r) { register_error($r->getMessage()); } - } - } diff --git a/plugins/cas_auth_unl/views/default/account/forms/login.php b/plugins/cas_auth_unl/views/default/account/forms/login.php index 406e6c2f191e663de92d6c6d2b6e72c0cbea23f4..8a83a872c8a2f14f4e2399c5851763946778c14d 100644 --- a/plugins/cas_auth_unl/views/default/account/forms/login.php +++ b/plugins/cas_auth_unl/views/default/account/forms/login.php @@ -11,7 +11,8 @@ global $CONFIG; ?> - + +<?php /* <div id="login"> <div class="two_col left"> <h2 class="sec_main">Students, Faculty, Staff</h2> @@ -23,7 +24,7 @@ $form_body .= elgg_view('input/submit', array('value' => elgg_echo('UNL Login'))) . '</p>'; $ts = time(); $token = generate_action_token($ts); - echo elgg_view('input/form', array('body' => $form_body, 'action' => "". $vars['url'] ."action/login")); + echo elgg_view('input/form', array('body' => $form_body, 'action' => "". $vars['url'] ."action/login?usecas=yes&__elgg_ts='.$ts.'&__elgg_token='.$token")); ?> <p style="margin-top: 40px;"><a title="Find your my.UNL password" href="https://login.unl.edu/faq/account-resetpw.shtml">Lost your my.UNL password?</a></p> @@ -38,4 +39,28 @@ echo elgg_view('input/form', array('body' => $form_body, 'action' => "". $vars['url'] ."action/login")); ?> </div> + </div> +*/ ?> + + <div id="login"> + <div class="two_col left"> + <h2 class="sec_main">Students, Faculty, Staff</h2> + <p>Use your my.UNL Single Sign-on account to begin.</p> + <?php + $ts = time(); + $token = generate_action_token($ts); + ?> + <a href="<?php echo $CONFIG->url ?>action/login?usecas=yes&__elgg_ts=<?php echo $ts; ?>&__elgg_token=<?php echo $token; ?>" class="wdn_loginLink"><span>UNL Login</span></a> + <p style="margin-top:85px"><a href="https://login.unl.edu/faq/account-resetpw.shtml" title="Find your my.UNL password">Lost your my.UNL password?</a></p> + </div> + <div class="two_col right"> + <h2 class="sec_main">Huskers Worldwide</h2> + <?php + $form_body = "<p class=\"login-box\"><label>" . elgg_echo('username') . "<br />" . elgg_view('input/text', array('internalname' => 'username', 'class' => 'login-textarea')) . "</label><br />"; + $form_body .= "<label>" . elgg_echo('password') . "<br />" . elgg_view('input/password', array('internalname' => 'password', 'class' => 'login-textarea')) . "</label><br />"; + $form_body .= elgg_view('input/submit', array('value' => elgg_echo('login'))) . "</p>"; + $form_body .= "<p><a href=\"". $vars['url'] ."account/register.php\">" . elgg_echo('register') . "</a> | <a href=\"". $vars['url'] ."account/forgotten_password.php\">" . elgg_echo('user:password:lost') . "</a></p>"; + echo elgg_view('input/form', array('body' => $form_body, 'action' => "". $vars['url'] ."action/login")); + ?> + </div> </div> \ No newline at end of file diff --git a/plugins/unl_theme/views/default/account/forms/login.php b/plugins/unl_theme/views/default/account/forms/login.php new file mode 100644 index 0000000000000000000000000000000000000000..c063ddb020fa72294aaf53359a399938550a94f1 --- /dev/null +++ b/plugins/unl_theme/views/default/account/forms/login.php @@ -0,0 +1,12 @@ + <div id="login"> + <div class="two_col right"> + <h2 class="sec_main">Huskers Worldwide</h2> + <?php + $form_body = "<p class=\"login-box\"><label>" . elgg_echo('username') . "<br />" . elgg_view('input/text', array('internalname' => 'username', 'class' => 'login-textarea')) . "</label><br />"; + $form_body .= "<label>" . elgg_echo('password') . "<br />" . elgg_view('input/password', array('internalname' => 'password', 'class' => 'login-textarea')) . "</label><br />"; + $form_body .= elgg_view('input/submit', array('value' => elgg_echo('login'))) . "</p>"; + $form_body .= "<p><a href=\"". $vars['url'] ."account/register.php\">" . elgg_echo('register') . "</a> | <a href=\"". $vars['url'] ."account/forgotten_password.php\">" . elgg_echo('user:password:lost') . "</a></p>"; + echo elgg_view('input/form', array('body' => $form_body, 'action' => "". $vars['url'] ."action/login")); + ?> + </div> + </div> \ No newline at end of file diff --git a/plugins/unl_theme/views/default/page_elements/unl_nav.php b/plugins/unl_theme/views/default/page_elements/unl_nav.php index d777084d9483ec13a9efa54f591c9c424ff050fb..ecda6fd30c567d5d7ea7f86485050132badff781 100644 --- a/plugins/unl_theme/views/default/page_elements/unl_nav.php +++ b/plugins/unl_theme/views/default/page_elements/unl_nav.php @@ -32,27 +32,11 @@ </div> </div> </div> -<?php //This is the login details hidden with CSS and displayed in the colorbox.?> + +<?php //This is the login details hidden with CSS and displayed in the colorbox. With CAS enabled this comes from cas_auth_unl views folder?> <div class="hidden"> - <div id="login"> - <div class="two_col left"> - <h2 class="sec_main">Students, Faculty, Staff</h2> - <p>Use your my.UNL Single Sign-on account to begin.</p> - <a href="<?php echo $CONFIG->url ?>?loginwith=UNLlogin" class="wdn_loginLink"><span>UNL Login</span></a> - <p style="margin-top:85px"><a href="https://login.unl.edu/faq/account-resetpw.shtml" title="Find your my.UNL password">Lost your my.UNL password?</a></p> - </div> - <div class="two_col right"> - <h2 class="sec_main">Huskers Worldwide</h2> - <?php - $form_body = "<p class=\"login-box\"><label>" . elgg_echo('username') . "<br />" . elgg_view('input/text', array('internalname' => 'username', 'class' => 'login-textarea')) . "</label><br />"; - $form_body .= "<label>" . elgg_echo('password') . "<br />" . elgg_view('input/password', array('internalname' => 'password', 'class' => 'login-textarea')) . "</label><br />"; - $form_body .= elgg_view('input/submit', array('value' => elgg_echo('login'))) . "</p>"; - $form_body .= "<p><a href=\"". $vars['url'] ."account/register.php\">" . elgg_echo('register') . "</a> | <a href=\"". $vars['url'] ."account/forgotten_password.php\">" . elgg_echo('user:password:lost') . "</a></p>"; - echo elgg_view('input/form', array('body' => $form_body, 'action' => "". $vars['url'] ."action/login")); - ?> - </div> - </div> + <?php echo elgg_view('account/forms/login'); ?> </div> <?php }?>