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
/**
* Settings for admin/people/import setup in unl_cas.module
*/
function unl_cas_user_import($form, &$form_state) {
$form['root'] = array(
'#type' => 'fieldset',
'#title' => 'Import from UNL Directory.',
......@@ -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) {
$form['ldap'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
......
......@@ -3,7 +3,7 @@ description = Enables CAS authentication/registration of users through login.unl
package = UNL
dependencies[] = unl
core = 7.x
version = "7.x-1.0-20101129"
version = "7.x-1.0-beta1"
configure = admin/config/people/unl_cas
files[] = unl_cas.module
......
<?php
/**
* Implements hook_schema().
*/
function unl_cas_schema() {
$schema = array();
$schema['unl_cas_settings'] = array(
......@@ -22,7 +25,7 @@ function unl_cas_schema() {
),
'primary key' => array('name'),
);
return $schema;
}
......@@ -50,6 +53,6 @@ function unl_cas_update_7100() {
),
'primary key' => array('name'),
);
db_create_table('unl_cas_settings', $table);
}
......@@ -2,12 +2,17 @@
require_once dirname(__FILE__) . '/../includes/common.php';
/**
* Implements hook_enable().
*/
function unl_cas_enable() {
variable_set('user_register', 0);
}
/**
* Implements hook_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 (!array_key_exists('unl_sso', $_COOKIE) && user_is_anonymous()) {
return;
......@@ -24,11 +29,14 @@ function unl_cas_init() {
$cas = unl_cas_get_adapter();
if ($cas->isTicketExpired() && ($_SERVER['REQUEST_METHOD'] == 'GET' || user_is_anonymous())) {
$cas->setGateway();
unset($_GET['destination']);
drupal_goto($cas->getLoginUrl());
}
}
/**
* Sets up an instance of Unl_Cas
*
* @return Unl_Cas
*/
function unl_cas_get_adapter() {
......@@ -43,16 +51,18 @@ function unl_cas_get_adapter() {
} else {
$url = url('user/cas', array('absolute' => TRUE, 'query' => drupal_get_destination()));
}
unset($_GET['destination']);
$adapter = new Unl_Cas($url, 'https://login.unl.edu/cas');
}
return $adapter;
}
/**
* Implements hook_menu().
*/
function unl_cas_menu() {
$items['user/cas'] = array(
'title' => 'UNL CAS Validation',
'page callback' => 'unl_cas_validate',
'page callback' => 'unl_cas_validate_ticket',
'access callback' => TRUE,
);
......@@ -64,7 +74,7 @@ function unl_cas_menu() {
'page arguments' => array('unl_cas_user_import'),
'type' => MENU_LOCAL_ACTION,
'file' => 'unl_cas.admin.inc',
'weight' => 1,
'weight' => 1,
);
$items['admin/config/people/unl_cas'] = array(
......@@ -74,19 +84,24 @@ function unl_cas_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('unl_cas_config'),
'file' => 'unl_cas.admin.inc',
'weight' => 1,
'weight' => 1,
);
return $items;
}
/**
* Implements hook_menu_alter().
*/
function unl_cas_menu_alter(&$items) {
$items['admin/people/create']['weight'] = 2;
$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();
if (array_key_exists('logoutRequest', $_POST)) {
......@@ -117,9 +132,13 @@ function unl_cas_validate() {
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') {
$cas = unl_cas_get_adapter();
unset($_GET['destination']);
drupal_goto($cas->getLoginUrl());
}
......@@ -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.
*/
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']) {
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) {
session_destroy();
$cas = unl_cas_get_adapter();
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) {
unl_load_zend_framework();
$user = array();
......@@ -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
* to be administrators. Also, automatically make users who are administrators
......@@ -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
* 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) {
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) {
$shared_prefix = unl_get_shared_db_prefix();
$shared_admin_role_id = unl_shared_variable_get('user_admin_role');
......@@ -290,6 +319,9 @@ function _unl_cas_is_user_default_site_administrator($username) {
return count($shared_admin_usernames) > 0;
}
/**
* Implements template_preprocess_user_picture().
*/
function unl_cas_preprocess_user_picture(&$variables) {
//Default image: https://planetred.unl.edu/mod/profile/graphics/defaultmedium.gif
if ($variables['account']->uid == 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment