diff --git a/htdocs/webservices/server_user.php b/htdocs/webservices/server_user.php index 226f061ba683d098041ae828e27de4f3d54609bd..c74ea28af511cd3e1b5b82e704db1489580d8c99 100644 --- a/htdocs/webservices/server_user.php +++ b/htdocs/webservices/server_user.php @@ -151,6 +151,7 @@ $server->wsdl->addComplexType( ), 'tns:group' ); + $thirdpartywithuser_fields = array( // For thirdparty and contact 'name' => array('name'=>'name','type'=>'xsd:string'), @@ -211,6 +212,20 @@ $server->wsdl->addComplexType( $thirdpartywithuser_fields ); +// Define WSDL user short object +$server->wsdl->addComplexType( + 'shortuser', + 'complexType', + 'struct', + 'all', + '', + array( + 'login' => array('name'=>'login','type'=>'xsd:string'), + 'password' => array('name'=>'password','type'=>'xsd:string'), + 'entity' => array('name'=>'entity','type'=>'xsd:string'), + ) +); + // 5 styles: RPC/encoded, RPC/literal, Document/encoded (not WS-I compliant), Document/literal, Document/literal wrapped @@ -261,6 +276,19 @@ $server->register( 'WS to create an external user with thirdparty and contact' ); +$server->register( + 'SetUserPassword', + // Entry values + array('authentication'=>'tns:authentication','shortuser'=>'tns:shortuser'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string'), + $ns, + $ns.'#SetUserPassword', + $styledoc, + $styleuse, + 'WS to change password of an user' +); + @@ -554,10 +582,9 @@ function CreateUserFromThirdparty($authentication,$thirdpartywithuser) foreach($extrafields->attribute_label as $key=>$label) { $key='contact_options_'.$key; + $key=substr($key,8); // Remove 'contact_' prefix $contact->array_options[$key]=$thirdpartywithuser[$key]; } - - $contact_id = $contact->create($fuser); @@ -630,6 +657,86 @@ function CreateUserFromThirdparty($authentication,$thirdpartywithuser) return $objectresp; } + +/** + * Set password of an user + * + * @param array $authentication Array of authentication information + * @param array $shortuser Array of login/password info + * @return mixed + */ +function SetUserPassword($authentication,$shortuser) { + + global $db,$conf,$langs; + + dol_syslog("Function: SetUserPassword login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + if ($fuser->societe_id) $socid=$fuser->societe_id; + + if (! $error && ! $shortuser) + { + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter shortuser must be provided."; + } + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->user->user->password || $fuser->rights->user->self->password) + { + $userstat=new User($db); + $res = $userstat->fetch('',$shortuser['login']); + if($res) + { + $res = $userstat->setPassword($userstat,$shortuser['password']); + if($res) + { + $objectresp = array( + 'result'=>array('result_code' => 'OK', 'result_label' => ''), + 'groups'=>$arraygroups + ); + } + else + { + $error++; + $errorcode='NOT_MODIFIED'; $errorlabel='Error when changing password'; + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='User not found'; + } + + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + + if ($error) + { + $objectresp = array( + 'result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel) + ); + } + + return $objectresp; +} + + // Return the results. $server->service($HTTP_RAW_POST_DATA);