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 CiviContribute (Moderator: Donald Lobo) »
  • Membership Best Practices
Pages: 1 [2]

Author Topic: Membership Best Practices  (Read 2688 times)

shinzan

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 0
  • CiviCRM version: 4.2
  • CMS version: Joomla 2.5.8
  • MySQL version: 5
  • PHP version: 5
[SOLVED] Re: Membership Best Practices
January 24, 2013, 12:24:35 pm
Ok so I went ahead with my design and I wrote a function to autologin a joomla user in the process which I will give away here

I'm using breezing forms so some of the code uses its api like running sql and getting url parameter strings but you can get the jist, of how it works if you are a php coder.

I login a new user by getting the joomla email address of the currently logged in user, then i grab the md5 of the password for that user, i then swap the password to 'demo', then i call the joomla api and login that user, next i put back the origional password of the user.  The user is none the wiser i have logged them back in after i update the civicrm_uf_match table, and all is right with the world....

Code: [Select]
$hash = ff_getParam('ff_param_hash','');

$memberid = decryptValue($hash);
$memberid = intval($memberid);

//Determine if this memberid is a club or individual and hide the appropriate button

if ($memberid > 0) {
  //SWAP THE CIVICRM ID AND RELOGIN THE USER TO APPEAR TO CIVICRM AS 'ANOTHER' USER

  $user = JFactory::getUser();
  $joomlauserid = $user->id;

  $sql = "UPDATE civicrm_uf_match SET contact_id = $memberid WHERE uf_id = $joomlauserid";

  ff_select($sql);

  $app = JFactory::getApplication();
  $user = JFactory::getUser();

  $user_id = $user->get('id');
  $username = $user->get('username');
  $email = $user->get('email');


$db = JFactory::getDBO();
$query = "SELECT * FROM #__users WHERE email = '" . $email . "'";                                                                     
$db->setQuery($query);
$rows = $db->loadObjectList();
$origionalpass = $rows[0]->password;
$joomlausername = $rows[0]->username;

$demopass = '27fcbd2216b8ae03b63a13633371f012:tDurytryP9yi7QuMrda48jGFS8cPVCk0'; //this is hash for passowrd "demo"
$query = "UPDATE `#__users` SET `password`= '". $demopass. "' WHERE `email` = '" . $email. "'";
$db->setQuery($query);
$update = $db->loadObjectList();   
 
  //preform the login action

define( '_JEXEC', 1 );
define('JPATH_BASE', '/var/www/virtual/usakaratemembership.com/htdocs' );
define( 'DS', DIRECTORY_SEPARATOR );
require_once('configuration.php');
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );

/* Create the Application */
$mainframe =& JFactory::getApplication('site');
jimport('joomla.plugin.helper');

$credentials = array();
$credentials['username'] = "$joomlausername";
$credentials['password'] = "demo";

 $options = array();
$options['remember'] = false;

//preform the login action

$error = $mainframe->login($credentials,$options);
$user = JFactory::getUser();

//$mainframe->logout();
//now you are logged out


// change back password back to the origional hash
  $query = "UPDATE `#__users` SET `password`= '". $origionalpass . "' WHERE `email` = '" . $email. "'";
  $db->setQuery($query);
  $update = $db->loadObjectList();

 $controlpanelurl = retControlPanelURL();
 ff_redirect($controlpanelurl);

} //memberid > 0


You can see the custom dashboard I have created in the attatchment that gives the user exactly what I want them to have and nothing else, everything works and you can swith civicrm users back and forth easily. 

The next problem was guest memberships.  The solution by    Eileen is pretty awesome, but building on what I had already here is what I did to get similar functionality.

My custom dashboard has buttons for membership signup.  They are shown their "current member" on the dashboard, if they click new membership then it renews the "current membership."  If they click "Add membership" then it silently logs them out and encrypts their userid in a cookie along with the encrypted time they logged out silently.  Then they are redirected to the membership signup page.  When they are finished registering the new membership, and they click on the joomla menu item "My control panel"  The code checks to see if its within 5 minutes of the encrypted cookie being created.  If it is they are silently logged back in provided the email of the new member matches the email within the encrypted cookie. 

I am very happy with the solution and I hope its helpful to someone else, if not at least I can say I've tried to give back to CiviCRM for all the excellent help and support I've been given!  This allows me to get the exact funtionality I want namely:

1.) Allowing the joomla user to edit all memberships in CIVICRM that match the email address of the joomla user (email must be unique in the joomla table so no security issue there)

2.) Guest memberships are available because once they are created with the same user email as the joomla login account they can edit it with the above logic

3.) Everything is completely transparent to the user, and no core hacks to joomla or to civicrm.  My Hack serves as an intermediary to both system.

Thank you very much,

David
« Last Edit: January 26, 2013, 05:12:27 pm by shinzan »

shinzan

  • I post occasionally
  • **
  • Posts: 49
  • Karma: 0
  • CiviCRM version: 4.2
  • CMS version: Joomla 2.5.8
  • MySQL version: 5
  • PHP version: 5
[SOLVED] Re: Membership Best Practices
January 26, 2013, 05:02:13 pm
Marking Solved

http://forum.civicrm.org/index.php/topic,27302.msg117230.html#msg117230

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviContribute (Moderator: Donald Lobo) »
  • Membership Best Practices

This forum was archived on 2017-11-26.