I’m interested in the ability to create member accounts remotely, triggered from another site/server. I’m wondering the best way to go about it:
If anyone can point me in the right direction I’d greatly appreciate it.
s
Hi hellodaylight,
I am moving this to the Development forum as more appropriate.
Whats the context behind it?
Take a look at the Vanilla forums bridge as this is down the lines of what you want I believe
The context: I’m building a site with EE, but my client wants to incorporate a third party social media tracking tool from another company. This company has requested that users sign up via their service in order to enable the tracking, but in the process an account could also be created in EE for the user (so they don’t have to go through a sign up twice). They want to send me the username and email address once someone signs up and I auto-generate a password and email it the user.
Here’s some code from a mcp.modulename.php file that I have used to create new users…
private function create_user($data){
// $data is new user data - first name, last name, email and country...
$this->EE->load->model('member_model');
$this->EE->load->helper('security');
$email = $data['email'];
$member_data['email'] = $email;
$member_data['username'] = substr($email, 0, strpos($email, '@'));
$password = $this->generatePassword();
$member_data['password'] = do_hash($password);
$member_data['ip_address'] = $this->EE->input->ip_address();
$member_data['unique_id'] = random_string('encrypt');
$member_data['join_date'] = $this->EE->localize->now;
$member_data['language'] = $this->EE->config->item('deft_lang');
$member_data['timezone'] = ($this->EE->config->item('default_site_timezone') && $this->EE->config->item('default_site_timezone') != '') ? $this->EE->config->item('default_site_timezone') : $this->EE->config->item('server_timezone');
$member_data['daylight_savings'] = ($this->EE->config->item('default_site_dst') && $this->EE->config->item('default_site_dst') != '') ? $this->EE->config->item('default_site_dst') : $this->EE->config->item('daylight_savings');
$member_data['time_format'] = ($this->EE->config->item('time_format') && $this->EE->config->item('time_format') != '') ? $this->EE->config->item('time_format') : '1';
$member_data['group_id'] = 5;
// add in any optional data
$opt_data = array('m_field_id_1' => $data['fname'],
'm_field_id_2' => $data['lname'],
'm_field_id_3' => $data['country'],
);
$member_id = $this->EE->member_model->create_member($member_data, $opt_data);
return array('member_id' => $member_id, 'password' => $password, 'username' => $member_data['username']);
}
private function generatePassword($lngth = 6) {
// based on code from http://uk.php.net/manual/en/function.mt-rand.php
// makes a random alpha numeric string of a given lenth
$aZ09 = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
$out ='';
for($i = 0; $i < $lngth; $i++) {
$out .= $aZ09[mt_rand(0,count($aZ09)-1)];
}
return $out;
}Hope that helps.
Martin
Hi Adam,
that code is a function taken from the control panel of a module I wrote. As such, the EE super object is referenced in the constructor of the class using
// Make a local reference to the ExpressionEngine super object
$this->EE =& get_instance();and is therefore available to use in the function…
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.