Blame view

sources/settings/ajax/createuser.php 1.58 KB
03e52840d   Kload   Init
1
2
3
4
5
6
7
  <?php
  
  OCP\JSON::callCheck();
  OC_JSON::checkSubAdminUser();
  
  if(OC_User::isAdminUser(OC_User::getUser())) {
  	$groups = array();
6d9380f96   Cédric Dupont   Update sources OC...
8
  	if (!empty($_POST["groups"])) {
03e52840d   Kload   Init
9
10
11
  		$groups = $_POST["groups"];
  	}
  }else{
6d9380f96   Cédric Dupont   Update sources OC...
12
  	if (isset($_POST["groups"])) {
03e52840d   Kload   Init
13
  		$groups = array();
6d9380f96   Cédric Dupont   Update sources OC...
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   Kload   Init
19
20
  			}
  		}
6d9380f96   Cédric Dupont   Update sources OC...
21
  		if (empty($groups)) {
03e52840d   Kload   Init
22
23
  			$groups = OC_SubAdmin::getSubAdminsGroups(OC_User::getUser());
  		}
6d9380f96   Cédric Dupont   Update sources OC...
24
  	} else {
03e52840d   Kload   Init
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   Kload   Upgrade to ownclo...
33
34
35
  	// check whether the user's files home exists
  	$userDirectory = OC_User::getHome($username) . '/files/';
  	$homeExists = file_exists($userDirectory);
03e52840d   Kload   Init
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   Kload   Upgrade to ownclo...
46

6d9380f96   Cédric Dupont   Update sources OC...
47
48
49
  	$userManager = \OC_User::getManager();
  	$user = $userManager->get($username);
  	OCP\JSON::success(array("data" =>
03e52840d   Kload   Init
50
  				array(
31b7f2792   Kload   Upgrade to ownclo...
51
52
  					// returns whether the home already existed
  					"homeExists" => $homeExists,
03e52840d   Kload   Init
53
  					"username" => $username,
6d9380f96   Cédric Dupont   Update sources OC...
54
55
  					"groups" => OC_Group::getUserGroups( $username ),
  					'storageLocation' => $user->getHome())));
03e52840d   Kload   Init
56
  } catch (Exception $exception) {
6d9380f96   Cédric Dupont   Update sources OC...
57
  	OCP\JSON::error(array("data" => array( "message" => $exception->getMessage())));
03e52840d   Kload   Init
58
  }