We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Create member remotely

Development and Programming

hellodaylight's avatar
hellodaylight
26 posts
14 years ago
hellodaylight's avatar hellodaylight

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:

  • Does member creation have to happen through the member signup form (either EE native or Solspace User module)?
  • Can this form be completed/triggered by a remote call (say with POST vars and javascript)?
  • Would it be easier to create a php page with some MySQL queries that creates the member entry directly in the database? What fields/process are needed?

If anyone can point me in the right direction I’d greatly appreciate it.

s

       
John Henry Donovan's avatar
John Henry Donovan
12,339 posts
14 years ago
John Henry Donovan's avatar John Henry Donovan

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

       
hellodaylight's avatar
hellodaylight
26 posts
14 years ago
hellodaylight's avatar hellodaylight

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.

       
frustrated's avatar
frustrated
4 posts
14 years ago
frustrated's avatar frustrated

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

       
vwadesign's avatar
vwadesign
4 posts
14 years ago
vwadesign's avatar vwadesign

Martin,

I was looking for a way to remotely add users and this code looks like it might do the trick. One question I have is how are you invoking EE ($this->EE->load->)?

-Adam

       
frustrated's avatar
frustrated
4 posts
14 years ago
frustrated's avatar frustrated

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…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.