-
- 132 Posts
I need to be able to create a user from within the web context in a "user admin" area of the site. Overall I have the permissions set well enough to only allowed logged users of type "userAdmin" into the area in question but not able to create user. I could very simply be doing this all wrong and or not have the proper level of permission for my "user admin" to be able to do this. That said the script simply fails with no error logs.. any help or direction is appreciated. I have also added my system "Administrator" account to this same UG as a super user. This then allows my Administrator access to the area but still not user created so my bet is my code is wrong to start.
This just dies and never echos.
$user = $modx->getNewObject('modUser');
$user->set('username','adamtester');
$user->set('password','adam');
if($user->save()){
echo 'success';die;
}
else{
echo 'failed';die;
}
"One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow
"
-
- 132 Posts
I need a day off ... thank you
"One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow
"
-
- 132 Posts
Yep that is all it was... I would now like to propose the getNewObject is an alias for newObject
J/K thanks again
As simple a solution this is it made my night... after the bad news I got elsewhere this just made my day
"One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow
"
-
- 132 Posts
This works but is there a better way???
$user = $modx->newObject('modUser');
$user->set('username','hello');
$user->set('password','world');
if($user->save()){
$id = $user->get('id');
$profile = $modx->newObject('modUserProfile');
$profile->fromArray(array(
'internalKey' => $id,
'fullname' => 'Adam Smith',
'address' => '12345',
'zip' => '91355',
'city' => 'Valencia',
'state' => 'CA',
'country' => 'USA'
));
$profile->save();
"One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow
"
-
- 24,544 Posts
I think this would be a little faster (untested):
<?php
$user = $modx->newObject('modUser', array('username'=>'hello', 'password'=>'world'));
$profile = $modx->newObject('modUserProfile',
array(
'internalKey' => $id,
'fullname' => 'Adam Smith',
'address' => '12345',
'zip' => '91355',
'city' => 'Valencia',
'state' => 'CA',
'country' => 'USA'
));
$user->addOne($profile);
if (! $user->save() ) {
return "oops -- problem with save";
}
The profile will be saved automatically.
Could also just put all the data in an array and abuse $modx->runProcessor. DOes all the permission checking too - so may run into some issues with too strict permissions for that
http://rtfm.modx.com/display/revolution20/Using+runProcessor