public function loadUserByUsername($username, $comeform = "") { if (Utils::validateMobile($username)) { //手机登录 return $this->loadUserByUsernameWithMobile($username); } $DataAccess = $this->container->get('we_data_access'); $staff = new \Justsy\BaseBundle\Management\Staff($DataAccess, $this->container->get('we_data_access_im'), $username, $this->container->get("logger"), $this->container); $us = $staff->getInfo(); if (!empty($us)) { $us = $staff->getSessionUser($us); return $us; } else { throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); } }
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 savemobilebind2Action($user) { $re = array(); $request = $this->getRequest(); $txtmobile = $request->get("txtmobile"); $txtvaildcode = $request->get("txtvaildcode"); $da = $this->get("we_data_access"); if (empty($txtmobile) || !Utils::validateMobile($txtmobile)) { $re["success"] = "0"; $re["msg"] = "请输入正确的手机号!"; $response = new Response(json_encode($re)); $response->headers->set('Content-Type', 'text/json'); return $response; } //根据帐号和手机号获取验证码 $sql = "select * from we_mobilebind_validcode where login_account=? and mobileno=? and actiontype='MB' order by req_date desc limit 0,1"; $ds = $da->GetData("t", $sql, array((string) $user["login_account"], (string) $txtmobile)); if (empty($ds) || count($ds["t"]["rows"]) == 0) { $re["success"] = "0"; $re["msg"] = "请输入获取验证码时的手机号!"; $response = new Response(json_encode($re)); $response->headers->set('Content-Type', 'text/json'); return $response; } if (empty($txtvaildcode) || $txtvaildcode != $ds["t"]["rows"][0]["validcode"]) { $re["success"] = "0"; $re["msg"] = "请输入正确的验证码!"; $response = new Response(json_encode($re)); $response->headers->set('Content-Type', 'text/json'); return $response; } try { $sqls = array(); $all_params = array(); $sql = "update we_staff set mobile_bind=null where mobile_bind=?"; $params = array(); $params[] = $txtmobile; $sqls[] = $sql; $all_params[] = $params; $sql = "update we_staff set mobile=?, mobile_bind=? where login_account=?"; $params = array(); $params[] = $txtmobile; $params[] = $txtmobile; $params[] = $user["login_account"]; $sqls[] = $sql; $all_params[] = $params; $da->ExecSQLs($sqls, $all_params); //发送手机绑定通知 try { $noticeMsg = array(); $noticeMsg["login_account"] = $user["login_account"]; $noticeMsg["nick_name"] = $user["nick_name"]; $noticeMsg["mobile_bind"] = "1"; $message = json_encode($noticeMsg); $staffMgr = new \Justsy\BaseBundle\Management\Staff($da, $this->get("we_data_access_im"), $user["login_account"]); Utils::sendImPresence("", implode(",", $staffMgr->getFriendAndColleagueJid()), "mobile_bind", $message, $this->container, "", "", false, Utils::$systemmessage_code); } catch (\Exception $e) { $this->get("logger")->err($e); } $re["success"] = "1"; } catch (\Exception $e) { $re["success"] = "0"; $re["msg"] = "绑定手机号失败!请重试"; $this->get('logger')->err($e); } $response = new Response(json_encode($re)); $response->headers->set('Content-Type', 'text/json'); return $response; }
public function sendMsg2($from, $to, $msg, $type, $isCheckTo = false, $cctomail = "0", $msg_id = "") { $pre_code = '/"code":".*?"/i'; preg_match($pre_code, $msg, $result); if (count($result) > 0) { $type = str_replace(""", "", $result[0]); $type = str_replace("code:", "", $type); } //获取发送人和接收人jid或者openid $from = trim($from); $msg = urlencode(trim($msg)); if (empty($from)) { $domain = $this->container->getParameter('edomain'); $from = "admin@" . $domain; } if (empty($msg)) { return array('returncode' => '9999', 'msg' => '消息内容不能为空'); } $da = $this->get("we_data_access"); $senderMail = "admin@" . $this->container->getParameter('edomain'); if (!strpos($from, "@")) { //获取opendid对应的jid,没找到则返回错误 if (Utils::validateMobile($from)) { //手机号 $table = $da->GetData("staff", "select fafa_jid,login_account from we_staff where mobile_bind=? ", array((string) $from, (string) $from)); } else { $table = $da->GetData("staff", "select fafa_jid,login_account from we_staff where openid=? or ldap_uid=?", array((string) $from, (string) $from)); } if (count($table["staff"]["rows"]) == 0) { return array('returncode' => '9999', 'msg' => '消息发送者参数不能为空'); } $from = $table["staff"]["rows"][0]["fafa_jid"]; $senderMail = $table["staff"]["rows"][0]["login_account"]; } else { if (strpos($from, "admin") === false) { //jid $table = $da->GetData("staff", "select fafa_jid,login_account from we_staff where fafa_jid=? or login_account=?", array((string) $from, (string) $from)); if (count($table["staff"]["rows"]) == 0) { return array('returncode' => '9999', 'msg' => '消息发送者参数不能为空'); } $from = $table["staff"]["rows"][0]["fafa_jid"]; $senderMail = $table["staff"]["rows"][0]["login_account"]; } } //-------------check To-------------- if (empty($to)) { return array('returncode' => '9999', 'msg' => '消息接收者参数不能为空'); } $arr = is_array($to) ? $to : explode(",", $to); $regUrl = $this->container->getParameter("FAFA_REG_JID_URL"); $toLst = array(); $nosendLst = array(); foreach ($arr as $key => $value) { $to2 = $value; if ($isCheckTo === false && $cctomail != "1") { $toLst[] = $to2; continue; //是否需要检查接收人是否有效。当内部调用且100%能确定有效且不抄送邮箱(要抄送时还是得去查询一次)时,可设置为不再检查 } if (!strpos($to2, "@")) { //获取opendid对应的jid,没找到则返回错误 if (Utils::validateMobile($to2)) { //手机号 $table = $da->GetData("staff", "select fafa_jid,login_account from we_staff where mobile_bind=? ", array((string) $to2)); } else { $table = $da->GetData("staff", "select fafa_jid,login_account from we_staff where openid=? or ldap_uid=?", array((string) $to2, (string) $to2)); } if (count($table["staff"]["rows"]) == 0) { $nosendLst[] = $to2; continue; } $to2 = $table["staff"]["rows"][0]["fafa_jid"]; if ($cctomail == "1") { Utils::saveMail($da, $senderMail, $table["staff"]["rows"][0]["login_account"], $title, $msg); } } else { if (strpos($to2, "admin") === false) { //jid $staffMgr = new Staff($da, $this->get("we_data_access_im"), $to2, $this->get("logger"), $this->container); $staffinfo = $staffMgr->getInfo(); if (!empty($staffinfo)) { $to2 = $staffinfo["fafa_jid"]; } else { $table = $da->GetData("staff", "select fafa_jid,login_account from we_staff where fafa_jid=?", array((string) $to2)); if (count($table["staff"]["rows"]) == 0) { $nosendLst[] = $to2; continue; } $to2 = $table["staff"]["rows"][0]["fafa_jid"]; if ($cctomail == "1") { Utils::saveMail($da, $senderMail, $table["staff"]["rows"][0]["login_account"], urldecode(iconv('UTF-8', 'GBK', $title)), urldecode(iconv('UTF-8', 'GBK', $msg)), "business-message"); } } } } $toLst[] = $to2; } $regUrlOrg = $regUrl . "/service.yaws"; $data = "sendMicroMsg=1&from={$from}&to=" . implode(",", $toLst) . "&msg={$msg}&type={$type}&busdata={$msg_id}"; //$this->get("logger")->alert("SEND MSG URL:$regUrlOrg?$data"); $re = Utils::do_post_request($regUrlOrg, $data); if (count($nosendLst) == 0) { return array('returncode' => '0000', 'nosend' => ''); } else { return array('returncode' => '0000', 'nosend' => implode(",", $nosendLst)); } }
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; $duty_index = 0; $dept_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) { $duty_index = $col; } else { if (strpos($titleAry[$col], "部门") !== false) { $dept_index = $col; } else { if (strpos($titleAry[$col], "密码") !== false) { $pwd_index = $col; } } } } } } } } $dm = $this->get("we_data_access_im"); $titleAry[] = "eno"; $err_list = array(); $active = new \Justsy\BaseBundle\Controller\ActiveController(); $active->setContainer($this->container); //获取数据行 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($this->get("we_data_access"), $this->get("we_data_access_im"), $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' => $user->ename, 'eshortname' => $user->eshortname, 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1')); $dm->ExecSQL("call dept_emp_stat(?)", array((string) $user->eno)); $staffmgr = new Staff($da, $dm, $account); $importData = $staffmgr->getImportInfo(); $staffmgr->updateByImport($importData); $staffmgr->deleteImportPhy(); } else { if ($isImport === false) { if ($active->doSave(array('account' => $account, 'passWord' => empty($mobile) ? $account : $mobile, 'realName' => $name, 'eno' => $user->eno, 'ename' => $user->ename, 'eshortname' => $user->eshortname, 'isNew' => '0', 'mailtype' => "1", 'isSendMessage' => "N", 'import' => '1'))) { $staffmgr = new Staff($da, $dm, $account); //根据导入信息更新注册信息 $importData = $staffmgr->getImportInfo(); $staffmgr->updateByImport($importData); $staffmgr->deleteImportPhy(); } } else { $err_list[] = array("name" => $name, "msg" => "注册失败!"); } } } 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 resetpwdAction() { $request = $this->getRequest(); $account = $request->get("account"); $txtvaildcode = $request->get("txtvaildcode"); $pwd = $request->get("txtnewpwd"); $pwd_im = $pwd; $da = $this->get("we_data_access"); $da_im = $this->get("we_data_access_im"); $re = array("returncode" => ReturnCode::$SUCCESS); if (empty($account)) { return $this->responseJson(Utils::WrapResultError("帐号不能为空"), $request->get('jsoncallback')); } if (empty($txtvaildcode)) { return $this->responseJson(Utils::WrapResultError("验证码不能为空"), $request->get('jsoncallback')); } //验证帐号及验证码 $isEmail = Utils::validateEmail($account); $isMobile = Utils::validateMobile($account); if (!$isEmail && !$isMobile) { return $this->responseJson(Utils::WrapResultError("帐号格式不正确,仅支持邮箱或手机帐号"), $request->get('jsoncallback')); } $u_staff = new \Justsy\BaseBundle\Management\Staff($da, $da_im, $account, $this->get('logger'), $this->container); $targetStaffInfo = $u_staff->getInfo(); if (empty($targetStaffInfo)) { return $this->responseJson(Utils::WrapResultError("帐号无效"), $request->get('jsoncallback')); } $sysparam = new \Justsy\BaseBundle\DataAccess\SysParam($this->container); $wn_code = $sysparam->GetSysParam("mobile_active_code"); if ($txtvaildcode != $wn_code) { $sql = "select * from we_mobilebind_validcode where login_account=? and actiontype='FP' and valid_date>now() order by valid_date desc limit 0,1"; $ds = $da->GetData('t', $sql, array((string) $account)); if ($txtvaildcode != $ds["t"]["rows"][0]["validcode"]) { return $this->responseJson(Utils::WrapResultError("验证码无效"), $request->get('jsoncallback')); } } try { $login_account = $targetStaffInfo['login_account']; $re = $u_staff->changepassword($login_account, $pwd, $this->get('security.encoder_factory')); return $this->responseJson($re, $request->get('jsoncallback')); } catch (Exception $e) { return $this->responseJson(Utils::WrapResultError("重置密码失败,请稍后重试"), $request->get('jsoncallback')); } }
public function mobilenumregAction() { $logger = $this->get("logger"); $request = $this->getRequest(); $txtmobile = trim($request->get('mobile_num')); $response = $this->getResponse(ReturnCode::$SUCCESS, ""); //验证手机号是否合法 if (!Utils::validateMobile($txtmobile)) { $logger->err("请输入正确的手机号[" . $txtmobile . "]"); return $this->getResponse(ReturnCode::$OTHERERROR, "请输入正确的手机号!"); } $login_account = $txtmobile; $domain = $this->container->getParameter('edomain'); if (!strpos($login_account, "@")) { $login_account .= "@" . $domain; } try { //手机号是否已经被使用 $da = $this->get('we_data_access'); $sql = "select count(1) as cnt from we_staff where mobile_bind=? and state_id!='3'"; $ds = $da->GetData("we_staff", $sql, array($txtmobile)); if ($ds && $ds['we_staff']['rows'][0]['cnt'] > 0) { $this->get("logger")->err("手机号已被使用"); return $this->getResponse(ReturnCode::$OTHERERROR, "该手机号已注册,继续使用请先找回密码"); } $active_code = rand(100000, 999999); $sql = "select submit_num,state_id,last_reg_date,timestampdiff(second,last_reg_date,now()) as dif" . " from we_register where login_account=?"; $ds = $da->GetData("we_register", $sql, array($login_account)); //$logger->err("记录数:".$ds["we_register"]["recordcount"]); if ($ds && $ds['we_register']['recordcount'] > 0) { if ($ds['we_register']['rows'][0]['state_id'] == '3') { return $this->getResponse(ReturnCode::$OTHERERROR, "该手机号已注册,继续使用请先找回密码"); } if ($ds['we_register']['rows'][0]['dif'] <= 60) { return $this->getResponse(ReturnCode::$OTHERERROR, "你获取验证码的次数太频繁!一分钟只能取一次!"); } if ($ds['we_register']['rows'][0]['submit_num'] > 5 && $ds['we_register']['rows'][0]['dif'] <= 60 * 60 * 24) { return $this->getResponse(ReturnCode::$OTHERERROR, "抱歉,验证码请求次数过多,如果获取不到验证码请根据下方提示与我们联系"); } else { if ($ds['we_register']['rows'][0]['dif'] > 60 * 60 * 24) { //一天以后重置 $sql = "update we_register set submit_num=0 where login_account=?"; $da->ExecSQL($sql, array($login_account)); } } $sql = "update we_register set active_code=?,last_reg_date=now(),submit_num=ifnull(submit_num,0)+1," . "state_id='0',review_note='0' where login_account=?"; } else { $sql = "insert into we_register (active_code,login_account,submit_num,state_id,first_reg_date,last_reg_date," . "register_date,review_note) values (?,?,1,'0',now(),now(),now(),'0')"; } $para = array($active_code, $login_account); $da->ExecSQL($sql, $para); $content = "验证码:" . $active_code . ",2分钟内有效,仅用于注册。【企业】"; $ec = new \Justsy\BaseBundle\Controller\SendSMSController(); $ec->setContainer($this->container); $ret = $ec->sendSMSAction($txtmobile, $content); if ($ret['returncode'] != '0000') { $response = $this->getResponse(ReturnCode::$OTHERERROR, json_encode($ret)); $this->get('logger')->err($ret); } } catch (\Exception $e) { $response = $this->getResponse(ReturnCode::$OTHERERROR, "获取验证码失败!请重试"); $this->get('logger')->err($e); } return $response; }
public function createstaff($parameter) { $deploy_mode = $this->container->getParameter('deploy_mode'); $mobile_num = $parameter['account']; $mobile_pwd = $parameter['password']; $org_pwd = $mobile_pwd; //原始密码 $deptid = isset($parameter['deptid']) ? $parameter['deptid'] : ""; $eno = isset($parameter['eno']) ? $parameter['eno'] : $this->container->getParameter('ENO'); $nick_name = $parameter['nick_name']; $ldap_uid = isset($parameter["ldap_uid"]) ? $parameter["ldap_uid"] : ""; //优先采用第三方标识做为帐号,其次使用手机号做为帐号 $login_account = empty($ldap_uid) ? $mobile_num : $ldap_uid; if (empty($login_account)) { return Utils::WrapResultError("请输入帐号!"); } if (empty($mobile_pwd)) { return Utils::WrapResultError("请输入密码!"); } if (empty($nick_name)) { return Utils::WrapResultError("请输入昵称!"); } if (!strpos($login_account, "@")) { $domain = $this->container->getParameter('edomain'); $login_account .= "@" . $domain; } $this->account = $login_account; $isHd = $this->getInfo(); if (!empty($isHd)) { //已经注册,直接返回 return Utils::WrapResultOK($isHd); } if (!empty($mobile_num) && Utils::validateMobile($mobile_num)) { if ($this->checkUser($mobile_num)) { return Utils::WrapResultError("该手机号已被绑定,请解绑后重试"); } } $da = $this->conn; $da_im = $this->conn_im; try { //同步人员到业务系统 $syncurl = null; try { //判断是否需要同步到其他系统 $syspara = new \Justsy\BaseBundle\DataAccess\SysParam($this->container); $syncurl = $syspara->GetSysParam('staff_sync_url', ''); } catch (\Exception $e) { } $cacheobj = new \Justsy\BaseBundle\Management\Enterprise($da, $this->logger, $this->container); //获取用户认证模块 $authConfig = $cacheobj->getUserAuth(); if (!empty($syncurl) && !empty($authConfig)) { try { $classname = $authConfig["ssoauthmodule"]; if (!empty($classname)) { $parameters = array("nick_name" => $nick_name, "mobile" => $login_account, "password" => $mobile_pwd); $classname = "\\Justsy\\InterfaceBundle\\SsoAuth\\Sso" . $classname; $re = call_user_func(array($classname, 'createUser'), $this->container, $parameters); $ldap_uid = $re["ldap_uid"]; //该 属性必须由对应用户认证模块的方法createUser返回 } } catch (\Exception $e) { $this->get("logger")->err($e); return Utils::WrapResultError($e->getMessage()); } } if (!empty($authConfig) && empty($eno)) { $eno = $authConfig["ENO"]; } //验证企业号 if (!empty($eno)) { $enterinfo = $cacheobj->getInfo($eno); if ($enterinfo == null) { return Utils::WrapResultError("未找到您注册的企业!"); } $edomain = $enterinfo['edomain']; } if (empty($deptid)) { $deptinfo = new \Justsy\BaseBundle\Management\Dept($da, $da_im); $deptid = $deptinfo->getDefaultDept($eno); $fafa_deptid = $deptid["deptid"]; $deptid = $deptid["deptid"]; } else { $deptinfo = new \Justsy\BaseBundle\Management\Dept($da, $da_im); $deptid = $deptinfo->getinfo($deptid); $fafa_deptid = $deptid["deptid"]; $deptid = $deptid["deptid"]; } $auth_level = "S"; $eno_vip = $enterinfo['vip_level']; $eno_level = $enterinfo['eno_level']; $edomain = $enterinfo['edomain']; $circleId = $enterinfo['circle_id']; //注册jid $jid = SysSeq::GetSeqNextValue($da, "we_staff", "fafa_jid"); $jid .= "-" . $eno . "@" . $edomain; //生成密码 $user = new UserSession($login_account, $mobile_pwd, $login_account, array("ROLE_USER")); $factory = $this->container->get("security.encoder_factory"); $encoder = $factory->getEncoder($user); $pwd = $encoder->encodePassword($mobile_pwd, $user->getSalt()); $mobile_pwd = DES::encrypt($mobile_pwd); $istester = ""; //是否是通过万能验证码激活的测试人员 //插入人员、圈子信息 $sqls[] = "insert into we_staff (dept_id,login_account,eno,password,nick_name,photo_path,state_id,fafa_jid,photo_path_small,photo_path_big,openid,register_date,active_date,t_code,auth_level,mobile,mobile_bind,ldap_uid,login_source) values (?,?,?,?,?,?,?,?,?,?,?,(select register_date from we_register where login_account=?),now(),?,?,?,?,?,?)"; $sqls[] = "insert into we_circle_staff (circle_id,login_account,nick_name) values (?,?,?)"; $sqls[] = "update we_register set state_id='3' where login_account=?"; $paras[] = array((string) $deptid, (string) $login_account, (string) $eno, (string) $pwd, (string) $nick_name, (string) '', (string) "1", (string) $jid, (string) '', (string) '', (string) md5($eno . $login_account), (string) $login_account, (string) $mobile_pwd, (string) $auth_level, empty($mobile_num) ? null : (string) $mobile_num, empty($mobile_num) ? null : (string) $mobile_num, (string) $ldap_uid, $istester); $paras[] = array((string) $circleId, (string) $login_account, (string) $nick_name); $paras[] = array((string) $login_account); $da->ExecSQLs($sqls, $paras); //向RBAC跟新用户身份 //$staffRole=new \Justsy\BaseBundle\Rbac\StaffRole($da,$da_im,$this->logger); //$staffRole->InsertStaffRoleByCode($login_account,$auth_level.$eno_vip,$eno); } catch (\Exception $e) { $this->logger->err($e); return Utils::WrapResultError($e->getMessage()); } //写we_im库 $sqls = array(); $paras = array(); try { //写入人员 如果$jid_old为空执行原有逻辑,否则更新旧jid数据 if (empty($jid_old)) { $sqls = array(); $paras = array(); $pinyin = Utils::Pinyin($nick_name); $employeeid = SysSeq::GetSeqNextValue($da_im, "im_employee", "employeeid"); $sqls[] = "insert into im_employee (employeeid, deptid, loginname, password, employeename,spell) values (?, ?, ?, ?, ?,?)"; $paras[] = array((string) $employeeid, (string) $fafa_deptid, (string) $jid, (string) $mobile_pwd, (string) $nick_name, (string) $pinyin); $sqls[] = "insert into users (username, password, created_at) values (?, ?, now())"; $paras[] = array((string) $jid, (string) $mobile_pwd); $sqls[] = "insert into im_b_msg_read (employeeid, lastid, readdatetime) values (?, (select max(id) from im_b_msg), now())"; $paras[] = array((string) $jid); $da_im->ExecSQLs($sqls, $paras); try { $da_im->ExecSQL("call dept_emp_stat(?)", array((string) $jid)); } catch (\Exception $e) { } $this->syncAttrsToIM(); $jid_old = $jid; } } catch (\Exception $e) { $this->logger->err($e); return Utils::WrapResultError($e->getMessage()); } //关注自己所属企业的开放的内部公众号 $mac = new \Justsy\BaseBundle\Management\MicroAccountMgr($da, $da_im, $login_account, $this->logger, $this->container); $mac->attenCompanyOpenAccount(); //自动关注当前企业的开放公众号 $re = $this->getInfo(); return Utils::WrapResultOK($re); }
private function getMobileCode($login_account) { $da = $this->get('we_data_access'); $sql = "select login_account,mobile_bind from we_staff where login_account=? or mobile_bind=? or ldap_uid=?;"; $para = array((string) $login_account, (string) $login_account, (string) $login_account); $ds = $da->GetData('we_staff', $sql, $para); $result = array(); if (!$ds || $ds['we_staff']['recordcount'] == 0) { $result = array("succeed" => false, "content" => "未存在的Wefafa账号!"); } else { $mobilenumber = $ds["we_staff"]["rows"][0]["mobile_bind"]; $login_account = $ds["we_staff"]["rows"][0]["login_account"]; //验证手机号是否合法 if (!Utils::validateMobile($mobilenumber)) { $result = array("succeed" => false, "content" => "绑定的手机号不正确!"); } else { try { $active_code = rand(100000, 999999); //发送短信前选判断 $sql = "select submit_num,state_id,last_reg_date,timestampdiff(second,last_reg_date,now()) as dif" . " from we_register where login_account=?"; $ds = $da->GetData("we_register", $sql, array($txtmobile)); $issend = true; if ($ds && $ds['we_register']['recordcount'] > 0) { if ($ds['we_register']['rows'][0]['dif'] <= 60) { $result = array("succeed" => false, "content" => "你获取验证码的次数太频繁!一分钟只能取一次!!"); $issend = false; } if ($ds['we_register']['rows'][0]['submit_num'] >= 3 && $ds['we_register']['rows'][0]['dif'] <= 60 * 60 * 24) { $result = array("succeed" => false, "content" => "你获取验证码的次数太多!每天最多只能取三次!!"); $issend = false; } else { if ($ds['we_register']['rows'][0]['dif'] > 60 * 60 * 24) { //一天以后重置 $sql = "update we_register set submit_num=0 where login_account=?"; $da->ExecSQL($sql, array($login_account)); } } } if ($issend) { $content = "您正在使用Wefafa手机密码找回功能,请您在收到本条短信后尽快进行密码修改。本次获得验证码:" . $active_code . "。【发发时代】"; $ec = new \Justsy\BaseBundle\Controller\SendSMSController(); $ec->setContainer($this->container); $ret = $ec->sendSMSAction($mobilenumber, $content); if (strpos($ret->getContent(), "<errorcode>0</errorcode>") === false) { $result = array("succeed" => false, "content" => "获取并发送短信验证码失败,请重试!"); } else { $sql = "insert into we_retrieve_password (id,login_account,req_date,valid_date,valid) values (?,?,now(),adddate(now(),1),'1')"; $da->ExecSQL($sql, array($active_code, $login_account)); //发送成功后存active_code码 $sql = "update we_register set active_code=?,last_reg_date=now(),submit_num=ifnull(submit_num,0)+1," . "state_id='0',review_note='0' where login_account=?"; $para = array($active_code, $login_account); $da->ExecSQL($sql, $para); $result = array("succeed" => true, "content" => "短信验证码已成功发送,请注意查收"); } } } catch (\Exception $e) { $result = array("succeed" => false, "content" => "获取并发送短信验证码失败,请重试!"); } } } return $result; }