Blame view
sources/settings/ajax/createuser.php
1.42 KB
|
03e52840d
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php
OCP\JSON::callCheck();
OC_JSON::checkSubAdminUser();
if(OC_User::isAdminUser(OC_User::getUser())) {
$groups = array();
if( isset( $_POST["groups"] )) {
$groups = $_POST["groups"];
}
}else{
if(isset( $_POST["groups"] )) {
$groups = array();
foreach($_POST["groups"] as $group) {
if(OC_SubAdmin::isGroupAccessible(OC_User::getUser(), $group)) {
$groups[] = $group;
}
}
|
|
31b7f2792
|
19 |
if(count($groups) === 0) {
|
|
03e52840d
|
20 21 22 23 24 25 26 27 28 29 30 |
$groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
}
}else{
$groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
}
}
$username = $_POST["username"];
$password = $_POST["password"];
// Return Success story
try {
|
|
31b7f2792
|
31 32 33 |
// check whether the user's files home exists $userDirectory = OC_User::getHome($username) . '/files/'; $homeExists = file_exists($userDirectory); |
|
03e52840d
|
34 35 36 37 38 39 40 41 42 43 |
if (!OC_User::createUser($username, $password)) {
OC_JSON::error(array('data' => array( 'message' => 'User creation failed for '.$username )));
exit();
}
foreach( $groups as $i ) {
if(!OC_Group::groupExists($i)) {
OC_Group::createGroup($i);
}
OC_Group::addToGroup( $username, $i );
}
|
|
31b7f2792
|
44 |
|
|
03e52840d
|
45 46 |
OC_JSON::success(array("data" =>
array(
|
|
31b7f2792
|
47 48 |
// returns whether the home already existed "homeExists" => $homeExists, |
|
03e52840d
|
49 50 51 52 53 |
"username" => $username,
"groups" => OC_Group::getUserGroups( $username ))));
} catch (Exception $exception) {
OC_JSON::error(array("data" => array( "message" => $exception->getMessage())));
}
|