From d1bf6727f765bfcae5327277c1b1876eaf7d3496 Mon Sep 17 00:00:00 2001
From: Bradley M. Froehle <brad.froehle@gmail.com>
Date: Thu, 21 Apr 2011 09:51:43 -0700
Subject: [PATCH] Use !account->login instead of $edit['cas_first_login']

---
 cas.api.php |    7 +++----
 cas.module  |   10 ++--------
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/cas.api.php b/cas.api.php
index b609a62..1dc7753 100644
--- a/cas.api.php
+++ b/cas.api.php
@@ -70,10 +70,9 @@ function hook_cas_user_alter(&$cas_user) {
  * account properties. For example, modules may want to synchronize Drupal
  * user roles or profile information with LDAP properties.
  *
- * The 'cas_first_login' flag in $edit will be set to TRUE if the CAS user was
- * just registered and this is their first login. This is useful if you want
- * to only synchronize information when an account is created instead of on
- * every login.
+ * If you would like to synchronize information only for new accounts, you may
+ * examine the value of $account->login which will be 0 if the user has never
+ * logged in before.
  *
  * The 'cas_user' key in $edit contains all information returned from
  * hook_cas_user_alter().
diff --git a/cas.module b/cas.module
index 757649b..2b8fa39 100644
--- a/cas.module
+++ b/cas.module
@@ -117,17 +117,13 @@ function cas_login_check() {
     }
 
     $account = cas_user_load_by_name($cas_name);
-    $cas_first_login = FALSE;
 
     // Automatic user registration.
     if (!$account && $cas_user['register']) {
       // No account could be found and auto registration is enabled, so attempt
       // to register a new user.
-      if ($account = cas_user_register($cas_name)) {
-        // Record that the user was just registered.
-        $edit = array('cas_first_login' => TRUE);
-      }
-      else {
+      $account = cas_user_register($cas_name);
+      if (!$account) {
         // The account could not be created, set a message.
         if ($cas_force_login) {
           drupal_set_message(t('A new account could not be created for %cas_name. The username is already in use on this site.', array('%cas_name' => $cas_name)), 'error');
@@ -1143,7 +1139,6 @@ function cas_user_register($cas_name, $options = array()) {
   if (!empty($options['invoke_cas_user_presave'])) {
     // Populate $edit with some basic properties.
     $edit = array(
-      'cas_first_login' => TRUE,
       'cas_user' => array(
         'name' => $cas_name,
       ),
@@ -1154,7 +1149,6 @@ function cas_user_register($cas_name, $options = array()) {
 
     // Clean up extra variables before saving.
     unset($edit['cas_user']);
-    unset($edit['cas_first_login']);
 
     $account = user_save($account, $edit);
   }
-- 
1.7.4.1

