From 6371dfc1f4902f2e41e25ee874c7f6916a05ea8f Mon Sep 17 00:00:00 2001 From: David Thompson Date: Mon, 26 Jan 2015 13:21:06 -0500 Subject: [PATCH] First commit! --- README.md | 5 +++++ auto_cas_user.info | 5 +++++ auto_cas_user.module | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 README.md create mode 100644 auto_cas_user.info create mode 100644 auto_cas_user.module diff --git a/README.md b/README.md new file mode 100644 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 index 0000000..6de3d84 --- /dev/null +++ b/auto_cas_user.info @@ -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 index 0000000..1938ff1 --- /dev/null +++ b/auto_cas_user.module @@ -0,0 +1,23 @@ +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 -- 2.25.1