Skip to content
Snippets Groups Projects
Commit c65bee3c authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

[gh-245] Merging test into staging -c1150 -c1152 -c1154 -c1162

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1271 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 1a3b0629
No related branches found
No related tags found
No related merge requests found
<?php <?php
/**
* Settings for admin/people/import setup in unl_cas.module
*/
function unl_cas_user_import($form, &$form_state) { function unl_cas_user_import($form, &$form_state) {
$form['root'] = array( $form['root'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
'#title' => 'Import from UNL Directory.', '#title' => 'Import from UNL Directory.',
...@@ -82,8 +84,10 @@ function unl_cas_user_import_submit($form, &$form_state) { ...@@ -82,8 +84,10 @@ function unl_cas_user_import_submit($form, &$form_state) {
} }
} }
/**
* Settings for admin/config/people/unl_cas setup in unl_cas.module
*/
function unl_cas_config($form, &$form_state) { function unl_cas_config($form, &$form_state) {
$form['ldap'] = array( $form['ldap'] = array(
'#tree' => TRUE, '#tree' => TRUE,
'#type' => 'fieldset', '#type' => 'fieldset',
......
...@@ -3,7 +3,7 @@ description = Enables CAS authentication/registration of users through login.unl ...@@ -3,7 +3,7 @@ description = Enables CAS authentication/registration of users through login.unl
package = UNL package = UNL
dependencies[] = unl dependencies[] = unl
core = 7.x core = 7.x
version = "7.x-1.0-20101129" version = "7.x-1.0-beta1"
configure = admin/config/people/unl_cas configure = admin/config/people/unl_cas
files[] = unl_cas.module files[] = unl_cas.module
......
<?php <?php
/**
* Implements hook_schema().
*/
function unl_cas_schema() { function unl_cas_schema() {
$schema = array(); $schema = array();
$schema['unl_cas_settings'] = array( $schema['unl_cas_settings'] = array(
......
...@@ -2,12 +2,17 @@ ...@@ -2,12 +2,17 @@
require_once dirname(__FILE__) . '/../includes/common.php'; require_once dirname(__FILE__) . '/../includes/common.php';
/**
* Implements hook_enable().
*/
function unl_cas_enable() { function unl_cas_enable() {
variable_set('user_register', 0); variable_set('user_register', 0);
} }
/**
* Implements hook_init().
*/
function unl_cas_init() { function unl_cas_init() {
// If no one is claiming to be logged in while no one is actually logged in, we don't need CAS. // If no one is claiming to be logged in while no one is actually logged in, we don't need CAS.
if (!array_key_exists('unl_sso', $_COOKIE) && user_is_anonymous()) { if (!array_key_exists('unl_sso', $_COOKIE) && user_is_anonymous()) {
return; return;
...@@ -24,11 +29,14 @@ function unl_cas_init() { ...@@ -24,11 +29,14 @@ function unl_cas_init() {
$cas = unl_cas_get_adapter(); $cas = unl_cas_get_adapter();
if ($cas->isTicketExpired() && ($_SERVER['REQUEST_METHOD'] == 'GET' || user_is_anonymous())) { if ($cas->isTicketExpired() && ($_SERVER['REQUEST_METHOD'] == 'GET' || user_is_anonymous())) {
$cas->setGateway(); $cas->setGateway();
unset($_GET['destination']);
drupal_goto($cas->getLoginUrl()); drupal_goto($cas->getLoginUrl());
} }
} }
/** /**
* Sets up an instance of Unl_Cas
*
* @return Unl_Cas * @return Unl_Cas
*/ */
function unl_cas_get_adapter() { function unl_cas_get_adapter() {
...@@ -43,16 +51,18 @@ function unl_cas_get_adapter() { ...@@ -43,16 +51,18 @@ function unl_cas_get_adapter() {
} else { } else {
$url = url('user/cas', array('absolute' => TRUE, 'query' => drupal_get_destination())); $url = url('user/cas', array('absolute' => TRUE, 'query' => drupal_get_destination()));
} }
unset($_GET['destination']);
$adapter = new Unl_Cas($url, 'https://login.unl.edu/cas'); $adapter = new Unl_Cas($url, 'https://login.unl.edu/cas');
} }
return $adapter; return $adapter;
} }
/**
* Implements hook_menu().
*/
function unl_cas_menu() { function unl_cas_menu() {
$items['user/cas'] = array( $items['user/cas'] = array(
'title' => 'UNL CAS Validation', 'title' => 'UNL CAS Validation',
'page callback' => 'unl_cas_validate', 'page callback' => 'unl_cas_validate_ticket',
'access callback' => TRUE, 'access callback' => TRUE,
); );
...@@ -80,13 +90,18 @@ function unl_cas_menu() { ...@@ -80,13 +90,18 @@ function unl_cas_menu() {
return $items; return $items;
} }
/**
* Implements hook_menu_alter().
*/
function unl_cas_menu_alter(&$items) { function unl_cas_menu_alter(&$items) {
$items['admin/people/create']['weight'] = 2; $items['admin/people/create']['weight'] = 2;
$items['admin/people/create']['title'] .= ' manually'; $items['admin/people/create']['title'] .= ' manually';
} }
function unl_cas_validate() { /**
drupal_session_start(); * Validates CAS ticket
*/
function unl_cas_validate_ticket() {
$cas = unl_cas_get_adapter(); $cas = unl_cas_get_adapter();
if (array_key_exists('logoutRequest', $_POST)) { if (array_key_exists('logoutRequest', $_POST)) {
...@@ -117,9 +132,13 @@ function unl_cas_validate() { ...@@ -117,9 +132,13 @@ function unl_cas_validate() {
drupal_goto($destination['destination']); drupal_goto($destination['destination']);
} }
function unl_cas_form_alter(&$form, $form_state, $form_id) { /**
* Implements hook_form_alter().
*/
function unl_cas_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_login') { if ($form_id == 'user_login') {
$cas = unl_cas_get_adapter(); $cas = unl_cas_get_adapter();
unset($_GET['destination']);
drupal_goto($cas->getLoginUrl()); drupal_goto($cas->getLoginUrl());
} }
...@@ -162,20 +181,27 @@ function unl_cas_form_alter(&$form, $form_state, $form_id) { ...@@ -162,20 +181,27 @@ function unl_cas_form_alter(&$form, $form_state, $form_id) {
} }
/** /**
* Implements hook_form_FORM_ID_alter().
* Make sure there's no funny business with somebody trying to change a password when we're using CAS. * Make sure there's no funny business with somebody trying to change a password when we're using CAS.
*/ */
function unl_cas_user_profile_form_validate(&$form, &$form_state) { function unl_cas_user_profile_form_validate(&$form, &$form_state, $form_id) {
if ($form_state['values']['pass']) { if ($form_state['values']['pass']) {
form_set_error('current_pass', t('Password changes are not allowed when CAS is enabled!')); form_set_error('current_pass', t('Password changes are not allowed when CAS is enabled!'));
} }
} }
/**
* Implements hook_user_logout().
*/
function unl_cas_user_logout($account) { function unl_cas_user_logout($account) {
session_destroy(); session_destroy();
$cas = unl_cas_get_adapter(); $cas = unl_cas_get_adapter();
drupal_goto($cas->getLogoutUrl(url('<front>', array('absolute' => TRUE)))); drupal_goto($cas->getLogoutUrl(url('<front>', array('absolute' => TRUE))));
} }
/**
* Generates and saves a user using info from LDAP or Directory
*/
function unl_cas_import_user($username) { function unl_cas_import_user($username) {
unl_load_zend_framework(); unl_load_zend_framework();
$user = array(); $user = array();
...@@ -229,7 +255,7 @@ function unl_cas_import_user($username) { ...@@ -229,7 +255,7 @@ function unl_cas_import_user($username) {
} }
/** /**
* Implements hook_user_presave() * Implements hook_user_presave().
* *
* On non-default sites, only allow users who are administrators on the default * On non-default sites, only allow users who are administrators on the default
* to be administrators. Also, automatically make users who are administrators * to be administrators. Also, automatically make users who are administrators
...@@ -262,7 +288,7 @@ function unl_cas_user_presave(&$edit, $account, $category) { ...@@ -262,7 +288,7 @@ function unl_cas_user_presave(&$edit, $account, $category) {
} }
/** /**
* Implements hook_user_login() * Implements hook_user_login().
* *
* On non-default sites, if a user with the administrator role logs in, verify * On non-default sites, if a user with the administrator role logs in, verify
* that they are still an admin in the default site. If not, remove them from * that they are still an admin in the default site. If not, remove them from
...@@ -283,6 +309,9 @@ function unl_cas_user_login(&$edit, $account) { ...@@ -283,6 +309,9 @@ function unl_cas_user_login(&$edit, $account) {
user_save($account, $edit); user_save($account, $edit);
} }
/**
* Determines if given user has the administrator role on the master/root site of a multisite setup.
*/
function _unl_cas_is_user_default_site_administrator($username) { function _unl_cas_is_user_default_site_administrator($username) {
$shared_prefix = unl_get_shared_db_prefix(); $shared_prefix = unl_get_shared_db_prefix();
$shared_admin_role_id = unl_shared_variable_get('user_admin_role'); $shared_admin_role_id = unl_shared_variable_get('user_admin_role');
...@@ -290,6 +319,9 @@ function _unl_cas_is_user_default_site_administrator($username) { ...@@ -290,6 +319,9 @@ function _unl_cas_is_user_default_site_administrator($username) {
return count($shared_admin_usernames) > 0; return count($shared_admin_usernames) > 0;
} }
/**
* Implements template_preprocess_user_picture().
*/
function unl_cas_preprocess_user_picture(&$variables) { function unl_cas_preprocess_user_picture(&$variables) {
//Default image: https://planetred.unl.edu/mod/profile/graphics/defaultmedium.gif //Default image: https://planetred.unl.edu/mod/profile/graphics/defaultmedium.gif
if ($variables['account']->uid == 0) { if ($variables['account']->uid == 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment