CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • v3.0 breaks the Joomla membership authentication plugin?
Pages: [1] 2

Author Topic: v3.0 breaks the Joomla membership authentication plugin?  (Read 6243 times)

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
v3.0 breaks the Joomla membership authentication plugin?
October 04, 2009, 01:07:05 pm
I've upgraded successfully to CiviCRM 3.0 on Joomla 1.5, but have just discovered that it appears to break the Joomla Civicrm Authentication plugin. Any Joomla user who is not a Super Administrator is treated as not having a valid membership and sent to the expired membership page. Super Administrators can login with no problems.

The only way round this I've found is to disable the plugins, but that then allows people to lign whose membership really has expired.

Has this problem been reported already and is there any workaround?

Thanks

ian

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: v3.0 breaks the Joomla membership authentication plugin?
October 04, 2009, 01:35:23 pm

that plugin is contributed and supported by the author. you might want to contact him via email / PM and see if he can take a look at the issue

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Re: v3.0 breaks the Joomla membership authentication plugin?
October 04, 2009, 02:41:35 pm
OK, will do

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Bug in CiviMember???
October 05, 2009, 02:21:08 pm
I did some delving and I think the problem is with CiviCRM, not the plugin. Sorry I'm not sure how exactly to go about reporting a bug (anyway my php skills aren't that great, so i want to check it is a bug!)

In civicrm/api/v2/Membership.php there's the deprecated compatilibility wrapper:

Code: [Select]
function civicrm_contact_memberships_get(&$contactID)
{
    return civicrm_membership_contact_get($contactID);
}

If you then look at the function "civicrm_membership_contact_get" that it calls in civicrm/api/v2/MembershipContact.php, it tests the value of the passed parameter to see if it's an integer (in which case it's recognised as a contactID passed from the compatibility wrapper).
line 138:
Code: [Select]
   } elseif( is_integer($params) ) {
But the value that is passed is a string representation of the contactID integer and so fails the test (and hence valid memberships get processed as if expired)

By forcing the compatibility wrapper function to pass the ID as an integer everything works fine.
Cheers
Ian

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: v3.0 breaks the Joomla membership authentication plugin?
October 11, 2009, 02:54:07 pm
Hi Ian,

I wrote this plugin ages ago and have been using it successfully ever since. I too recently went from 2.x to 3.0 and it is working for me. I know in the past there have been issues with the uf_match borking if a user changed their email address but now updating email from profiles works correctly in CiviCRM.

I'm not a coder by trade and don't have much time to get on these things. Do you know if there is an updated API we should be using?

Henry

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Re: v3.0 breaks the Joomla membership authentication plugin?
October 11, 2009, 04:52:23 pm
Hi Henry
I didn't notice a problem when i first upgraded because I had super-administrator status - and this bypasses the membership check. Does your site work ok when logging in with Registered status? - that's when I get trouble.

As I say the issue doesn't seem to be your plugin per se.
Line 124 in the plugin is
$contactID = CRM_Core_BAO_UFMatch::getContactId( $result->id );
but this core Civicrm function returns the contactID as a string not an integer. This wasn't a problem with the previous version
of "civicrm_contact_memberships_get" which retrieves the membership details for the given contact, but in v3.0, this function is replaced by another one "civicrm_membership_contact_get" which now tests if the contactID parameter is an integer.

Because $contactID is a string, however, the is_integer() function returns false. Really the test should be is_numeric() which returns true with a string representation of an integer. Of course the best thing would be if  CRM_Core_BAO_UFMatch::getContactId( ) returned an integer rather than a string.

Anyway to get round the problem I just forced a type conversion in your plugin by adding the line $contactID=$contactID+0; before passing it to "civicrm_contact_memberships_get()".  I don't suppose this is very elegant (I'm definitely not a php afficianado) but it appears to work!

Cheers

Ian

speleo

  • Ask me questions
  • ****
  • Posts: 396
  • Karma: 28
  • CiviCRM version: 4.3.1
  • CMS version: J! 2.5,9
  • MySQL version: 5.1
  • PHP version: 5.3.24
Re: v3.0 breaks the Joomla membership authentication plugin?
October 11, 2009, 11:45:50 pm
Hi Ian,

