From 09fae03844138ac249d691a880a7555aa7ef7133 Mon Sep 17 00:00:00 2001
From: Bradley M. Froehle <brad.froehle@gmail.com>
Date: Sat, 5 Mar 2011 14:43:30 -0800
Subject: [PATCH] Begin work on cleaning up CAS settings.

---
 cas.admin.inc |   18 ++----------------
 cas.install   |   21 +++++++++++++++++++++
 cas.module    |    8 ++------
 3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/cas.admin.inc b/cas.admin.inc
index fd20374..0f9d16f 100644
--- a/cas.admin.inc
+++ b/cas.admin.inc
@@ -226,20 +226,13 @@ function cas_admin_settings() {
 
 
   // Settings for redirection upon first login
-  $form['pages']['cas_first_login'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Force redirection on initial login'),
-    '#default_value' => variable_get('cas_first_login', 0),
-    '#description' => t("Activate this option if you want a user to be directed to the following page after their first CAS login."),
-  );
-
   $form['pages']['cas_first_login_destination'] = array(
     '#type' => 'textfield',
     '#title' => t('Initial login landing page'),
     '#default_value' => variable_get('cas_first_login_destination', ''),
     '#size' => 30,
     '#maxlength' => 255,
-    '#description' => t("Drupal path or URL. An example path is '<em>blog</em>' for the blog page. '&lt;front&gt;' is the front page. An example URL is '<em>http://www.example.com</em>'."),
+    '#description' => t("Enter a Drupal path or URL here if you want the user to be redirected to this page after their first CAS login. An example path is <em>blog</em> for the blog page, <em>&lt;front&gt;</em> for the front page, or <em>user</em> for the user's page. An example URL is <em>http://www.example.com</em>."),
   );
 
   // Setting for message displayed to user upon successfull login
@@ -251,20 +244,13 @@ function cas_admin_settings() {
   );
 
   // Setting for page to return to after a CAS logout
-  $form['pages']['cas_logout_redirect'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Redirect user on logout'),
-    '#default_value' => variable_get('cas_logout_redirect', 0),
-    '#description' => t("Activate this option if you want a user to be directed to the following page after logging out of CAS. The logout destination must be specified below."),
-  );
-
   $form['pages']['cas_logout_destination'] = array(
     '#type' => 'textfield',
     '#title' => t('Logout destination'),
     '#default_value' => variable_get('cas_logout_destination', ''),
     '#size' => 30,
     '#maxlength' => 255,
-    '#description' => t("URL. An example URL is '<em>http://www.example.com</em>'. You can also use '&lt;front&gt;' for the front page."),
+    '#description' => t("Enter a Drupal path or URL here if you want a user to be redirected to this page after logging out of CAS. An example path is <em>blog</em> for the blog page or <em>&lt;front&gt;</em> for the front page. An example URL is <em>http://www.example.com</em>."),
   );
 
 
diff --git a/cas.install b/cas.install
index b459a28..caf11f6 100644
--- a/cas.install
+++ b/cas.install
@@ -205,3 +205,24 @@ function cas_update_6302() {
   variable_del('cas_hijack_user');
   return $messages;
 }
+
+/**
+ * Simplify CAS settings.
+ */
+function cas_update_6303() {
+  // We have removed the cas_first_login option, and instead verify that
+  // cas_first_login_destination is non-empty. To preserve functionality,
+  // we need to update the destination to '<front>' if previously the option
+  // was selected but the destination was empty.
+  if (variable_get('cas_first_login', FALSE) && variable_get('cas_first_login_destination', '') == '') {
+    variable_set('cas_first_login_destination', '<front>');
+  }
+  variable_del('cas_first_login');
+
+  // Similarly for the cas_logout_redirect and cas_logout_destination
+  // variables.
+  if (variable_get('cas_logout_redirect', FALSE) && variable_get('cas_logout_destination', '') == '') {
+    variable_get('cas_logout_destination', '<front>');
+  }
+  variable_del('cas_logout_redirect');
+}
\ No newline at end of file
diff --git a/cas.module b/cas.module
index a12deef..087efc5 100644
--- a/cas.module
+++ b/cas.module
@@ -466,7 +466,7 @@ function cas_login_page($cas_first_login = FALSE) {
   global $user;
   $destination = variable_get('site_frontpage', 'node');
   // If it is the user's first CAS login and initial login redirection is enabled, go to the set page
-  if ($cas_first_login && variable_get('cas_first_login', FALSE)) {
+  if ($cas_first_login && variable_get('cas_first_login_destination', '')) {
     $destination = variable_get('cas_first_login_destination', '');
   }
   elseif (isset($_REQUEST['destination'])) {
@@ -524,12 +524,8 @@ function cas_logout() {
   $destination = preg_replace("/(destination=|caslogout)/", "", drupal_get_destination());
 
   // If there was no override and admin has set and enabled a logout destination, look for it
-  if (empty($destination) && variable_get('cas_logout_redirect', 0)) {
+  if (empty($destination) && variable_get('cas_logout_destination', '')) {
     $destination = variable_get('cas_logout_destination', '');
-    // redirecti is enabled but no url is given - default to baseurl
-    if (empty($destination)) {
-      $destination = $base_url;
-    }
   }
 
   //Make it an absolute url.  This will also convert <front> to the front page.
-- 
1.7.3.5

