Skip to content
Snippets Groups Projects
Commit 4ca59cc1 authored by Tim Steiner's avatar Tim Steiner
Browse files

[gh-49] Merging changes into production

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/production@368 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent 84133611
Branches
Tags
No related merge requests found
......@@ -232,9 +232,10 @@ EOF;
'default' => $new_prefix,
// shared tables across all sites
'filter' => $shared_prefix,
'filter_format' => $shared_prefix,
'wysiwyg' => $shared_prefix,
'filter' => $shared_prefix,
'filter_format' => $shared_prefix,
'unl_cas_settings' => $shared_prefix,
'wysiwyg' => $shared_prefix,
);
$settings['databases'] = array(
......
......@@ -65,4 +65,49 @@ function unl_cas_user_import_submit($form, &$form_state) {
if($user) drupal_set_message('<li>User '.$name.' successfully created.</li>');
}
?>
function unl_cas_config($form, &$form_state) {
$form['ldap'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#title' => 'LDAP Settings',
);
$form['ldap']['uri'] = array(
'#type' => 'textfield',
'#title' => 'URI',
'#description' => 'ie: ldap://example.com/',
'#default_value' => unl_cas_get_setting('ldap_uri'),
'#parents' => array('ldap', 'uri'),
'#required' => TRUE,
);
$form['ldap']['dn'] = array(
'#type' => 'textfield',
'#title' => 'Distinguished Name (DN)',
'#description' => 'ie: uid=admin,dc=example,dc=com',
'#default_value' => unl_cas_get_setting('ldap_dn'),
'#parents' => array('ldap', 'dn'),
'#required' => TRUE,
);
$form['ldap']['password'] = array(
'#type' => 'password',
'#title' => 'Password',
'#parents' => array('ldap', 'password'),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Update',
);
return $form;
}
function unl_cas_config_submit($form, &$form_state) {
unl_cas_set_setting('ldap_uri', $form_state['values']['ldap']['uri']);
unl_cas_set_setting('ldap_dn', $form_state['values']['ldap']['dn']);
unl_cas_set_setting('ldap_password', $form_state['values']['ldap']['password']);
}
......@@ -2,5 +2,8 @@
name = UNL CAS
description = Enables UNL CAS authentication/registration of users.
core = 7.x
version = "7.x-1.0-20101129"
configure = admin/config/people/unl_cas
files[] = unl_cas.module
files[] = unl_loader.php
<?php
function unl_cas_schema() {
$schema = array();
$schema['unl_cas_settings'] = array(
'description' => 'Settings for the UNL CAS module.',
'fields' => array(
'name' => array(
'description' => 'The name of the variable.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The value of the variable.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'translatable' => TRUE,
),
),
'primary key' => array('name'),
);
return $schema;
}
/**
* Updates prior to upgrading to unl module 7.x-1.0
*/
function unl_cas_update_7100() {
$table = array(
'description' => 'Settings for the UNL CAS module.',
'fields' => array(
'name' => array(
'description' => 'The name of the variable.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'value' => array(
'description' => 'The value of the variable.',
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'translatable' => TRUE,
),
),
'primary key' => array('name'),
);
db_create_table('unl_cas_settings', $table);
}
......@@ -59,6 +59,16 @@ function unl_cas_menu() {
'weight' => 1,
);
$items['admin/config/people/unl_cas'] = array(
'title' => 'UNL CAS',
'description' => 'Configure the UNL CAS module',
'access callback' => 'unl_cas_user_is_administrator',
'page callback' => 'drupal_get_form',
'page arguments' => array('unl_cas_config'),
'file' => 'unl_cas.admin.inc',
'weight' => 1,
);
return $items;
}
......@@ -79,10 +89,8 @@ function unl_cas_validate() {
if ($auth) {
$username = $cas->getUsername();
$user = user_load_by_name($username);
if (!$user) {
$user = unl_cas_import_user($username);
}
$user = unl_cas_import_user($username);
if ($GLOBALS['user']->uid != $user->uid) {
$GLOBALS['user'] = $user;
user_login_finalize();
......@@ -161,28 +169,54 @@ function unl_cas_user_logout($account) {
}
function unl_cas_import_user($username) {
$xml = @file_get_contents('http://peoplefinder.unl.edu/service.php?format=xml&uid=' . $username);
if ($xml) {
$dom = new DOMDocument();
$dom->loadXML($xml);
$firstName = $dom->getElementsByTagName('givenName')->item(0)->textContent;
$lastName = $dom->getElementsByTagName('sn')->item(0)->textContent;
$email = $dom->getElementsByTagName('mail')->item(0)->textContent;
$displayName = $dom->getElementsByTagName('displayName')->item(0)->textContent;
$user = array();
// First, try getting the info from LDAP.
try {
$ldap = new Unl_Ldap(unl_cas_get_setting('ldap_uri'));
$ldap->bind(unl_cas_get_setting('ldap_dn'), unl_cas_get_setting('ldap_password'));
$results = $ldap->search('dc=unl,dc=edu', 'uid=' . $username);
if (count($results) > 0) {
$result = $results[0];
$user['firstName'] = $result['givenname'][0];
$user['lastName'] = $result['sn'][0];
$user['email'] = $result['mail'][0];
$user['displayName'] = $result['displayname'][0];
}
}
else {
$email = $username . '@unl.edu';
catch (Exception $e) {
// don't do anything, just go on to try the people finder method
}
// Next, if LDAP didn't work, try peoplefinder.
if (!isset($user['email'])) {
$xml = @file_get_contents('http://peoplefinder.unl.edu/service.php?format=xml&uid=' . $username);
if ($xml) {
$dom = new DOMDocument();
$dom->loadXML($xml);
$user['firstName'] = $dom->getElementsByTagName('givenName')->item(0)->textContent;
$user['lastName'] = $dom->getElementsByTagName('sn')->item(0)->textContent;
$user['email'] = $dom->getElementsByTagName('mail')->item(0)->textContent;
$user['displayName'] = $dom->getElementsByTagName('displayName')->item(0)->textContent;
}
}
// Finally, if peoplefinder didn't work either, just guess.
if (!isset($user['email'])) {
$user['email'] = $username . '@unl.edu';
}
$userData = array(
'name' => $username,
'mail' => $email,
'mail' => $user['email'],
'status' => 1,
'timezone' => variable_get('date_default_timezone', @date_default_timezone_get()),
);
$user = user_save(NULL, $userData);
return $user;
$account = user_load_by_name($username);
return user_save($account, $userData);
}
/**
......@@ -258,3 +292,40 @@ function unl_cas_preprocess_user_picture(&$variables) {
$variables['user_picture'] = '<img class="profile_pic medium" src="http://planetred.unl.edu/pg/icon/unl_' . $username . '/medium" alt="' . $username . '\'s photo" />';
}
function unl_cas_get_setting($name, $default = NULL) {
$data = db_select('unl_cas_settings', 's')
->fields('s', array('value'))
->condition('s.name', $name)
->execute()
->fetchCol();
if (count($data) > 0) {
return unserialize($data[0]);
}
return $default;
}
function unl_cas_set_setting($name, $value) {
$value = serialize($value);
if (unl_cas_get_setting($name, '__foobar__') == '__foobar__') {
db_insert('unl_cas_settings')
->fields(array('name', 'value'))
->values(array($name, $value))
->execute();
}
else {
db_update('unl_cas_settings')
->fields(array('value' => $value))
->condition('name', $name)
->execute();
}
}
function unl_cas_user_is_administrator()
{
$user = $GLOBALS['user'];
if ($user && in_array(variable_get('user_admin_role'), array_keys($user->roles))) {
return TRUE;
}
return FALSE;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment