Jump to content

Create new member programmatically?


Tom S.

Recommended Posts

Posted

Is there a class/function I can use to create a new member programmatically?

So, I pass in the necessary parameters, such as display name, email, password, etc. And it creates an account?

Posted

Example I use in one of my resources:

	$password = \IPS\Login::generateRandomString( 8 );
	$member 	= new \IPS\Member;
	$member->name	= 'Name';
	$member->email	= 'something@domain.com';
	$member->setLocalPassword( $password );
	$member->member_group_id = 3;
	$member->save();

 

Posted
1 minute ago, Adriano Faria said:

Example I use in one of my resources:


	$member = new \IPS\Member;
	$member->name				= 'Name';
	$member->email				= 'something@domain.com';
	$member->members_pass_salt  = \IPS\Member::loggedIn()->members_pass_salt;
	$member->members_pass_hash  = \IPS\Member::loggedIn()->members_pass_hash;
	$member->member_group_id	= 3;
	$member->save();

 

Thank you so much. A few questions if you do not mind:

1. Does this method create a random password? Or what exactly is going on with the password part?

2. How do you set a secondary group value?

3. Do you know how to set "Send confirmation email" to either true or false?

Posted

I edited my post above.

- Random password:

	$password = \IPS\Login::generateRandomString( 8 );
	$member->setLocalPassword( $password );

Or you can use:

	$member->setLocalPassword( $values['password'] );

Or even a hardcoded value:

	$member->setLocalPassword( '123456' );

- Secondary groups:

	$member->mgroup_others = implode( ',', $groupsArray );

- Confirmation email:

	$member->members_bitoptions['validating'] = TRUE;

This will put the new member under validation and will (probably) send the email.

Is that what you asked regarding confirmation email?

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...