Commit 1df13608 authored by 张育槟's avatar 张育槟

优化接口功能

parent 4ed42d4f
......@@ -16,15 +16,15 @@ class LdapController extends Controller
public $provider=null;
public function __construct()
{
$ad = new \Adldap\Adldap();
$config = [
'hosts'=>[$this->host],
'base_dn'=>$this->dn,
'username' => $this->username,
'password' =>$this->password
];
$ad->addProvider($config);
$this->provider = $ad->connect();
// $ad = new \Adldap\Adldap();
// $config = [
// 'hosts'=>[$this->host],
// 'base_dn'=>$this->dn,
// 'username' => $this->username,
// 'password' =>$this->password
// ];
// $ad->addProvider($config);
// $this->provider = $ad->connect();
}
public function handle(Request $request)
{
......@@ -72,12 +72,9 @@ class LdapController extends Controller
{
$data['data']=json_decode($data['data'],true);
}
//print_r($data);
//exit();
if ($data['operation_type'] == 'emp') {
if ($data['operation'] == 'add') {
$this->saveEmp($data['data']);
$this->saveEmp($data);
} else if($data['operation'] == 'edit'){
$this->editEmp($data['data']);
} else if ($data['operation'] == 'del'){
......@@ -116,10 +113,15 @@ class LdapController extends Controller
{
if (empty($data)) return;
foreach ($data as $key => $value) {
$dept_name='IT发展部';
if(!empty($data['deptName'])){
$dept_name=$dept_name.'/'.$data['deptName'];
}
foreach ($data['data'] as $key => $value) {
$entry=["cn"=>"{$value}"];
$user=$this->provider->make()->user($entry);
$user->setDn("cn={$value},ou=IT发展部,ou=Users_hoto,dc=hoto,dc=test"); //在IT发展部新增人员
$user->setDn("cn={$value},ou='.$dept_name.',ou=Users_hoto,dc=hoto,dc=test"); //在IT发展部新增人员
$user->setAccountName("$value");
$user->setCommonName("$value");
if($user->create()){
......@@ -263,4 +265,31 @@ class LdapController extends Controller
}
// $this->saveDept($handleData);
}
/**
* 输出调试函数
*
* @param array $args
*/
function pr($args = array()) {
$escape_html = true;
$bg_color = '#EEEEE0';
$txt_color = '#000000';
$args = func_get_args();
foreach($args as $arr){
echo sprintf('<pre style="background-color: %s; color: %s;">', $bg_color, $txt_color);
if($arr) {
if($escape_html){
echo htmlspecialchars( print_r($arr, true) );
}else{
print_r($arr);
}
}else {
var_dump($arr);
}
echo '</pre>';
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment