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