I'm Super Admin but have a "registered" account too just for testing. I can see members logging in fine so figure it must be working. Thanks for the heads up on the fix. Understand that it is quick and dirty but if it works thats cool.

When I get some time (or anyone else?) I'll look into the APIs and make sure I've got the latest versions. While the ones I'm using are V2 they aren't listed as depreciated (I think).

Henry

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Re: v3.0 breaks the Joomla membership authentication plugin?
October 12, 2009, 02:06:43 am
That's strange - it sounds like it's something specific to my installation, but as it all depends on how $contactID is cast by a core function I don't see how that can be the case ???. I don't know anything about the APIs I'm afarid (until i started tracking down the problem, I didn't know anything about any of it!)

Cheers
Ian

nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Re: v3.0 breaks the Joomla membership authentication plugin?
November 05, 2009, 11:19:26 am
This fix works for me too :-)

I didn't notice the problem at first as I was testing with an administrator account. When testing as a registered user after upgrading from 2.2.7 to 3.0.2, I was unable to log in whether my status was new, current or grace.

Adding
Code: [Select]
$contactID = $contactID+0; to line 128 of /plugins/authentication/civicrm.php as you suggest fixed it.

Thanks! Much appreciated.

Nic

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: v3.0 breaks the Joomla membership authentication plugin?
November 05, 2009, 12:10:02 pm

i just checked the api code and the CRM_Utils_Rule::integer function does handle the case if it is numeric

would be great if you can find the specific line of code where we require it to be an integer

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Re: v3.0 breaks the Joomla membership authentication plugin?
November 05, 2009, 12:35:31 pm
It's in the function "civicrm_membership_contact_get"  in civicrm/api/v2/MembershipContact.php. Line 138 tests the value of the passed parameter to see if it's an integer (in which case it's recognised as the legacy case where a contactID is passed from the compatibility wrapper).
line 138:
Code: [Select]
} elseif( is_integer($params) ) {
The contactID that the civicrm authentication plugin passes ($SontactID) is cast as a string and so fails the is_integer test (though it would return true in if test with is_numeric()). Adding 0 to the contact ID  froces it to betyped as an integer and so it then passes the test.

In the authentication plugin the contact ID is obtained on line 124:
Code: [Select]
$contactID = CRM_Core_BAO_UFMatch::getContactId( $result->id );This must mean that this core function is returning a string rather than an integer.

Hope this help

ian

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: v3.0 breaks the Joomla membership authentication plugin?
November 05, 2009, 12:40:15 pm

can u apply this patch:

Code: [Select]
svn diff api/v2/MembershipContact.php
Index: api/v2/MembershipContact.php
===================================================================
--- api/v2/MembershipContact.php        (revision 24884)
+++ api/v2/MembershipContact.php        (working copy)
@@ -124,7 +124,7 @@
 function civicrm_membership_contact_get(&$params)
 {   
     _civicrm_initialize();
-
+
     $activeOnly = false;
     if ( is_array($params) ) {
         $contactID = CRM_Utils_Array::value('contact_id', $params);
@@ -134,7 +134,7 @@
         } else {
             $activeOnly = false;
         }
-    } elseif( is_integer($params) ) {
+    } elseif( CRM_Utils_Rule::integer($params) ) {
         $contactID = $params;
     } else {
         return civicrm_create_error( 'Paramers can be only of type array or integer' );

and see if it works

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

cleit

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
Re: v3.0 breaks the Joomla membership authentication plugin?
November 06, 2009, 12:42:19 pm
Yes that does the job, thanks.

BUT, back at the authentication plugin I think I've found a number of incompatibilities with v 3.0 that i didn't notice at first (and I think some of these may explain why not everyone has found valid logins blocked).

1) If there is no membership for a contact the plugin incorrectly allows a login.

This seems to be because of the code in civicrm.php at line 139:
Code: [Select]
138 // Make sure there is a membership record.
139 if ($membership['is_error'] == 1){
140 $response->status = JAUTHENTICATE_STATUS_FAILURE;
141 $response->error_message = 'no memberships for this contact';
142 ob_end_clean();
143 header($civicrm_redirect_old_membership);
144 exit;}
This no longer works because the action when a contact has no membership has been changed from raising an error code to setting the 'record_count' element of the membership array to 0 (api/v2/MembershipContact.php
 line 158):
 
Code: [Select]
155    if ( empty( $membershipValues ) ) {
156        # No results is NOT an error!
157        # return civicrm_create_error('No memberships for this contact.');
158        $membershipValues['record_count'] = $recordCount;
159        return $membershipValues;
160    }


A record_count of 0 is what line 139 of the the plugin now needs to test for (rather than the the 'is_error' element:
Code: [Select]
139 if ($membership['is_error'] == 1 || $membership['record_count']==0){


2)If a pay-later membership is taken out then a sign-in is allowed while the membership is still pending.
This is because of this code at line 158 in the plugin:
Code: [Select]
158 if ($membership_status['id'] <= $civicrm_is_current){
159 $response->status = JAUTHENTICATE_STATUS_SUCCESS;
160 $response->error_message = '';}
161 else {
162 $response->status = JAUTHENTICATE_STATUS_FAILURE;
163 $response->error_message = 'membership not valid';
164 ob_end_clean();
165 header($civicrm_redirect_old_membership);
166 exit;}
167 }
For a Paylater membership, the start, join and end dates are null until the membership is activated. The $membership_status['id'] is determined by the function "getMembershipStatusByDate" (CRM/Member/BAO/MembershipStatus.php, ), but this function can't set the 'id' element if all these dates are null. In line 158 above $membership_status['id'] is therefore empty and the logical test evaluates to true and so allows login.
To get around this, the section of code in the plugin needs to be preceded by something like
Code: [Select]
if(empty($membership_status['id'])) {
$membership_status['id']=9999;
}
which sets a large dummy value if none has already been set and so the login is prevented

3) The functions that return the membership status to the plugin ignore the manually set Membership Status
Theplugin ultimately gets the membership status from  "civicrm_membership_status_calc" which in turns calculates the status purely from the start, join and end dates using the function "getMembershipStatusByDate" (CRM/Member/BAO/MembershipStatus.php). (I'm guessing that this may previously have got its status value from the Status_id value in the civicrm_membership table - but I don't actually know).
getMembershipStatusByDate calculates the status from first principles using the membership status rules, and completely ignores the manual status setting for the membership. So you can cancel the membership, or mark it expired and it will still  report it as current unless the End date is also changed.
I think the plugin either needs to get its status from the civicrm_membership Status_id value, or else perhaps be conservative and block logins if either the manual status setting, or the getMembershipStatusByDate calculation suggests that the membership is not current.

