From: Andrew Engelbrecht Date: Fri, 8 Apr 2022 21:16:34 +0000 (-0400) Subject: various corrections for long-term member check X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2e644466b856a0eec76f1320058d2cf0a1c58a29;p=fsfdrupalauth.git various corrections for long-term member check --- diff --git a/docs/fsf-drupal-auth.md b/docs/fsf-drupal-auth.md index 3c1fd52..d9579a1 100644 --- a/docs/fsf-drupal-auth.md +++ b/docs/fsf-drupal-auth.md @@ -18,7 +18,7 @@ SQL queries in `config/authsources.php` should be something like the following: // don't filter with 'and c.is_test = 0' because these may be useful for FSF staff 'query_membership' => "select c.status_id from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.status = 1 and d.is_deleted = 0 and c.status_id is not NULL and a.name = :username and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) order by c.status_id limit 10;", 'query_staff' => "select a.name as is_fsf_staff from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_contact c on b.contact_id=c.id inner join civicrm.civicrm_relationship d on c.id=d.contact_id_a where a.name=:username and a.status=1 and c.is_deleted=0 and d.relationship_type_id=4 and d.contact_id_b=FOOBAR and d.is_active=1 and (d.end_date>NOW() or d.end_date is NULL) limit 1;", - 'query_long_term_member' => "select c.join_date from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.name = :username and c.status_id is not NULL and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) and c.join_date <= :member_long_term_date order by c.join_date limit 1;", + 'query_membership_long_term' => "select c.join_date from drupal.users a inner join civicrm.civicrm_uf_match b on a.uid=b.uf_id inner join civicrm.civicrm_membership c on b.contact_id=c.contact_id inner join civicrm.civicrm_contact d on c.contact_id=d.id where a.name = :username and c.status_id is not NULL and (c.status_id = 1 or c.status_id = 2 or c.status_id = 3 or c.status_id = 4) and c.join_date <= :member_long_term_date order by c.join_date limit 1;", ], diff --git a/lib/Auth/Source/FSFDrupalAuth.php b/lib/Auth/Source/FSFDrupalAuth.php index f09346b..8ee8f2c 100644 --- a/lib/Auth/Source/FSFDrupalAuth.php +++ b/lib/Auth/Source/FSFDrupalAuth.php @@ -44,6 +44,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase private $query_main; private $query_membership; private $query_staff; + private $query_membership_long_term; /** * Date for determining whether someone is a long-term member or not @@ -65,7 +66,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase parent::__construct($info, $config); // Make sure that all required parameters are present. - foreach (['dsn', 'username', 'password', 'query_main', 'query_membership', 'query_staff', 'member_long_term_date'] as $param) { + foreach (['dsn', 'username', 'password', 'query_main', 'query_membership', 'query_staff', 'query_membership_long_term', 'member_long_term_date'] as $param) { if (!array_key_exists($param, $config)) { throw new Exception('Missing required attribute \''.$param. '\' for authentication source '.$this->authId); @@ -85,6 +86,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase $this->query_main = $config['query_main']; $this->query_membership = $config['query_membership']; $this->query_staff = $config['query_staff']; + $this->query_membership_long_term = $config['query_membership_long_term']; $this->member_long_term_date = $config['member_long_term_date']; if (isset($config['options'])) { $this->options = $config['options']; @@ -200,7 +202,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase * query the database with arbitrary queries that only require a user name. * */ - private function query_db($queryname, $username) + private function query_db($queryname, $query_params) { assert(is_string($queryname)); assert(is_string($username)); @@ -215,7 +217,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase } try { - $sth->execute(['username' => $username]); + $sth->execute($query_params); } catch (PDOException $e) { throw new Exception('fsfdrupalauth:'.$this->authId. ': - Failed to execute queryname: '.$queryname.': '.$e->getMessage()); @@ -243,7 +245,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase // query on membership // - $membership_data = $this->query_db('query_membership', $username); + $membership_data = $this->query_db('query_membership', ['username' => $username]); if (count($membership_data) === 0) { // No rows returned - invalid username @@ -274,7 +276,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase // query on first membership join date // - $membership_date_data = $this->query_db('query_membership_date', $username, $member_long_term_date); + $membership_date_data = $this->query_db('query_membership_long_term', ['username' => $username, 'member_long_term_date' => $member_long_term_date]); if (count($membership_date_data) === 0) { // No rows returned - no old membership start @@ -298,7 +300,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase // query on staff // - $staff_data = $this->query_db('query_staff', $username); + $staff_data = $this->query_db('query_staff', ['username' => $username]); if (count($staff_data) === 0) { // No rows returned - invalid username @@ -365,7 +367,7 @@ class FSFDrupalAuth extends \SimpleSAML\Module\core\Auth\UserPassBase //Logger::debug('fsfdrupalauth:'.$this->authId.': entered password: '.$password); - $user_data = $this->query_db('query_main', $username); + $user_data = $this->query_db('query_main', ['username' => $username]); if (count($user_data) === 0) {