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) »
  • Create new user in front-end using CiviCRM
Pages: [1] 2

Author Topic: Create new user in front-end using CiviCRM  (Read 8002 times)

andrews

  • Guest
Create new user in front-end using CiviCRM
February 12, 2008, 12:17:42 pm
I just installed CiviCRM 1.9 on Joomla 1.5 and I'm trying to figure out how to give my users the ability to create their own free memberships online (without linking it to the contribution page). I guess what I'm really looking for is a front-end login module that allows users to login and then have all their information (contact dashboard) available to them.  I'm sure i'm just overlooking something but I'm lost. Thanks.

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Create new user in front-end using CiviCRM
February 13, 2008, 02:42:42 pm
There is NOT an option in Joomla to "create joomla user" and "enter CiviCRM contact info" on a single form (as there is with Drupal).

HOWEVER - you can expose forms for users to enter and update their contact information using the CiviCRM Profile functionality - and creating menu items in the front-end which point to the Profile forms as well as the CiviCRM Contact Dashboard.

If you haven't read through the Profile Admin doc here - start with this:
http://wiki.civicrm.org/confluence/display/CRMDOC/Profiles+Admin

Then check out:
http://wiki.civicrm.org/confluence/display/CRMDOC/Configuring+Front-end+Profile+Listings+and+Forms+in+Joomla%21+Sites
http://wiki.civicrm.org/confluence/display/CRMDOC/Configuring+Front-end+Contact+Dashboard+in+Joomla%21+Sites
Protect your investment in CiviCRM by  becoming a Member!

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
February 28, 2008, 07:32:47 am
I have a question.

Is there a way, once you've imported a bunch of members (I guess you import them as contacts), is it possible to automate the creation of a Joomla user based on this contact information?

Using 2.0b3 and J!1.5

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Create new user in front-end using CiviCRM
February 28, 2008, 11:03:36 am
CiviCRM has a function to do the reverse - create a CiviCRM contact record for every Joomla user:
http://wiki.civicrm.org/confluence/display/CRMDOC/Synchronize+Users-to-Contacts

I guess if you can import Joomla users - then you can tell CiviCRM to make contact records for them using this function - altho I haven't heard of folks doing this. (I have seen posts about folks doing it in Drupal, using a User Import module.)

Protect your investment in CiviCRM by  becoming a Member!

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: Create new user in front-end using CiviCRM
February 28, 2008, 12:30:11 pm

It is possible to do so :) but there is no code to do it right now.

For joomla 1.0.x, we have most of the pieces we need to do it. We just need to loop through for all the contacts you want users created and then call the function to create a user (CRM_Core_BAO_CMSUser::createJoomlaUser). In a batch script, you will need to make some decisions on what the user name and password for the newly created user will be

Not sure how applicable this is to 1.5, but i suspect its pretty close. Please share your work with others if you do implement it

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

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
February 28, 2008, 03:12:20 pm
Pretty far beyond my skillset but I will give it a try!

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
March 26, 2008, 12:29:34 pm
Did I see on a feature list that this had been added to 2.0.1 for Joomla 1.0?

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: Create new user in front-end using CiviCRM
March 26, 2008, 02:14:23 pm

If you did see it, it should be there :) You might want to test it and check it works on 1.0.x

This feature definitely DOES NOT work as is with 1.5.x. Some db column names have changed in 1.5

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

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
March 31, 2008, 06:21:13 am
I don't have a 1.0.x installation at this point.

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
April 02, 2008, 08:40:54 am
Quote from: Donald Lobo on March 26, 2008, 02:14:23 pm

If you did see it, it should be there :) You might want to test it and check it works on 1.0.x

This feature definitely DOES NOT work as is with 1.5.x. Some db column names have changed in 1.5

lobo


Should be an easy fix then :)  Do you know offhand what the db column names are for 1.0? Also what files touch this in the Civicrm install?

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: Create new user in front-end using CiviCRM
April 02, 2008, 01:09:30 pm
check CRM/Core/BAO/CMSUser.php, function createJoomlaUser (line 463). I think aro_id changed names (not sure).

Here is some untested code for 1.5 to replace this function contributed by Rob S (a core Joomla dev). Please report back on any changes you had to make

