First commit!
authorDavid Thompson <davet@gnu.org>
Mon, 26 Jan 2015 18:21:06 +0000 (13:21 -0500)
committerDavid Thompson <davet@gnu.org>
Mon, 26 Jan 2015 18:21:06 +0000 (13:21 -0500)
README.md [new file with mode: 0644]
auto_cas_user.info [new file with mode: 0644]
auto_cas_user.module [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..97ee2a8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,5 @@
+Auto CAS user
+=============
+
+Automatically create a CAS user that corresponds to the Drupal account
+with the same name upon first login.
diff --git a/auto_cas_user.info b/auto_cas_user.info
new file mode 100644 (file)
index 0000000..6de3d84
--- /dev/null
@@ -0,0 +1,5 @@
+name = Auto CAS User
+description = Automatically creates CAS users that correspond to Drupal usernames.
+core = 7.x
+package = Central Authentication Service
+dependencies[] = cas
diff --git a/auto_cas_user.module b/auto_cas_user.module
new file mode 100644 (file)
index 0000000..1938ff1
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+function auto_cas_user_cas_user_alter(&$cas_user) {
+  $username = $cas_user['name'];
+
+  // Test for existing CAS user
+  $count = db_select('cas_user', 'c')
+    ->condition('cas_name', $username)
+    ->countQuery()->execute()->fetchfield();
+
+  if($count == 0) {
+    $account = user_load_by_name($username);
+
+    if($account) {
+      // User exists but doesn't have a CAS user record, so create
+      // one.
+      db_insert('cas_user')
+        ->fields(array('cas_name' => $username,
+                       'uid' => $account->uid))
+        ->execute();
+    }
+  }
+}
\ No newline at end of file