Changeset View
Changeset View
Standalone View
Standalone View
lib/api/kolab_api_service_user.php
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | public function user_add($getdata, $postdata) | ||||
$attributes = $this->parse_input_attributes('user', $postdata); | $attributes = $this->parse_input_attributes('user', $postdata); | ||||
password_policy::validate_password($attributes['userpassword']); | password_policy::validate_password($attributes['userpassword']); | ||||
Log::trace("user_add()", $attributes); | Log::trace("user_add()", $attributes); | ||||
$auth = Auth::get_instance(); | $auth = Auth::get_instance(); | ||||
$conf = Conf::get_instance(); | |||||
# validate if the uid is unique inside this domain, or across multiple domains | |||||
$all_domains = array(); | |||||
if ($conf->get('unique_uid_across_domains') == "true") { | |||||
$domainslist = $auth->list_domains(); | |||||
foreach ($domainslist['list'] as $domainobj) { | |||||
$domain = $domainobj['associateddomain']; | |||||
if (is_array($domain)) { | |||||
$domain = $domain[0]; | |||||
} | |||||
$all_domains[] = $domain; | |||||
} | |||||
} else { | |||||
$all_domains[] = $_SESSION['user']->get_domain(); | |||||
} | |||||
$user_found = null; | |||||
foreach ($all_domains as $domain) { | |||||
$user_found = $auth->user_find_by_attribute_per_domain($domain, array('uid' => $attributes['uid'])); | |||||
if ($user_found) { | |||||
throw new Exception(kolab_api_controller::translate("error").": ". | |||||
kolab_api_controller::translate("user.add.duplicateuid", $attributes['uid'])); | |||||
} | |||||
} | |||||
$result = $auth->user_add($attributes, $postdata['type_id']); | $result = $auth->user_add($attributes, $postdata['type_id']); | ||||
if ($result) { | if ($result) { | ||||
if ($id = $this->unique_attribute_value($result)) { | if ($id = $this->unique_attribute_value($result)) { | ||||
$attributes['id'] = $id; | $attributes['id'] = $id; | ||||
} | } | ||||
return $attributes; | return $attributes; | ||||
▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | public function user_find($get, $post) | ||||
if ($result) { | if ($result) { | ||||
return $result; | return $result; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | |||||
* Find user and return his domain. | |||||
* If the search returns only one record we'll return the domain of the user. | |||||
* | |||||
* @param array $get GET parameters | |||||
* @param array $post POST parameters | |||||
* | |||||
* @return array|bool User attributes, False on error | |||||
*/ | |||||
public function user_get_domain($get, $post) | |||||
{ | |||||
$auth = Auth::get_instance(); | |||||
$all_domains = $auth->list_domains(); | |||||
$all_domains = $all_domains['list']; | |||||
$exists_in_domain = ""; | |||||
foreach ($all_domains as $domainobj) { | |||||
$domain = $domainobj['associateddomain']; | |||||
if (is_array($domain)) { | |||||
$domain = $domain[0]; | |||||
} | |||||
if ($auth->user_find_by_attribute_per_domain($domain, array('uid' => $get['id']))) { | |||||
if (!empty($exists_in_domain)) { | |||||
// there are multiple users with the same userid in different domains | |||||
return false; | |||||
} | |||||
$exists_in_domain = $domain; | |||||
} | |||||
} | |||||
if (empty($exists_in_domain)) { | |||||
return false; | |||||
} | |||||
return array('domain' => $exists_in_domain); | |||||
} | |||||
} | } |