Code: [Select]
static function createJoomlaUser( &$params, $mail )
    {
        $acl         = &JFactory::getACL();
        $userParams    = JComponentHelper::getParams('com_users');
        $userType    = $userParams->get('new_usertype');

        // Prepare the values for a new Joomla! user.
        $values                 = array();
        $values['name']            = trim($params['cms_name']);
        $values['username']        = trim($params['cms_name']);
        $values['password']        = $params['cms_pass'];
        $values['password2']    = $params['cms_confirm_pass'];
        $values['email']        = trim($params[$mail]);
        $values['gid']            = $acl->get_group_id( '', $userType);

        // Get an empty JUser instance.
        $user = &JUser::getInstance(0);
        $user->bind($values);

        // Store the Joomla! user.
        if (!$user->store()) {
            // Error can be accessed via $user->getError();
            return false;
        }

        return $user->get('id');
    }
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
April 07, 2008, 09:34:22 am
Mkay I replaced the function:

Code: [Select]
static function createJoomlaUser( &$params, $mail )
{
$config =& CRM_Core_Config::singleton( );
$dao =& new CRM_Core_DAO( );
$name = $dao->escape( $params['cms_name'] );

$fname = trim($params['cms_name']);
$uname = trim($params['cms_name']);
$pwd = md5($params['cms_pass']);
$email = trim($params[$mail]);
$date = date('y-m-d h:i:s');

//In Joomla, Registered User is fixed to 18, at some point we should make this dynamic
$userType = 'Registered';
$userTypeId = '18';

//Get MySQL Table Prefix eg.'jos_'
list( $prefix, $table ) = split( '_', $config->userFrameworkUsersTableName );

$db_cms = DB::connect($config->userFrameworkDSN);
if ( DB::isError( $db_cms ) ) {
die( "Cannot connect to UF db via $dsn, " . $db_cms->getMessage( ) );
}

require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction( );

//1.Insert into 'jos_users' table
$sql = "INSERT INTO {$config->userFrameworkUsersTableName} VALUES
('', '$fname', '$uname', '$email', '$pwd', '$userType', 0, 1, $userTypeId, '$date', '0000-00-00 00:00:00', '', '')";

$query = $db_cms->query( $sql );

//Fetch id of newly added user
$id_sql = "SELECT id FROM {$config->userFrameworkUsersTableName} where username = '$uname'";
$id_query = $db_cms->query( $id_sql );
$id_row = $id_query->fetchRow( DB_FETCHMODE_ASSOC ) ;
$id = $id_row['id'];

//2.Insert into 'jos_core_acl_aro' table
$table = "{$prefix}_core_acl_aro";
$acl_sql = "INSERT INTO {$table} VALUES ('','users','$id',0,'$uname',0)";
$acl_query = $db_cms->query( $acl_sql );

//Fetch aro_id of newly added acl
$aro_id_sql = "SELECT aro_id FROM {$table} where value = '$id'";
$aro_id_query = $db_cms->query( $aro_id_sql );
$aro_id_row = $aro_id_query->fetchRow( DB_FETCHMODE_ASSOC ) ;
$aro_id = $aro_id_row['aro_id'];

//3.Insert into 'jos_core_acl_groups_aro_map' table
$table = "{$prefix}_core_acl_groups_aro_map";
$group_sql = "INSERT INTO {$table} VALUES ('$userTypeId','','$aro_id')";
$group_query = $db_cms->query( $group_sql );

$transaction->commit( );

return $id;
}

With your code.

Can't tell if it works though. I tried to trigger it by creating a user through the front end with the joomla user creation enabled, no dice (but no error), and through the back end, there is no option to create CMS user. Do I need to rework the profile? Also do I need to add code to the backend user creation to trigger this?

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: Create new user in front-end using CiviCRM
April 07, 2008, 12:21:08 pm

sorry, cant be of too much help here since we have not yet started work on joomla 1.5 :(

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

sbrawner

  • Guest
Re: Create new user in front-end using CiviCRM
April 08, 2008, 06:59:34 am
How does it work in 1.0?

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: Create new user in front-end using CiviCRM
April 08, 2008, 02:25:58 pm

Not sure what the question is?

The createJoomlaUser is called as part of processing the form and if enabled, we call that function.

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

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviMember (Moderator: Deepak Srivastava) »
  • Create new user in front-end using CiviCRM

This forum was archived on 2017-11-26.