From 7531155be49bc96ff07cd41c9f3d966c5d326414 Mon Sep 17 00:00:00 2001
From: Bradley M. Froehle <brad.froehle@gmail.com>
Date: Thu, 14 Apr 2011 12:29:34 -0700
Subject: [PATCH] Issue #1127472: Have CAS first login redirection work for admin created accounts.

---
 cas.module |    3 ++-
 cas.test   |   12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/cas.module b/cas.module
index feb42ed..6aaaada 100644
--- a/cas.module
+++ b/cas.module
@@ -125,7 +125,6 @@ function cas_login_check() {
       if ($account = cas_user_register($cas_name)) {
         // Record that the user was just registered.
         $edit = array('cas_first_login' => TRUE);
-        $cas_first_login = TRUE;
       }
       else {
         // The account could not be created, set a message.
@@ -138,6 +137,8 @@ function cas_login_check() {
 
     // final check to make sure we have a good user
     if ($account && $account->uid > 0) {
+      $cas_first_login = !$account->login;
+
       // Save single sign out information
       if (!empty($_SESSION['cas_ticket'])) {
         _cas_single_sign_out_save_token($account);
diff --git a/cas.test b/cas.test
index ba52f92..9c32cbe 100644
--- a/cas.test
+++ b/cas.test
@@ -521,6 +521,18 @@ class CasLoginRedirectionTestCase extends CasTestHelper {
     $this->casLogin($cas_name);
     $this->assertUrl('');
     $this->drupalLogout();
+
+    // Initial login with a admin-created account goes to the specified
+    // destination.
+    $account = $this->casCreateUser();
+    $this->casLogin($account);
+    $this->assertUrl("node/$node->nid");
+    $this->drupalLogout();
+
+    // The second login should not be redirected.
+    $this->casLogin($account);
+    $this->assertUrl('');
+    $this->drupalLogout();
   }
 }
 
-- 
1.7.4.1

