Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Tom S. Posted September 13, 2018 Posted September 13, 2018 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?
Adriano Faria Posted September 13, 2018 Posted September 13, 2018 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();
Tom S. Posted September 13, 2018 Author Posted September 13, 2018 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?
Adriano Faria Posted September 13, 2018 Posted September 13, 2018 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?
bfarber Posted September 24, 2018 Posted September 24, 2018 You can alternatively use the REST API to create a new member. https://invisioncommunity.com/developers/rest-api?endpoint=core/members/POSTindex
Tom S. Posted September 24, 2018 Author Posted September 24, 2018 52 minutes ago, bfarber said: You can alternatively use the REST API to create a new member. https://invisioncommunity.com/developers/rest-api?endpoint=core/members/POSTindex Very useful to know, thanks.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.