Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By markosef on
How can i do that? Is it possible? I have some app. that should send data about users and create them, i cannot find anything abou this, any help please?
Comments
user_save
user_save
i tried like this?
and nothing happened, what could i be doing wrong or is code wrong?
you ever get this to work?
you ever get this to work?
try this (change accoridngly to your users)
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$data['name'] = $_POST['name'];
$data['mail'] = $_POST['mail'];
$data['pass'] = $_POST['pass'];
$data['status'] = 1;
$data['roles'] = array(
DRUPAL_AUTHENTICATED_RID => 'authenticated user',
5 => 'pretplatnik', //this is my custom user and his ID is 5
);
require_once DRUPAL_ROOT. '
require_once DRUPAL_ROOT. '/includes/password.inc';
$user->pass = user_hash_password($password);
$account = user_save($user);
Note: under D7 for the password to actually work you need to store it as a hash.
Here's a way to do it via
Here's a way to do it via the forms api:
Above taken from: http://api.drupal.org/api/function/drupal_execute/6
Worked for me, only a minor issue, instead of only one password value the form in drupal 6 requires 2 password values or it fails:
thanks : capmex
Just $form_state['values']['pass'] = 'password';
is given in the documentation for drupal_execute(user_register', $form_state) ;
Thanks alot!
But Password is not storing properly
But Password is not storing properly.. It is storing as " d41d8cd98f00b204e9800998ecf8427e " for all kind of passwords..
Please let me know.. where is my fault.
It is importing users from another database :
Following is my code :
module_load_include('inc', 'user', 'user.pages');
db_set_active('mydb');
$pmresult = db_query("SELECT * FROM {user}");
while ($username = db_fetch_object($pmresult)) {
$pmusername= $username->username ;
$pmpassword= $username->password;
db_set_active('default');
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Get an array of roles
$roles = user_roles();
print $pmpassword ;
// Basic account information
$account = array(
'name' => $pmusername,
'pass' => $pmpassword,
'mail' => $pmusername,
'status' => 1,
/*'init' => $pmusername,*/
'roles' => array(array_search('customer', $roles) => 1),
);
// See if the user exists by calling Drupal's user_load()
$existing_user = user_load(array('name' => $account['name']));
if (!$existing_user->uid) {
$form_state['values'] = $account;
$form_state['values']['pass'] = array(
'pass1' => $account['pass'],
'pass2' => $account['pass'],
);
$form_state['values']['op'] = t('Create new account');
drupal_execute('user_register', $form_state);
}
}
If you're referring to what
If you're referring to what actually gets stored in the database, then it's not supposed to be the plain text password. Drupal only stores a one-way hash of the password to verify log-ins, not the password itself.
Example in Drupal 6
The code that markosef posted (reply #2) worked for me. To be precise, this was my code:
D7 Example
you can use build-in drupal API to do that
check out this web site
http://thedrupalblog.com/programmatically-addupdate-users-using-user-save
you can create a custom form to collect the data you want and create the users on submit,
I hope this help you.
Thanks,
Ma'moun.othman
http://artofeclipse.com/
http://vardot.com/
Thanks.
Thanks.
Are there a guide to do this
Are there a guide to do this in D7?
/Lars Nielsen
I believe the link above for
I believe the link above for D6 should still apply in D7.
Thanks.
Thanks.