As I say, my php skills ain't that great, so some of the stuff above may be wrong, but the plugin seems to work correctly after these changes.

Cheers

ian


nicol

  • I post occasionally
  • **
  • Posts: 95
  • Karma: 5
  • CiviCRM version: 4.2, 4.3, 4.4
  • CMS version: Joomla 2.5.x, Joomla 3.x Wordpress 3.x, Drupal 7.x
  • MySQL version: 5.x
  • PHP version: 5.3 / 5.4
Re: v3.0 breaks the Joomla membership authentication plugin?
November 06, 2009, 03:53:03 pm
Posted by: Donald Lobo
Quote
can u apply this patch:
Yes that worked, thanks.

Posted by: Cleit
Quote
1) If there is no membership for a contact the plugin incorrectly allows a login.

not for me - a contact without a connected membership wouldn't log in. same with a normal joomla user with no contact.

Quote
2)If a pay-later membership is taken out then a sign-in is allowed while the membership is still pending.

again this seemed to work ok - I couldn't get in if my payment status was 'pending'

Quote
3) The functions that return the membership status to the plugin ignore the manually set Membership Status

I did see that - tho I've always changed it via the expiry date - think this might have been the same with 2.2.7?

Cheers
nic
« Last Edit: November 06, 2009, 03:55:00 pm by nicol »

lkbhokie

  • Guest
Re: v3.0 breaks the Joomla membership authentication plugin?
November 11, 2009, 02:32:16 pm
I also had the problem with registered users not being able to login and the patch fixed that, but when a visitor has a failed login attempt (i.e. wrong un/pw), it still goes to a blank white page.  Does anyone else have this?

J1.5.14
CiviCRM 3.0.alpha1
Civiuser 0.4
« Last Edit: November 12, 2009, 04:07:41 pm by lkbhokie »

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • v3.0 breaks the Joomla membership authentication plugin?

This forum was archived on 2017-11-26.