Beispiel #1
0
 public function importEmployeeAction($network_domain)
 {
     $request = $this->get("request");
     $user = $this->get('security.context')->getToken()->getUser();
     //判断当前导入人员是否是企业邮箱
     $userDomain = explode("@", $user->getUserName());
     $da = $this->get("we_data_access");
     $sql = "select 1 from we_public_domain where domain_name=?";
     $ds = $da->GetData("mt", $sql, array((string) $userDomain[1]));
     $mailType = count($ds["mt"]["rows"]) > 0 ? "0" : "1";
     //1表示是企业邮箱
     try {
         $upfile = $request->files->get("filedata");
         $tmpPath = $upfile->getPathname();
         $oldName = $upfile->getClientOriginalName();
         $fixs = explode(".", strtolower($oldName));
         if (count($fixs) < 2) {
             $re = array('s' => 0, 'message' => "文件类型不正确");
         } else {
             $fixedType = $fixs[count($fixs) - 1];
             if ($fixedType != "xlsx" && $fixedType != "xls") {
                 $re = array('s' => 0, 'message' => "文件类型不正确");
             } else {
                 $newFileName = $user->openid . date('y-m-d-H-m-s') . "." . $fixedType;
                 if (move_uploaded_file($tmpPath, 'upload/' . $newFileName)) {
                     $da = $this->container->get('we_data_access');
                     $objReader = \PHPExcel_IOFactory::createReader($fixedType == "xlsx" ? 'Excel2007' : "Excel5");
                     //use excel2007 for 2007 format
                     $objPHPExcel = $objReader->load($_SERVER['DOCUMENT_ROOT'] . '/upload/' . $newFileName);
                     $objWorksheet = $objPHPExcel->getActiveSheet();
                     $highestRow = $objWorksheet->getHighestRow();
                     $highestColumn = $objWorksheet->getHighestColumn();
                     $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);
                     //总列数
                     //获取标题行
                     $titleAry = array();
                     $account_index = 0;
                     $name_index = 0;
                     $mobile_index = 0;
                     $pwd_index = 0;
                     for ($row = 0; $row <= 1; $row++) {
                         for ($col = 0; $col < $highestColumnIndex; $col++) {
                             $titleAry[$col] = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                             if (strpos($titleAry[$col], "邮箱") !== false) {
                                 $account_index = $col;
                             } else {
                                 if (strpos($titleAry[$col], "姓名") !== false) {
                                     $name_index = $col;
                                 } else {
                                     if (strpos($titleAry[$col], "手机") !== false) {
                                         $mobile_index = $col;
                                     } else {
                                         if (strpos($titleAry[$col], "密码") !== false) {
                                             $pwd_index = $col;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     $titleAry[] = "eno";
                     $err_list = array();
                     $da = $this->get("we_data_access");
                     $dm = $this->get("we_data_access_im");
                     //获取数据行
                     for ($row = 2; $row <= $highestRow; $row++) {
                         $strs = array();
                         for ($col = 0; $col < $highestColumnIndex; $col++) {
                             $strs[$col] = trim((string) $objWorksheet->getCellByColumnAndRow($col, $row)->getValue());
                         }
                         $strs[] = $user->eno;
                         $name = $strs[$name_index];
                         if (empty($name)) {
                             $err_list[] = array("name" => "", "row" => $row, "msg" => "姓名不能为空");
                             continue;
                         }
                         if (strlen($name) == 1) {
                             $err_list[] = array("name" => "", "row" => $row, "msg" => "姓名不能少于2个字符");
                             continue;
                         }
                         //获取填写的帐号
                         $account = $strs[$account_index];
                         if (empty($account)) {
                             $err_list[] = array("name" => $name, "row" => $row, "msg" => "邮箱帐号不能为空");
                             continue;
                         }
                         if (!Utils::validateEmail($account)) {
                             $err_list[] = array("name" => $name, "row" => $row, "msg" => "邮箱帐号格式不正确");
                             continue;
                         }
                         $staffmgr = new Staff($da, $dm, $account);
                         if ($staffmgr->checkNickname($user->eno, $name) === true) {
                             $err_list[] = array("name" => "", "row" => $row, "msg" => "[" . $name . "]已经注册,请检查!");
                             continue;
                         }
                         //if($mailType=="1" && explode("@",$account)[1]!=$userDomain[1] )
                         //{
                         //	 $err_list[]=array("name"=>$name,"row"=>($row),"msg"=>"不允许导入公共邮箱$account");
                         //   continue;
                         //}
                         $mobile = $strs[$mobile_index];
                         if (!empty($mobile)) {
                             if (!Utils::validateMobile($mobile)) {
                                 $err_list[] = array("name" => $name, "row" => $row, "msg" => "手机号码格式不正确");
                                 continue;
                             }
                         }
                         //判断帐号是否已经注册
                         $isexist = $staffmgr->isExist($mobile);
                         if (!empty($isexist)) {
                             //已注册
                             $err_list[] = array("name" => $name, "msg" => "邮箱或手机号已被使用");
                             continue;
                         }
                         //判断是否已导入,已导入,则不再发邮件
                         $isImport = false;
                         try {
                             $isImport = $staffmgr->getImportInfo();
                         } catch (\Exception $err) {
                         }
                         try {
                             $staffmgr->importReg($titleAry, $strs);
                             //判断是否设置了密码
                             $pwd = $strs[$pwd_index];
                             if (!empty($pwd)) {
                                 $sql = "select ename from we_enterprise where eno=?";
                                 $ds = $da->GetData("t", $sql, array((string) $user->eno));
                                 //自动激活
                                 $active = new \Justsy\BaseBundle\Controller\ActiveController();
                                 $active->setContainer($this->container);
                                 $active->doSave(array('account' => $account, 'realName' => $name, 'passWord' => $pwd, 'eno' => $user->eno, 'ename' => $ds["t"]["rows"][0]["ename"], 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1'));
                                 $staffmgr = new Staff($da, $dm, $account);
                                 $importData = $staffmgr->getImportInfo();
                                 $staffmgr->updateByImport($importData);
                                 $staffmgr->deleteImportPhy();
                             } else {
                                 if ($isImport === false) {
                                     //发送邮件
                                     $activeurl = $this->generateUrl("JustsyBaseBundle_empimport_setpass", array('account' => DES::encrypt($account)), true);
                                     $txt = $this->renderView('JustsyBaseBundle:Register:mail.html.twig', array('realName' => $user->nick_name, 'account' => $account, 'activeurl' => $activeurl));
                                     Utils::saveMail($da, $this->container->getParameter('mailer_user'), $account, "欢迎加入Wefafa企业协作网络", $txt);
                                 }
                             }
                         } catch (\Exception $err) {
                             //写导入数据发生异常
                             $err_list[] = array("name" => $name, "msg" => "导入失败:" . $err->getMessage());
                             continue;
                         }
                     }
                     $re = array('s' => 1, 'error_list' => $err_list);
                 } else {
                     $re = array('s' => 0, 'message' => "文件上传失败");
                 }
                 try {
                     unlink($tmpPath);
                 } catch (\Exception $e) {
                 }
             }
         }
     } catch (\Exception $ex) {
         $re = array('s' => 0, 'message' => "导入失败");
     }
     $response = new Response("<script>parent.import_callback(" . json_encode($re) . ")</script>");
     $response->headers->set('Content-Type', 'text/html');
     return $response;
 }
 public function updateStaffAction()
 {
     $da = $this->get("we_data_access");
     $da_im = $this->get('we_data_access_im');
     $request = $this->getRequest();
     $state = $request->get("state");
     $im_deptid = $request->get("dept_id");
     //将im的部门id转化为sns里的部门id
     $deptInfo = $this->getDeptInfo($im_deptid);
     $sns_deptid = $deptInfo["deptid"];
     $login_account = $request->get("login_account");
     $e_mail = $request->get("e_mail");
     $nick_name = $request->get("nick_name");
     $password = $request->get("password");
     $sex = $request->get("sex");
     $duty = $request->get("duty");
     $duty = empty($duty) ? null : $duty;
     $mobile = $request->get("mobile");
     $mobile = empty($mobile) ? null : $mobile;
     $success = true;
     $msg = "";
     //判断手机号正误
     if (!empty($mobile)) {
         if (!Utils::validateMobile($mobile)) {
             $result = array("success" => false, "msg" => "手机账号格式错误!");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         } else {
             $sql = "";
             $para = array();
             if ($state == "add") {
                 $sql = "select count(*) number from we_staff where mobile_bind=?;";
                 array_push($para, (string) $mobile);
             } else {
                 $sql = "select count(*) number from we_staff where mobile_bind=? and login_account!=?;";
                 array_push($para, (string) $mobile, $login_account);
             }
             try {
                 $ds = $da->GetData("table", $sql, $para);
                 if ($ds && $ds["table"]["recordcount"] > 0) {
                     if ((int) $ds["table"]["rows"][0]["number"] > 0) {
                         $result = array("success" => false, "msg" => "已存在该手机号码!");
                         $response = new Response(json_encode($result));
                         $response->headers->set('Content-Type', 'text/json');
                         return $response;
                     }
                 }
             } catch (\Exception $e) {
                 $this->get("logger")->err($e->getMessage());
             }
         }
     }
     $user = $this->get('security.context')->getToken()->getUser();
     $deptMgr = new \Justsy\BaseBundle\Management\Dept($da, $da_im, $this->container);
     $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $login_account, $this->container->get("logger"), $this->container);
     if ($state == "add") {
         if ($staffMgr->checkUser($mobile)) {
             $result = array("success" => false, "msg" => "用户账号已存在,请重新输入!");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         //获得ldap_uid
         $login_array = explode("@", $login_account);
         if (count($login_array) < 2) {
             continue;
         }
         $ldap_uid = $login_array[0];
         //注册用户账号
         $register = new \Justsy\BaseBundle\Controller\ActiveController();
         $register->setContainer($this->container);
         $parameter = array("account" => $login_account, "realName" => $nick_name, "passWord" => $password, "ldap_uid" => $ldap_uid, "eno" => $user->eno, "ename" => $user->ename, "isNew" => '0', "mailtype" => "1", "import" => '1', "isSendMessage" => "N", "mobile" => $mobile, "duty" => $duty, "deptid" => $sns_deptid, "mutual" => "Y");
         $result = $register->doSave($parameter);
         if ($result["returncode"] == "0000") {
             $staffdata = $staffMgr->getInfo();
             //成功后统计人员
             $sql = "call dept_emp_stat(?)";
             $da_im->ExecSQL($sql, array((string) $staffdata["fafa_jid"]));
             //自动关注服务号
             $servicerMgr = new \Justsy\BaseBundle\Management\Service($this->container);
             $parameter = array("eno" => $user->eno, "deptid" => $im_deptid, "login_account" => $login_account);
             $servicerMgr->atten_service($parameter);
             $revJids = $staffMgr->getFriendAndColleagueJid();
             Utils::sendImMessage($user->fafa_jid, implode(",", $revJids), "newstaff", json_encode($staffMgr->getinfo()), $this->container, "", "", false, Utils::$systemmessage_code);
         } else {
             $success = false;
             $msg = "添加用户账号失败:" . $result["msg"];
         }
         $result = array("success" => $success, "msg" => $msg);
         $response = new Response(json_encode($result));
         $response->headers->set('Content-Type', 'text/json');
         return $response;
     } else {
         $staffinfo = $staffMgr->getInfo();
         $deptinfo = $deptMgr->getinfo($staffinfo["dept_id"]);
         //判断是否更改了性别
         if ($sex == $staffinfo["sex_id"]) {
             $sex = null;
         }
         //判断是否更改了职务
         if ($duty == $staffinfo["duty"]) {
             $duty = null;
         }
         //判断是否更改了姓名
         if ($nick_name == $staffinfo["nick_name"]) {
             $nick_name = null;
         }
         //判断是否更新了部门
         if ($sns_deptid == $deptinfo["dept_id"]) {
             $sns_deptid = null;
         }
         //判断是否更新了手机
         if ($mobile == $staffinfo["mobile_bind"]) {
             $mobile = null;
         }
         $uResult = $staffMgr->checkAndUpdate($nick_name, $mobile, $sns_deptid, $duty, null, $sex, null, $e_mail);
         $u_staff = null;
         $factory = null;
         //判断是否修改了密码
         if (!empty($password)) {
             $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'), $this->container);
             $factory = $this->get('security.encoder_factory');
             $targetStaffInfo = $u_staff->getInfo();
             $re = $u_staff->changepassword($targetStaffInfo["login_account"], $password, $factory);
             if ($re) {
                 //给自己发送一个staff-changepasswod的出席,通知在线客户端密码发生修改,需要新密码重新登录
                 Utils::sendImPresence($user->fafa_jid, $targetStaffInfo["fafa_jid"], "staff-changepasswod", "staff-changepasswod", $this->container, "", "", false, Utils::$systemmessage_code);
             }
         }
         //判断是否修改了帐号
         if ($e_mail != $login_account) {
             //判断邮件是否存在
             if (empty($u_staff)) {
                 $u_staff = new Staff($da, $da_im, $login_account, $this->get('logger'), $this->container);
             }
             if (empty($factory)) {
                 $factory = $this->get('security.encoder_factory');
             }
             $u_staff->changeLoginAccount($e_mail, $factory);
         }
         try {
             $revJids = $staffMgr->getFriendAndColleagueJid();
             if ($uResult && !empty($sns_deptid)) {
                 //部门变更时,需要通知手机端更新原部门和新部门数据
                 Utils::sendImMessage("", implode(",", $revJids), "staff-changedept", json_encode($deptinfo), $this->container, "", "", false, Utils::$systemmessage_code);
                 Utils::sendImMessage("", implode(",", $revJids), "staff-changedept", json_encode($deptMgr->getinfo($sns_deptid)), $this->container, "", "", false, Utils::$systemmessage_code);
                 $old_fafa_deptid = $deptinfo["fafa_deptid"];
                 $fafa_jid = $staffinfo["fafa_jid"];
                 //取消关注服务号
                 $servicerMgr = new \Justsy\BaseBundle\Management\Service($this->container);
                 $parameter = array("eno" => $user->eno, "deptid" => $old_fafa_deptid, "login_account" => $login_account);
                 $servicerMgr->cancel_atten($parameter);
                 //自动关注服务号
                 $parameter = array("eno" => $user->eno, "deptid" => $im_deptid, "login_account" => $login_account);
                 $servicerMgr->atten_service($parameter);
             }
         } catch (\Exception $e) {
             $this->get("logger")->err($e->getMessage());
             $success = false;
             $msg = "修改人员信息失败!";
         }
     }
     $result = array("success" => $success, "msg" => $msg);
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
 public function ThirdpartyRegisterAction()
 {
     $da = $this->get('we_data_access');
     $request = $this->getRequest();
     $login_account = trim($request->get("login_account"));
     //传入的注册账号
     $account_type = $request->get("account_type");
     $appid = $request->get("appid");
     $eno = $request->get("eno");
     $code = $request->get("code");
     $staffinfo = $request->get("staffinfo");
     //数据完整性判断
     if (empty($appid)) {
         return array("returncode" => "9999", "msg" => "应用ID不能为空。");
     }
     if (empty($code)) {
         return array("returncode" => "9999", "msg" => "动态授权码不能为空。");
     }
     if (empty($eno)) {
         return array("returncode" => "9999", "msg" => "企业编号不能为空。");
     }
     if (empty($staffinfo)) {
         return array("returncode" => "9999", "msg" => "注册人员不能为空。");
     }
     if ($account_type != "createfulluser") {
         $sql = "select appkey from we_appcenter_apps where appid=?";
         $ds = $da->GetData("table", $sql, array((string) $appid));
         if ($ds && $ds["table"]["recordcount"] == 0 || empty($ds["table"]["rows"][0]["appkey"])) {
             $result = array("success" => false, "msg" => "应用ID不正确。");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
         $appkey = $ds["table"]["rows"][0]["appkey"];
         if (strtolower($code) != strtolower(MD5($appid . $appkey))) {
             $result = array("returncode" => "9999", "msg" => "动态授权码不正确。");
             $response = new Response(json_encode($result));
             $response->headers->set('Content-Type', 'text/json');
             return $response;
         }
     }
     $thirdRegister = new \Justsy\OpenAPIBundle\Controller\ApiController();
     $thirdRegister->setContainer($this->container);
     //返回结果
     $result = array("returncode" => "0000", "msg" => "");
     $nick_name = "";
     $stafflist = json_decode($staffinfo, true);
     $openid = null;
     if ($account_type == "email") {
         //邮箱格式
         $parameter = array("email" => $login_account, "reg_name" => $stafflist[0]["nick_name"], "password" => $stafflist[0]["password"], "uid" => $stafflist[0]["uid"]);
         $para = array($parameter);
         $result = $thirdRegister->mail_registerStaff($appid, $code, $eno, json_encode($para));
     } else {
         if ($account_type == "mobile") {
             $parameter = array("mobile" => $login_account, "reg_name" => $stafflist[0]["nick_name"], "password" => $stafflist[0]["password"], "uid" => $stafflist[0]["uid"]);
             $para = array($parameter);
             $result = $thirdRegister->registerStaff($appid, $code, $eno, json_encode($para), 1);
         } else {
             if ($account_type == "createfulluser") {
                 $active = new \Justsy\BaseBundle\Controller\ActiveController();
                 $active->setContainer($this->container);
                 $result = $active->doSave($stafflist);
                 if ($result === true) {
                     $result = array("returncode" => "0000", "msg" => "");
                 } else {
                     $result = array("returncode" => "9999", "msg" => "");
                 }
             } else {
                 if ($account_type == "qq") {
                     if (isset($stafflist[0]["openid"])) {
                         $openid = $stafflist[0]["openid"];
                     }
                     if (!empty($openid)) {
                         $login_account = $this->getAccountByOpenid($openid, "tencent");
                         if (empty($login_account)) {
                             $login_account = $this->delimit_login_account("tencent_");
                             $nick_name = isset($stafflist[0]["nick_name"]) ? $stafflist[0]["nick_name"] : "";
                             if (empty($nick_name)) {
                                 $nick_name = "QQ_" . rand(100000, 999999);
                             }
                             $img_url = isset($stafflist[0]["headimgurl"]) ? $stafflist[0]["headimgurl"] : null;
                             $parameter = array("appid" => $appid, "login_account" => $login_account, "province" => "", "city" => "", "nick_name" => $nick_name, "eno" => $eno, "ldap_uid" => $stafflist[0]["uid"], "openid" => $openid, "sex" => "", "headimgurl" => $img_url, "type" => "tencent");
                             $result = $this->Register($parameter);
                             $this->get("logger")->err($login_account);
                         } else {
                             $result = array("returncode" => "99999", "msg" => "已存在该用户账号!");
                         }
                     } else {
                         $result = array("returncode" => "9999", "msg" => "请传入openid参数值");
                     }
                 } else {
                     if ($account_type == "micro") {
                         if (isset($stafflist[0]["openid"])) {
                             $openid = $stafflist[0]["openid"];
                         }
                         if (!empty($openid)) {
                             $login_account = $this->getAccountByOpenid($openid, "weixin");
                             if (empty($login_account)) {
                                 $login_account = $this->delimit_login_account("weixin_");
                                 $nick_name = isset($stafflist[0]["nick_name"]) ? $stafflist[0]["nick_name"] : null;
                                 if (empty($nick_name)) {
                                     $nick_name = "WX_" . rand(100000, 999999);
                                 }
                                 $img_url = isset($stafflist[0]["headimgurl"]) ? $stafflist[0]["headimgurl"] : null;
                                 $ldap_uid = isset($stafflist[0]["unionid"]) ? $stafflist[0]["unionid"] : null;
                                 $unionid = isset($stafflist[0]["unionid"]) ? $stafflist[0]["unionid"] : null;
                                 $parameter = array("appid" => $appid, "eno" => $eno, "openid" => $openid, "login_account" => $login_account, "nick_name" => $nick_name, "headimgurl" => $img_url, "unionid" => $unionid, "ldap_uid" => $ldap_uid, "sex" => null, "province" => null, "city" => null, "type" => "weixin");
                                 $result = $this->Register($parameter);
                             } else {
                                 $result = array("returncode" => "9999", "msg" => "已存在用户账号!");
                             }
                         } else {
                             $result = array("returncode" => "9999", "msg" => "请传入openid值!");
                         }
                     }
                 }
             }
         }
     }
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Beispiel #4
0
 public function mail_registerStaff($appid, $code, $eno, $stafflist)
 {
     $conn = $this->get("we_data_access");
     $conn_im = $this->get("we_data_access_im");
     $request = $this->getRequest();
     //if(empty($appid)) return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"应用ID不能为空。");
     //if(empty($code)) return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"动态授权码不能为空。");
     if (empty($eno)) {
         return array("returncode" => ReturnCode::$SYSERROR, "msg" => "企业编号不能为空。");
     }
     if (empty($stafflist)) {
         return array("returncode" => ReturnCode::$SYSERROR, "msg" => "注册人员不能为空,");
     }
     $sql_app = "select appkey from we_appcenter_apps where appid=?";
     $para_app = array($appid);
     $data_app = $conn->GetData("dt", $sql_app, $para_app);
     if ($data_app == null || count($data_app["dt"]["rows"]) == 0 || empty($data_app["dt"]["rows"][0]["appkey"])) {
         //return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"应用ID不正确。");
     }
     //        $appkey=$data_app["dt"]["rows"][0]["appkey"];
     //        if(strtolower($code)!=strtolower(MD5($appid.$appkey))){
     //            //return array("returncode"=>ReturnCode::$SYSERROR,"msg"=>"动态授权码不正确。");
     //        }
     //判断企业是否存在
     $sql_eno = "select a.eno,a.eno_level,a.create_staff,b.auth_level,a.sys_manager,a.ename from we_enterprise a left join we_staff b on a.create_staff=b.login_account where a.eno=?";
     $para_eno = array($eno);
     $data_eno = $conn->GetData("dt", $sql_eno, $para_eno);
     if ($data_eno == null || count($data_eno["dt"]["rows"]) == 0 || empty($data_eno["dt"]["rows"][0]["eno"])) {
         return array("returncode" => ReturnCode::$SYSERROR, "msg" => "企业编号不正确。");
     }
     $stafflist = json_decode($stafflist, true);
     $create_staff = $data_eno["dt"]["rows"][0]["create_staff"];
     if (empty($stafflist)) {
         return array("returncode" => ReturnCode::$SYSERROR, "msg" => "注册人员不正确。");
     }
     $staffdata = array();
     $staffreg = array();
     $staffnoreg = array();
     $json = array();
     $ename = $data_eno["dt"]["rows"][0]['ename'];
     //企业名称
     $eno_level = $data_eno["dt"]["rows"][0]['eno_level'];
     //企业属于什么角色
     $auth_level = $data_eno["dt"]["rows"][0]['auth_level'];
     //企业创建者属于什么角色
     $sys_manager = $data_eno["dt"]["rows"][0]['sys_manager'];
     //企业管理员
     $mobileReg = new \Justsy\InterfaceBundle\Controller\MobileRegisterController();
     $mobileReg->setContainer($this->container);
     for ($i = 0; $i < count($stafflist); $i++) {
         if (!empty($stafflist[$i]["reg_name"]) && !empty($stafflist[$i]["email"])) {
             //需要验证电子邮箱的合法性
             $pattern = $this->checkmail();
             $login_account = $stafflist[$i]['email'];
             $reg_name = $stafflist[$i]['reg_name'];
             $password = isset($stafflist[$i]["password"]) ? $stafflist[$i]["password"] : "******";
             $ldap_uid = isset($stafflist[$i]["uid"]) ? $stafflist[$i]["uid"] : "";
             $this->get("logger")->err("-----------------传入的ldap_uid:" . $ldap_uid);
             if (preg_match($pattern, $login_account)) {
                 //验证通过
                 $sql_staff = "select eno,mobile,openid,nick_name,auth_level from we_staff where login_account=? ";
                 $para_staff = array($login_account);
                 $data_staff = $conn->GetData("dt", $sql_staff, $para_staff);
                 if ($data_staff != null && count($data_staff["dt"]["rows"]) > 0 && !empty($data_staff["dt"]["rows"][0]["openid"])) {
                     //成员已经存在
                     if ($data_staff["dt"]["rows"][0]["eno"] != $eno) {
                         array_push($staffreg, array("openid" => "", "login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人邮箱已注册,加入企业编号与【" . $eno . "】不是同一企业。"));
                     } else {
                         if ($data_staff["dt"]["rows"][0]["nick_name"] != $reg_name) {
                             array_push($staffreg, array("openid" => "", "login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人邮箱已注册,注册人姓名与【" . $reg_name . "】不一致。"));
                         } else {
                             //同一企业的同一用户需要修改权限
                             $mobile = $data_staff["dt"]["rows"][0]["mobile"];
                             $staff_auth_level = $data_staff["dt"]["rows"][0]["auth_level"];
                             //权限与管理员不一致,修改人员权限
                             if ($staff_auth_level != $auth_level) {
                                 try {
                                     $sql_upd = "update we_staff set auth_level=? where login_account=? ";
                                     $para_upd = array($staff_auth_level, $login_account);
                                     $conn->ExecSQL($sql_upd, $para_upd);
                                     $staffRole = new \Justsy\BaseBundle\Rbac\staffRole($conn, $conn_im, $this->container);
                                     $staffRole->UpdateStaffRoleByCode($login_account, $auth_level . $eno_level, $staff_auth_level . $eno_level, $eno);
                                 } catch (\Exception $e) {
                                     $this->get("logger")->err($e->getMessage());
                                 }
                             }
                             $staffMgr = new \Justsy\BaseBundle\Management\Staff($conn, $conn_im, $login_account, $this->get("logger"));
                             //和管理员相互添加好友
                             if (!empty($sys_manager)) {
                                 $sysmanager = explode(';', $sys_manager);
                                 //循环添加管理员为好友
                                 for ($i = 0; $i < count($sysmanager); $i++) {
                                     $manager_staff = trim($sysmanager[$i]);
                                     try {
                                         if (!empty($manager_staff)) {
                                             $staffMgr->bothAddFriend($this->container, $manager_staff);
                                         }
                                     } catch (\Exception $e) {
                                         $this->get("logger")->err($e->getMessage());
                                     }
                                 }
                             }
                             try {
                                 //和创建者相互添加好友
                                 $staffMgr->bothAddFriend($this->container, $create_staff);
                             } catch (\Exception $e) {
                                 $this->get("logger")->err($e->getMessage());
                             }
                             array_push($staffreg, array("openid" => $data_staff["dt"]["rows"][0]["openid"], "login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人邮箱已注册。"));
                         }
                     }
                 } else {
                     //手机号码未被注册
                     //获取企业名称
                     $sql = "select ename from we_enterprise where eno=?";
                     $params = array($eno);
                     $ds = $conn->Getdata('enoname', $sql, $params);
                     $ename = '';
                     $mailtype = '';
                     if ($ds['enoname']['recordcount'] > 0) {
                         $ename = $ds['enoname']['rows'][0]['ename'];
                     }
                     $sql1 = "select 1 from we_public_domain where domain_name=?";
                     $params1 = array($this->getSubDomain($login_account));
                     $ds1 = $conn->Getdata('tt', $sql1, $params1);
                     if ($ds1['tt']['recordcount'] > 0) {
                         $mailtype = '0';
                     } else {
                         $mailtype = '1';
                     }
                     $active = new \Justsy\BaseBundle\Controller\ActiveController();
                     $active->setContainer($this->container);
                     $active->doSave(array('account' => $login_account, 'realName' => $reg_name, 'passWord' => $password, 'eno' => $eno, 'ename' => $ename, 'isNew' => '0', 'mailtype' => $mailtype, 'ldap_uid' => $ldap_uid, 'import' => '1'));
                     $sql = "select openid from we_staff where login_account=?";
                     $params = array($login_account);
                     $ds = $conn->Getdata('op', $sql, $params);
                     $openid = '';
                     if ($ds['op']['recordcount'] > 0) {
                         $openid = $ds['op']['rows'][0]['openid'];
                     }
                     $res = array('openid' => $openid);
                     if (!empty($res["openid"])) {
                         //更改其他信息
                         array_push($staffdata, array("openid" => $res["openid"], "login_account" => $login_account));
                         //"reg_name"=>$reg_name,
                     } else {
                         //注册成员失败
                         $msg = "注册成员失败。";
                         if (!empty($res["msg"])) {
                             $msg = $res["msg"];
                         }
                         array_push($staffnoreg, array("login_account" => $login_account, "reg_name" => $reg_name, "msg" => $msg));
                     }
                 }
             } else {
                 //电子邮件格式不对
                 array_push($staffnoreg, array("login_account" => $login_account, "reg_name" => $reg_name, "msg" => "注册人帐号格式不正确。"));
             }
         }
     }
     //返回结果
     if (empty($staffdata) && empty($staffreg) && empty($staffnoreg)) {
         $json = array("returncode" => ReturnCode::$SYSERROR, "msg" => "没有人员需要注册。");
     } else {
         $json = array("returncode" => ReturnCode::$SUCCESS, "list" => $staffdata, "reg" => $staffreg, "noreg" => $staffnoreg);
     }
     return $json;
 }
Beispiel #5
0
 public static function userAuthAction($container, $request, $dbcon, $con_im, $login_account, $password, $comefrom)
 {
     $defaultPostURl = "http://10.100.20.27/CallCenter/ESB_InvokeService.ashx";
     $cacheobj = new Enterprise($dbcon, $container->get("logger"), $container);
     //
     $authConfig = $cacheobj->getUserAuth();
     $httpUrlConfig = $authConfig["ssoauthurl"];
     if (empty($httpUrlConfig)) {
         $httpUrlConfig = $defaultPostURl;
         $eno = "100001";
     } else {
         $ldapConfgiObject = json_decode($httpUrlConfig, true);
         $eno = $ldapConfgiObject["ENO"];
         $httpUrlConfig = $ldapConfgiObject["URL"];
     }
     try {
         $data = array();
         $data["loginName"] = $login_account;
         $data["password"] = $password;
         $data["isNeedSyn"] = false;
         $para = "ServiceName=WXSC_Account&MethodName=POST:JSON:UserAuthentication&Message=" . json_encode($data) . "&Version=1";
         $container->get("logger")->err("SOA URL:" . $httpUrlConfig . "?" . $para);
         $postresult = Utils::do_post_request($httpUrlConfig, $para);
         $container->get("logger")->err("SOA Result:" . $postresult);
         $resultObject = json_decode($postresult, true);
         if (!empty($resultObject["errcode"]) || $resultObject["isSuccess"] === false) {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             return $re;
         }
         $mbuser = $resultObject["results"];
         $fafa_account = strtolower($login_account . "@fafatime.com");
         if (count($mbuser) > 0) {
             $mbuser = $mbuser[0];
             $nickName = isset($mbuser["nickName"]) ? $mbuser["nickName"] : $mbuser["phoneNumber"];
             $staff = new Staff($dbcon, $con_im, $fafa_account);
             $staffinfo = $staff->getInfo();
             if (empty($staffinfo)) {
                 //新用户:注册 激活
                 $enInfo = $cacheobj->getInfo($eno);
                 $active = new \Justsy\BaseBundle\Controller\ActiveController();
                 $active->setContainer($container);
                 $uid = strtolower($mbuser["id"]);
                 $active->doSave(array('account' => $fafa_account, 'realName' => $nickName, 'passWord' => $password, 'eno' => $eno, 'ename' => $enInfo["ename"], 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1'));
                 $sex_id = "1";
                 $duty = isset($mbuser["userRoles"]) ? $mbuser["userRoles"] : "";
                 $ldap_uid = isset($mbuse["id"]) ? $mbuser["id"] : "";
                 $tmp = "";
                 if (!empty($duty) && count($duty) > 0) {
                     for ($i = 0; $i < count($duty); $i++) {
                         $tmp = $duty[$i]["roleName"];
                         if ($tmp == "Designer") {
                             break;
                         }
                     }
                 }
                 if ($tmp == "Designer") {
                     $duty = "造型师";
                 } else {
                     $duty = "";
                 }
                 $sql = "update we_staff set ldap_uid=?,sex_id=?,duty=? where login_account=?";
                 $params = array($uid, (string) $sex_id, $duty, $fafa_account);
                 $dbcon->ExecSQL($sql, $params);
                 if (!empty($mbuser["phoneNumber"])) {
                     $staff->checkAndUpdate(null, $mbuser["phoneNumber"], null, null);
                 }
             } else {
                 $duty = isset($mbuser["userRoles"]) ? $mbuser["userRoles"] : "";
                 $ldap_uid = isset($mbuser["id"]) ? $mbuser["id"] : "";
                 $tmp = "";
                 if (!empty($duty) && count($duty) > 0) {
                     for ($i = 0; $i < count($duty); $i++) {
                         $tmp = $duty[$i]["roleName"];
                         if ($tmp == "Designer") {
                             break;
                         }
                     }
                 }
                 if ($tmp == "Designer") {
                     $duty = "造型师";
                 } else {
                     $duty = "";
                 }
                 //更新信息
                 $staff->checkAndUpdate($nickName, $mbuser["phoneNumber"], null, $duty, $ldap_uid);
             }
             //头像
             $headUrl = $mbuser["headPortrait"];
         }
         $Obj = new \Justsy\BaseBundle\Login\UserProvider($container);
         $user = $Obj->loadUserByUsername($fafa_account, $comefrom);
         //�Ǽ�seesion
         $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($user, $user->getPassword(), "secured_area", $user->getRoles());
         $container->get("security.context")->setToken($token);
         $session = $request->getSession()->set('_security_' . 'secured_area', serialize($token));
         $event = new \Symfony\Component\Security\Http\Event\InteractiveLoginEvent($request, $token);
         $container->get("event_dispatcher")->dispatch("security.interactive_login", $event);
         $re["returncode"] = ReturnCode::$SUCCESS;
         $re["openid"] = $user->openid;
         $re["login_account"] = $fafa_account;
         $re["ldap_uid"] = $user->ldap_uid;
         $re["jid"] = $user->fafa_jid;
         //为了避免用户修改密码后只刷新了所在服务器,im密码实时获取
         $sql = "select password from users where username=?";
         $iminfo = $con_im->GetData("im", $sql, array((string) $user->fafa_jid));
         $re["des"] = count($iminfo["im"]["rows"]) > 0 ? $iminfo["im"]["rows"][0]["password"] : "";
     } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
         $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
     } catch (\Exception $e) {
         $re["returncode"] = ReturnCode::$SYSERROR;
     }
     return $re;
 }
Beispiel #6
0
 public function register_announcer($parameter)
 {
     $nick_name = isset($parameter["name"]) ? $parameter["name"] : null;
     $state = isset($parameter["state"]) ? $parameter["state"] : "add";
     $login_account = isset($parameter["login_account"]) ? $parameter["login_account"] : null;
     $account = explode("@", $login_account);
     $ldap_uid = $account[0];
     $deptid = isset($parameter["deptid"]) ? $parameter["deptid"] : array();
     $fileid = isset($parameter["fileid"]) ? $parameter["fileid"] : null;
     $fileid = empty($fileid) ? null : $fileid;
     $password = isset($parameter["password"]) ? $parameter["password"] : null;
     $staffid = isset($parameter["staffid"]) ? $parameter["staffid"] : array();
     $user = $parameter["user"];
     $success = true;
     $msg = "";
     $da = $this->conn;
     if ($state == "add") {
         //取公众号部门id
         $departmentid = "";
         $sql = " select dept_id from we_department where fafa_deptid=?;";
         $ds = $da->GetData("table", $sql, array("v" . $user->eno . "999888"));
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $departmentid = $ds["table"]["rows"][0]["dept_id"];
             $register = new \Justsy\BaseBundle\Controller\ActiveController();
             $register->setContainer($this->container);
             $register_parameter = array("account" => $login_account, "realName" => $nick_name, "passWord" => $password, "ldap_uid" => $ldap_uid, "eno" => $user->eno, "ename" => $user->ename, "isNew" => '0', "mailtype" => "1", "import" => '1', "isSendMessage" => "N", "mobile" => "", "duty" => "", "indefaultgroup" => "N", "mutual" => "N", "deptid" => $departmentid);
             $success = $register->doSave($register_parameter);
         }
         if ($success) {
             //向广播员添加具有的默认菜单项
             $sql = "insert into mb_staff_menu(staff_id,menu_id)values(?,'firendcircle');";
             try {
                 $da->ExecSQL($sql, array((string) $login_account));
             } catch (\Exception $e) {
             }
         }
         if (!$success) {
             $msg = "用户账号(" . $login_account . ")注册失败!";
         }
     } else {
         //用户修改了密码的操作
         if (!empty($password)) {
             $u_staff = new Staff($da, $this->conn_im, $login_account, $this->logger);
             $targetStaffInfo = $u_staff->getInfo();
             $re = $u_staff->changepassword($targetStaffInfo["login_account"], $password, $this->container->get('security.encoder_factory'));
             $this->logger("-----------" . $re);
         }
     }
     if ($success) {
         $sqls = array();
         $paras = array();
         //修改头像
         $sql = "update we_staff set nick_name=?,photo_path=?,photo_path_small=?,photo_path_big=? where login_account=?;";
         $para = array((string) $nick_name, (string) $fileid, (string) $fileid, (string) $fileid, (string) $login_account);
         array_push($sqls, $sql);
         array_push($paras, $para);
         //修改im数据
         //获得fafa_jid
         $fafa_jid = "";
         $sql = "select fafa_jid from we_staff where login_account=?;";
         $ds = $da->GetData("table", $sql, array((string) $login_account));
         if ($ds && $ds["table"]["recordcount"] > 0) {
             $fafa_jid = $ds["table"]["rows"][0]["fafa_jid"];
             $sql_im = "update im_employee set employeename=?,photo=? where loginname=?;";
             $para_im = array((string) $nick_name, $fileid, (string) $fafa_jid);
             try {
                 $this->conn_im->ExecSQL($sql_im, $para_im);
             } catch (\Exception $e) {
             }
         }
         if ($state == "edit") {
             $sql = "delete from we_announcer where login_account=?;";
             $da->ExecSQL($sql, array((string) $login_account));
         }
         //部门的处理
         for ($j = 0; $j < count($deptid); $j++) {
             $sql = "insert into we_announcer(login_account,objid,`type`)values(?,?,1)";
             $para = array((string) $login_account, (string) $deptid[$j]);
             array_push($sqls, $sql);
             array_push($paras, $para);
         }
         //人员的处理
         for ($j = 0; $j < count($staffid); $j++) {
             $sql = "insert into we_announcer(login_account,objid,`type`)values(?,?,2)";
             $para = array((string) $login_account, (string) $staffid[$j]);
             array_push($sqls, $sql);
             array_push($paras, $para);
         }
         try {
             $da->ExecSQLS($sqls, $paras);
         } catch (\Exception $e) {
             $success = false;
             $msg = "更新用户信息失败!";
             $this->logger->err($e->getMessage());
         }
     }
     return array("success" => $success, "msg" => $msg);
 }
Beispiel #7
0
 public static function tokenValidate($container, $token)
 {
     $request = $container->get("request");
     $dbcon = $container->get("we_data_access");
     $con_im = $container->get("we_data_access_im");
     $rest = "/rest/validate";
     $defaultPostURl = "https://sso.avicmall.com:8443";
     $appcodeConfig = "fafa-app";
     $appkeyConfig = "DKGHwqJ5H91noPYNYm9b8EUPQSY";
     $cacheobj = new Enterprise($dbcon, $container->get("logger"), $container);
     //
     $authConfig = $cacheobj->getUserAuth();
     $httpUrlConfig = $authConfig["ssoauthurl"];
     if (empty($httpUrlConfig)) {
         $httpUrlConfig = $defaultPostURl;
         $eno = "100001";
     } else {
         $ldapConfgiObject = json_decode($httpUrlConfig, true);
         $eno = $ldapConfgiObject["ENO"];
         $httpUrlConfig = $ldapConfgiObject["URL"];
         $appcodeConfig = $ldapConfgiObject["AppCode"];
         $appkeyConfig = $ldapConfgiObject["AppKey"];
     }
     $httpUrlConfig = $httpUrlConfig . $rest;
     try {
         $reqHeader = SsoAvicAuth::getHeaders($appcodeConfig, $appkeyConfig);
         $para = array("ticketName" => "SIAMTGT", "ticketValue" => $token);
         //$container->get("logger")->err("SOA URL:".$httpUrlConfig." Body:".json_encode($para));
         $postresult = Utils::do_post_request($httpUrlConfig, json_encode($para), $reqHeader, $container->get("logger"));
         //$container->get("logger")->err("SOA Result:".$postresult);
         $resultObject = json_decode($postresult, true);
         if (!isset($resultObject["status"])) {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             $re["msg"] = "服务器异常";
             return $re;
         }
         if (!$resultObject["status"] || $resultObject["status"] == "false") {
             $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
             $re["msg"] = $resultObject["message"];
             return $re;
         }
         $usertoken = $resultObject["ticketEntry"]["ticketValue"];
         $user = $resultObject["user"];
         //用户信息
         $nickName = $user["cn"];
         //获取姓名
         $phoneNumber = $user["smart-securemobile"];
         //获取手机号
         $login_account = $user["uid"];
         $eninfo = $cacheobj->getInfo($eno);
         $domain = $eninfo["edomain"];
         $domain = strpos($domain, ".") === false ? "fafatime.com" : $domain;
         $fafa_account = strtolower($login_account . "@" . $domain);
         $staff = new Staff($dbcon, $con_im, $fafa_account);
         $staffinfo = $staff->getInfo();
         if (empty($staffinfo)) {
             $password = rand(100000, 999999);
             //新用户:注册 激活
             $enInfo = $cacheobj->getInfo($eno);
             $active = new \Justsy\BaseBundle\Controller\ActiveController();
             $active->setContainer($container);
             $uid = strtolower($login_account);
             $active->doSave(array('account' => $fafa_account, 'realName' => $nickName, 'passWord' => $password, 'eno' => $eno, 'ename' => $enInfo["ename"], 'isNew' => '0', 'mailtype' => "1", 'deptid' => "100054", 'isSendMessage' => "N", 'import' => '1'));
             $sql = "update we_staff set ldap_uid=?,mobile=?,mobile_bind=? where login_account=?";
             $params = array((string) $uid, (string) $phoneNumber, (string) $phoneNumber, (string) $fafa_account);
             $dbcon->ExecSQL($sql, $params);
         } else {
             $ldap_uid = $login_account;
             //更新信息
             if ($nickName == $staffinfo["nick_name"]) {
                 $nickName = null;
             }
             if ($phoneNumber == $staffinfo["mobile"]) {
                 $phoneNumber = null;
             }
             if (!empty($nickName) || !empty($phoneNumber)) {
                 try {
                     $staff->checkAndUpdate($nickName, $phoneNumber, null, null, $ldap_uid);
                 } catch (\Exception $e) {
                     $container->get("logger")->err($e->getMessage());
                 }
             }
         }
         $Obj = new \Justsy\BaseBundle\Login\UserProvider($container);
         $user = $Obj->loadUserByUsername($fafa_account, $comefrom);
         //�Ǽ�seesion
         $token = new \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken($user, $user->getPassword(), "secured_area", $user->getRoles());
         $container->get("security.context")->setToken($token);
         $session = $request->getSession()->set('_security_' . 'secured_area', serialize($token));
         $event = new \Symfony\Component\Security\Http\Event\InteractiveLoginEvent($request, $token);
         $container->get("event_dispatcher")->dispatch("security.interactive_login", $event);
         $re["returncode"] = ReturnCode::$SUCCESS;
         $re["openid"] = $user->openid;
         $re["login_account"] = $fafa_account;
         $re["ldap_uid"] = $user->ldap_uid;
         $re["jid"] = $user->fafa_jid;
         $re["token"] = $usertoken;
         //用户凭据
         //为了避免用户修改密码后只刷新了所在服务器,im密码实时获取
         $sql = "select password from users where username=?";
         $iminfo = $con_im->GetData("im", $sql, array((string) $user->fafa_jid));
         $re["des"] = count($iminfo["im"]["rows"]) > 0 ? $iminfo["im"]["rows"][0]["password"] : "";
     } catch (\Symfony\Component\Security\Core\Exception\UsernameNotFoundException $e) {
         $re["returncode"] = ReturnCode::$ERROFUSERORPWD;
     } catch (\Exception $e) {
         $re["msg"] = $e->getMessage();
         $re["returncode"] = ReturnCode::$SYSERROR;
     }
     return $re;
 }