Programmatically activating a new user

This forum is for general questions about extensions for Joomla! version 1.5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
davecov
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Thu Mar 21, 2013 7:17 am

Programmatically activating a new user

Post by davecov » Thu Oct 30, 2014 9:40 pm

I have the following:

Code: Select all

<?php
  $user = JFactory::getUser(0); 
  jimport('joomla.application.component.helper');
	$usersParams = &JComponentHelper::getParams( 'com_users' ); 
  $acl =& JFactory::getACL();
  $usertype = $usersParams->get( 'new_usertype' );
  if (!$usertype) {
    $usertype = 'Registered';
  }
	$userdata = array(); 
  $userdata['username'] = $username;
  $userdata['email'] = $email;
  $userdata['name'] = $name;
  $userdata['password'] = $password;
  $userdata['gid'] = $acl->get_group_id( '', $usertype, 'ARO' );
  $defaultUserGroup = $usersParams->get('new_usertype', 2);
  $userdata['groups']=array($defaultUserGroup);   
  $userdata['block'] = 0;
  $usersParams->get( 'useractivation' );
  if ($useractivation == 1) {
    jimport('joomla.user.helper');
    $userdata['activation'] =JUtility::getHash( $password);
  }
  if (!$user->bind($userdata)) {
    $form->data['email_message']='Sorry, something went wrong with the registration process. Please try again.'.$user->getError();
  }else if (!$user->save()) {
    $form->data['message'].=$user->getError(); // something went wrong!!
  }
?>
This sends an email to the newly registered user with a link to take a test.

However, when the user follows the link and enters his password, it says User is not activated

How do I activate the new user programmatically?
Last edited by imanickam on Fri Oct 31, 2014 6:29 am, edited 1 time in total.
Reason: Moved the topic from the forum Extensions for Joomla! 2.5 to the forum Extensions for Joomla! 1.5

webvirtuoso
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Mon Oct 06, 2014 11:26 pm
Contact:

Re: Programmatically activating a new user

Post by webvirtuoso » Thu Oct 30, 2014 9:52 pm

davecov wrote:I have the following:

Code: Select all

<?php
  $user = JFactory::getUser(0); 
  jimport('joomla.application.component.helper');
	$usersParams = &JComponentHelper::getParams( 'com_users' ); 
  $acl =& JFactory::getACL();
  $usertype = $usersParams->get( 'new_usertype' );
  if (!$usertype) {
    $usertype = 'Registered';
  }
	$userdata = array(); 
  $userdata['username'] = $username;
  $userdata['email'] = $email;
  $userdata['name'] = $name;
  $userdata['password'] = $password;
  $userdata['gid'] = $acl->get_group_id( '', $usertype, 'ARO' );
  $defaultUserGroup = $usersParams->get('new_usertype', 2);
  $userdata['groups']=array($defaultUserGroup);   
  $userdata['block'] = 0;
  $usersParams->get( 'useractivation' );
  if ($useractivation == 1) {
    jimport('joomla.user.helper');
    $userdata['activation'] =JUtility::getHash( $password);
  }
  if (!$user->bind($userdata)) {
    $form->data['email_message']='Sorry, something went wrong with the registration process. Please try again.'.$user->getError();
  }else if (!$user->save()) {
    $form->data['message'].=$user->getError(); // something went wrong!!
  }
?>
This sends an email to the newly registered user with a link to take a test.

However, when the user follows the link and enters his password, it says User is not activated

How do I activate the new user programmatically?
If you're modifying the Joomla core code, be aware that an update will wipe that up.

davecov
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Thu Mar 21, 2013 7:17 am

Re: Programmatically activating a new user

Post by davecov » Fri Oct 31, 2014 4:06 am

I'm not.

The code is in a Chronoforms "Custom Code" element.

davecov
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Thu Mar 21, 2013 7:17 am

Re: Programmatically activating a new user

Post by davecov » Fri Oct 31, 2014 5:04 am

As far as I can tell, the activation field in the database is an empty string (as it should be).

davecov
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Thu Mar 21, 2013 7:17 am

Re: Programmatically activating a new user

Post by davecov » Fri Oct 31, 2014 6:23 am

Oops.

This topic should be in the Joomla 1.5 section.

Terribly sorry!

What's the drill? Can someone move it? or can I start a new topic in that section?

~Dave

User avatar
imanickam
Joomla! Master
Joomla! Master
Posts: 28202
Joined: Wed Aug 13, 2008 2:57 am
Location: Chennai, India

Re: Programmatically activating a new user

Post by imanickam » Fri Oct 31, 2014 6:31 am

davecov wrote:This topic should be in the Joomla 1.5 section.

Terribly sorry!

What's the drill? Can someone move it?
The topic has been moved to 1.5 foum.
Ilagnayeru (MIG) Manickam | இளஞாயிறு மாணிக்கம்
Joomla! - Global Moderators Team | Joomla! Core - Tamil (தமிழ்) Translation Team Coordinator
Former Joomla! Translations Coordination Team Lead
Eegan - Support the poor and underprivileged


Locked

Return to “Extensions for Joomla! 1.5”